Page 2 of 2

Re: Freq meter err (FC11,Nano)

Posted: Tue May 19, 2026 9:36 am
by mnfisher
Might be pushing it...

There are alternative techniques. One is a custom interrupt handler (to reduce the ISR overhead) Faster still - move the input to D5 and use it as input for TMR1... Both need some C.

Signal integrity needs to be good too - and not degrade due to capacitance etc

Martin

Re: Freq meter err (FC11,Nano)

Posted: Tue May 19, 2026 11:04 am
by mnfisher
... and using TMR1 with an input as its pulse.

This requires D5 as the signal to be measured and D3 with a 1s pulse - I used a AWG for both signals

The theoretical maximum frequency it can measure is 6.4MHz - at 5MHz I got 4999986Hz :-)

It is pretty much all in C - I used a custom interrupt for the timer1 overflow - to reduce the overhead (overflows is defined in supplementary code) - needed to create a dummy macro to keep FC happy (dummy - is never called)

The 1s (d3) interrupt uses the standard FC setup - but most of the code is in C (to retrieve the current value of TCNT1 and the number of overflows)

Now the pulse counter is hardware based - so the MCU isn't overloaded. This means we can use delays again.

An average value would be good - again I've kept the code as short as possible.

Martin

Re: Freq meter err (FC11,Nano)

Posted: Tue May 19, 2026 11:07 am
by mnfisher
Tested at 6.4MHz and pretty good (6399981Hz) and at 1MHz - 999997. A few 'ticks' are missed whilst handling the 1Hz / overflow interrupts?

Using an external 1Hz pulse means that the results are independent of the Arduino's clock - so should be reliable - depending on the accuracy of the timer instead.

I used a square wave for the 1Hz signal and initially a sine for the frequency to be measured (also tested with square for this)

Re: Freq meter err (FC11,Nano)

Posted: Tue May 19, 2026 11:42 pm
by viktor_aust
Hi Martin
I like the idea of external 1Hz pulse.
Looks like this is the key to a good freq meter with Arduino.
Will test it with Mega shortly.
Thanks.

Re: Freq meter err (FC11,Nano)

Posted: Wed May 20, 2026 6:22 am
by mnfisher
Okay, let us know how you get on...

It looks like there will be a few changes - you'll need to change the pin from d5 to one that is a timer breakout (you might need to change to timer 5 and D47?) and d3 is int5 rather than int1

Will require some changes to the setup and interrupt handler for the 1hz pulse.

Martin

Re: Freq meter err (FC11,Nano)

Posted: Wed May 20, 2026 9:26 pm
by viktor_aust
Sure. Will do.