I’m trying to build a simple frequency counter application using ticker with InterruptIn. Every thing is working in order as long as the frequency is less than 100kHz.
Am using PWM to generate the input for the counter, when the frequency goes above 100KHz, my counter will read out the half of the correct value.
I really need to measure frequencies up to 250KHz. I presume this should be easily achievable with mbed considering that it runs at 96MHz
Is there something wrong with my code? Or will be there any other method that allow me to measure frequencies up to 250KHz?
Below is my simple code
Thank you all
#include "mbed.h"
#include "TextLCD.h"
unsigned int counts;
float freq;
TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
class Counter {
public:
Counter(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter
_interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance
}
void increment() {
_count++;
}
void clear() {
_count = 0;
}
unsigned int read() {
return _count;
}
private:
InterruptIn _interrupt;
volatile unsigned int _count;
};
Ticker out;
Counter counter(p5);
PwmOut x(p21);
void output() {
counts = counter.read();
counter.clear();
freq = counts;
}
int main() {
out.attach(&output, 1);
while(1) {
x= 0.5;
x.period_us(10);
// x.pulsewidth_us(1) ;
lcd.printf("freq: %f\r\n", freq);
wait(0.25);
}
}
I’m trying to build a simple frequency counter application using ticker with InterruptIn. Every thing is working in order as long as the frequency is less than 100kHz. Am using PWM to generate the input for the counter, when the frequency goes above 100KHz, my counter will read out the half of the correct value.
I really need to measure frequencies up to 250KHz. I presume this should be easily achievable with mbed considering that it runs at 96MHz
Is there something wrong with my code? Or will be there any other method that allow me to measure frequencies up to 250KHz?
Below is my simple code
Thank you all