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
Freq meter err (FC11,Nano)
-
mnfisher
- Valued Contributor
- Posts: 1976
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 158 times
- Been thanked: 936 times
-
mnfisher
- Valued Contributor
- Posts: 1976
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 158 times
- Been thanked: 936 times
Re: Freq meter err (FC11,Nano)
... 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
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
- Attachments
-
- freq_hs.fcfx
- (13.5 KiB) Downloaded 18 times
-
mnfisher
- Valued Contributor
- Posts: 1976
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 158 times
- Been thanked: 936 times
Re: Freq meter err (FC11,Nano)
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)
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)
-
viktor_aust
- Posts: 39
- Joined: Fri May 17, 2024 1:04 am
- Has thanked: 15 times
- Been thanked: 5 times
Re: Freq meter err (FC11,Nano)
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.
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.
-
mnfisher
- Valued Contributor
- Posts: 1976
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 158 times
- Been thanked: 936 times
Re: Freq meter err (FC11,Nano)
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
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
-
viktor_aust
- Posts: 39
- Joined: Fri May 17, 2024 1:04 am
- Has thanked: 15 times
- Been thanked: 5 times