Frequency not being read(at all maybe)?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

Frequency not being read(at all maybe)?

Post 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
Attachments
Freq_Reciever.fcfx
(32.23 KiB) Downloaded 213 times
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

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

Post 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"
Attachments
Freq_Reciever mod1.fcfx
(32.27 KiB) Downloaded 207 times
Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

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

Post by mnf »

Hi Steven,

Your interrupt routine is incorrect too...
INC.JPG
INC.JPG (15.05 KiB) Viewed 6629 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

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

Post 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.
Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

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

Post by mnf »

Also see this thread for some tips on improving the AVR interrupt code...

viewtopic.php?f=76&t=20638

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

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

Post 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?
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

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

Post by medelec35 »

Timer ISR.png
(25.32 KiB) Downloaded 2930 times
Martin

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

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

Post 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
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

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

Post 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"
Martin

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

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

Post 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
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

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

Post by medelec35 »

Can you post your flowchart so we can see how you have implemented arrays?
Martin

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

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

Post 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
Attachments
Freq_Reciever.fcfx
(32.23 KiB) Downloaded 163 times
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

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

Post by medelec35 »

Did you post the correct flowchart as you have not got any arrays set up?
Martin

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

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

Post 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 !
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

Post Reply