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

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)?

Postby Steven_SS » Fri Dec 21, 2018 12:24 am

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8609
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2477 times
Been thanked: 3559 times
Contact:

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

Postby medelec35 » Fri Dec 21, 2018 8:24 am

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 54 times
These users thanked the author medelec35 for the post:
Steven_SS (Fri Dec 21, 2018 3:13 pm)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

mnf
Valued Contributor
Valued Contributor
Posts: 627
Joined: Wed May 31, 2017 11:57 am
Has thanked: 56 times
Been thanked: 347 times
Contact:

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

Postby mnf » Fri Dec 21, 2018 8:46 am

Hi Steven,

Your interrupt routine is incorrect too...

INC.JPG
INC.JPG (15.05 KiB) Viewed 2778 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
These users thanked the author mnf for the post (total 2):
medelec35 (Fri Dec 21, 2018 8:51 am) • Steven_SS (Fri Dec 21, 2018 6:29 pm)
Rating: 10%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8609
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2477 times
Been thanked: 3559 times
Contact:

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

Postby medelec35 » Fri Dec 21, 2018 8:51 am

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.
These users thanked the author medelec35 for the post:
mnf (Fri Dec 21, 2018 9:08 am)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

mnf
Valued Contributor
Valued Contributor
Posts: 627
Joined: Wed May 31, 2017 11:57 am
Has thanked: 56 times
Been thanked: 347 times
Contact:

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

Postby mnf » Fri Dec 21, 2018 8:54 am

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

viewtopic.php?f=76&t=20638
These users thanked the author mnf for the post:
medelec35 (Fri Dec 21, 2018 6:02 pm)
Rating: 5%
 

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)?

Postby Steven_SS » Fri Dec 21, 2018 3:16 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8609
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2477 times
Been thanked: 3559 times
Contact:

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

Postby medelec35 » Fri Dec 21, 2018 3:34 pm

Timer  ISR.png
Timer ISR.png (25.32 KiB) Viewed 2753 times
These users thanked the author medelec35 for the post (total 2):
mnf (Fri Dec 21, 2018 5:32 pm) • Steven_SS (Fri Dec 21, 2018 6:27 pm)
Rating: 10%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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)?

Postby Steven_SS » Fri Dec 21, 2018 8:30 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8609
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2477 times
Been thanked: 3559 times
Contact:

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

Postby medelec35 » Fri Dec 21, 2018 8:53 pm

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"
These users thanked the author medelec35 for the post:
kersing (Fri Dec 21, 2018 10:13 pm)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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)?

Postby Steven_SS » Sat Dec 22, 2018 12:10 am

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8609
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2477 times
Been thanked: 3559 times
Contact:

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

Postby medelec35 » Sat Dec 22, 2018 12:42 am

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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)?

Postby Steven_SS » Wed Dec 26, 2018 6:07 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8609
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2477 times
Been thanked: 3559 times
Contact:

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

Postby medelec35 » Wed Dec 26, 2018 7:16 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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)?

Postby Steven_SS » Sat Dec 29, 2018 6:52 pm

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