Yeah, that should work. However, the code can be optimized a little (as shown below). In general, you want to do as little as possible in the interrupt routine. You also don't need to stop and start the timer after a reset or a read (not that it won't work...)
Also, whatever it is you're plugging in, you have to make sure that the input voltage to the pin is within 0 and 3.3 volts. Make sure the signal does not become negative and does not go over 5V. Depending on your device, you might have to do a little singal conditioning before you connect it.
#include "mbed.h"
Serial pc(USBTX, USBRX);
InterruptIn frec_input(p5);
Timer t;
float T,f; // Temporary float for period and frequency;
void start_timer() {
T=t.read() // Get time between interrupts
f=1/T; // Calculate frequency
t.reset(); // Reset Timer;
}
int main() {
t.reset();
t.start(); // Start the timer;
frec_input.rise(&start_timer);
while(1) {
printf("period: %3.3fms Frequency: %.2fHz\n",T*1000.0,f);
wait(1);
}
}
hello every one.
I am trying to read the frequency from a voltage to frequency converter integrated circuit using an Mbed , could one help me?
Following there is the datasheet
http://www.farnell.com/datasheets/83861.pdf
Cheers
Antonio