Frequency Measurement

Author Message

Joined: 05/03/2018
Location: Netherlands
Posts: 329
Posted: 11:45am 25 Jun 2018      

IF the MX has a counter input, it should be possible to simply let it increment on every edge, and frequently read out the counter.
With a 16 bit counter you could do this in 1msec period, and count up to 60MHz.
There are HW limitations to the frequency you can input to the counter, but this can hardly be an issue with a 50MHz+ chip like the PIC32 series.

I build a 50MHz frequency counter this way in a 4MHz PIC16F84 20 years ago.
For frequencies above 40-50MHz, you would need a prescaler (not a 74LS90....your MX is far faster than the separate TTL chips).

You probably could have use of a Cfunction, but I bet you can do it in MMbasic also.
The 1msec reading of the counter register does not need to be accurate, as long as you have an accurate time as a reference.
The 1msec loop is only needed if you have a 16 bit counter. If your HW has a 32 bit counter, you simple read it every second, and divide by the reference time.

something like

main loop
get reference time
clear work register (32 bit)
1msec loop (i.e. 1000 times)
read counter
add to work register
end loop
get current time
subtract reference time = delta time
divide work register by delta time = accurate frequency
end main loop

This you can do in MMbasic, I am sure...
Edited by Volhout 2018-06-26
If nothing goes right ... turn left