Page 1 of 1

Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 12:24 am
by Steven_SS
Hello friends,
So in this program I have these interrupts to find frequency, however it is not working when connected to the hardware.
The display kept showing 0 when it shouldn't have. The interrupt is set at PortB0 which should be the correct one from the sensor output.
Can anyone see why the program is not picking up the frequency?? The max expected frequency should be around 150 Hz.
Greatly appreciate any help

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 8:24 am
by medelec35
Hi Steven,
You have not got a loop to continuously display updated frequency on your display.
The initial frequency which will be 0 is displayed, then the code ends.
Try the modified flowchart and see if it works any better?

The maybe an issue with values flashing on the display?
If that is the case then instead of using clear, it will be better to remove the ClearDispaly within WriteDisplay Macro,
then add spaces after the HZ so you have something like Print "HZ " instead of Print "HZ"

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 8:46 am
by mnf
Hi Steven,

Your interrupt routine is incorrect too...
INC.JPG
INC.JPG (15.05 KiB) Viewed 6753 times
Things only get changed if TimerTick = 61??? but TimerTick is never incremented. In IOCB PinChange is incremented (edit - This is counting the frequency - increment TimerTick in the timer interrupt) .

You also are using floats (PinChange = PinChange + 1.0 for example) which may cause grief for some values.. PinChange et al are integer values so use an integer increment.....

And that ClearDisplay makes for an unpleasant viewing experience.

Martin

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 8:51 am
by medelec35
Hi Martin,
mnf wrote:Things only get changed if TimerTick = 61??? but TimerTick is never incremented. In IOCB PincChange is incremented.
Good spot as I did not even look at the timer interrupt routine.

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 8:54 am
by mnf
Also see this thread for some tips on improving the AVR interrupt code...

viewtopic.php?f=76&t=20638

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 3:16 pm
by Steven_SS
mnf wrote: Things only get changed if TimerTick = 61??? but TimerTick is never incremented. In IOCB PinChange is incremented (edit - This is counting the frequency - increment TimerTick in the timer interrupt) .
Martin
So your saying I need to add a counter to TimerTick? Would I add that to the interrupt routine?
Or is that "edit" saying otherwise?

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 3:34 pm
by medelec35
Timer ISR.png
(25.32 KiB) Downloaded 2930 times

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 8:30 pm
by Steven_SS
medelec35 wrote: The maybe an issue with values flashing on the display?
If that is the case then instead of using clear, it will be better to remove the ClearDispaly within WriteDisplay Macro,
then add spaces after the HZ so you have something like Print "HZ " instead of Print "HZ"
I do have the values flashing onto the display...
How do I make that not happen? As example, will either flash between the values of 100 or 99. And if i take the ClearDisplay out then it'd show 100 then 990 which i believe is the 99 overwritting the 100 so the 3rd character of the previous(100) is still visible letting it be 990.
So how can i fix this? Thanks a lot

Re: Frequency not being read(at all maybe)?

Posted: Fri Dec 21, 2018 8:53 pm
by medelec35
medelec35 wrote:The maybe an issue with values flashing on the display?
If that is the case then instead of using clear, it will be better to remove the ClearDispaly within WriteDisplay Macro,
then add spaces after the HZ so you have something like Print "HZ " instead of Print "HZ"

Re: Frequency not being read(at all maybe)?

Posted: Sat Dec 22, 2018 12:10 am
by Steven_SS
Last question for awhile haha, how can I manage to store the Hz value into a index of an array??

When I attempt to do so, the array catches the first value that it's given properly then takes that first index(first reading) value and continues to place them into the rest of the array which is size 10. I have it testing where it shows the actual HZ value alongside the value that is in the array at the count, which should be the same but are not.

Have a happy and safe Holiday

Re: Frequency not being read(at all maybe)?

Posted: Sat Dec 22, 2018 12:42 am
by medelec35
Can you post your flowchart so we can see how you have implemented arrays?

Re: Frequency not being read(at all maybe)?

Posted: Wed Dec 26, 2018 6:07 pm
by Steven_SS
medelec35 wrote:Can you post your flowchart so we can see how you have implemented arrays?
Sorry for the late reply, but here it is... I might just end up accepting and taking the first value since it comes out always within 2 Hz
(an example is that the first reading might be 60 Hz, then next maybe 61, and next 62 but no more than 2 Hz difference).
Thanks

Re: Frequency not being read(at all maybe)?

Posted: Wed Dec 26, 2018 7:16 pm
by medelec35
Did you post the correct flowchart as you have not got any arrays set up?

Re: Frequency not being read(at all maybe)?

Posted: Sat Dec 29, 2018 6:52 pm
by Steven_SS
medelec35 wrote:Did you post the correct flowchart as you have not got any arrays set up?
Ahh it must not then, I've been out for a while & asked a friend to send me the file on my home computer. Guess it was the wrong file.
I won't be back in the office until Jan 2nd. So i'll pull it up then Martin! If i still can't figure it out
Have a happy new years !