hi all
im trying to get my head around using Interrupts and how they work, therefore ive done a short program to try to simulate a led flashing at 1Hz but im having problems, the Interrupt is 15.2 Hz does this mean as im toggling the output its flashing 7.5Hz on and 7.5Hz off im confused on what many of you will find easy please pardon my ignorance
bob
Hz flash using interupt
Moderator: Benj
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Hz flash using interupt
Hi Bob,
Yes an interrupt firing at 15.2 Hz will run the selected macro 15.2 times a second.
Your program looks ok but will likely be flashing at a rate of 0.5Hz. 1second on and 1 second off.
The problem with your program is you are also calling the pop macro within your main loop, remove the macro call from the loop and it should run as expected.
Yes an interrupt firing at 15.2 Hz will run the selected macro 15.2 times a second.
Your program looks ok but will likely be flashing at a rate of 0.5Hz. 1second on and 1 second off.
The problem with your program is you are also calling the pop macro within your main loop, remove the macro call from the loop and it should run as expected.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
Re: Hz flash using interupt
hi benj
thanks for the reply in simulation the led seems to flicker quick certainly more than 1 times a second even with the macro removed from the loop ??,also in some form of code wouldn't the timer macro need calling to perform the function rather than leaving it out
bob
thanks for the reply in simulation the led seems to flicker quick certainly more than 1 times a second even with the macro removed from the loop ??,also in some form of code wouldn't the timer macro need calling to perform the function rather than leaving it out
bob
-
- 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: Hz flash using interupt
Hi Bob,
To toggle output at a more precise frequency, take a look here.
It is handled by the microcontroller so you don't need to call it as Ben has stated.
To toggle output at a more precise frequency, take a look here.
Yes, simulation runs much faster than on real hardware so that is normal.siliconchip wrote: ↑Thu Dec 17, 2020 2:40 pmin simulation the led seems to flicker quick certainly more than 1 times a second even with the macro removed from the loop ??
No the interrupt call macro (pop in your case) is automatically called 15.259 times every second or once every 1/15.259 = 65.5ms.siliconchip wrote: ↑Thu Dec 17, 2020 2:40 pmalso in some form of code wouldn't the timer macro need calling to perform the function rather than leaving it out
It is handled by the microcontroller so you don't need to call it as Ben has stated.
Martin
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
Re: Hz flash using interupt
Hi martin
As always thanks for the reply, i removed the "pop" macro call from the main loop and added the relevant osccon details for speed and tested in hardware and found i had roughly a 1 second flash, i then used the example in the link you provided for toggling and found this was flashing a lot quicker ie half the frequency for both on and off using my base frequency of 15Hz im guessing you would need some thing like a johnson counter ie the cmos cd4017 to divide the output to something suitable for your application if you couldnt get the desired frequency from the toggle method ??
Bob
As always thanks for the reply, i removed the "pop" macro call from the main loop and added the relevant osccon details for speed and tested in hardware and found i had roughly a 1 second flash, i then used the example in the link you provided for toggling and found this was flashing a lot quicker ie half the frequency for both on and off using my base frequency of 15Hz im guessing you would need some thing like a johnson counter ie the cmos cd4017 to divide the output to something suitable for your application if you couldnt get the desired frequency from the toggle method ??
Bob
-
- 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: Hz flash using interupt
Your welcome Bob.
Just using the count and and additional variable should do it .
What frequency did have in mind?
I will edit your flowchart toggle at the stated duration.
That should not be necessary.siliconchip wrote: ↑Fri Dec 18, 2020 8:00 pmim guessing you would need some thing like a johnson counter ie the cmos cd4017 to divide the output to something suitable for your application if you couldnt get the desired frequency from the toggle method ??
Just using the count and and additional variable should do it .
What frequency did have in mind?
I will edit your flowchart toggle at the stated duration.
Martin
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
Re: Hz flash using interupt
Hi martin
Ive not a particular frequency in mind but it would be nice to select a desired frequency from 1 to 1500 or something like that but i guess if possible would get pretty involved also just out of interest could you alter the code as you suggested to say 5Hz
Bob
Ive not a particular frequency in mind but it would be nice to select a desired frequency from 1 to 1500 or something like that but i guess if possible would get pretty involved also just out of interest could you alter the code as you suggested to say 5Hz
Bob