6 years ago.

How can I use Mbed to measure frequencies in 3 different range?

System Specification The following specifications indicate 3 ranges of measurement.

Frequency Measurements

The device should be able to measure frequencies in three ranges: High : 10 MHz Medium : 100 kHz Low : 100 Hz

Period Measurements

The device should measure the time of a periodic signal to a resolution of High : 1.0 ms Medium : 10 ms Low : 1.000 s

Time Interval Measurements

The device should measure the time of a periodic signal to a resolution of High : 1.0000 ms Medium : 10.00 ms Low : 1.000 s

1 Answer

6 years ago.

For slow signals, you can use a Timer to track time and attach a callback to the rising edge of signal Digital Input. In the ISR maybe use a circular buffer and push a time in on every rising edge. Then in the main loop you can take an average of the buffer to smooth out the results.

The 10MHz is going to be a problem. If your micro runs at 80MHz that leaves only 8 clock ticks between rising edges to do everything else which is not even close to enough time. You can break out the reference manual and look at the options for the Timers. For example, using the input capture feature would eliminate the error that comes from calling the ISR.

You might also be able to use the timer as a pulse counter using the external signal as a clock input. So instead of the ticks coming from the internal system clock they come from the signal you're measuring. Then you can just read the value of the timer at a regular interval and see how many counts you have for the interval. You will probably have to dig into the lower level libraries to do this. This post describes doing just this with success:

https://os.mbed.com/questions/145/Is-it-possible-to-count-the-pulses-of-a-/

By the way, your time resolution numbers don't line up. 1MHz = 1us period. For accuracy of say +/- 1% the resolution needs to be 0.01us.