I am stepping into the use of Timers. I wrote a simple program to begin the first step into learning whether I can program it correctly. I am doing something wrong but do not know what it is. Can you help? Program is attached.
I have two interrupts in the program. The first one is executed on an external signal. This interrupt is called when an external signal goes LOW. Within this interrupt routine, Timer1 is enabled.
Timer1 is to interrupt every 100 us. The interrupt routine is to basically increase a counter. For the purpose of this test program, I am sending the counter variable to a USB output so that I can verify the counter is increasing.
What I am experiencing with failure are the following:
1) counter variable does not increment based on the information displayed through the USB.
2) The USB device stops displaying after 16 values have been sent to it. Not sure why this would happen. I suspect there is a lock-up in the program.
Thank you for your help.
TIMER not working ???
TIMER not working ???
- Attachments
-
- TIMER_PIC24FJ64GB002__PLL_clock_8_MHz.fcfx
- (17.85 KiB) Downloaded 314 times
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
Re: TIMER not working ???
Hi
The first major error I saw in your Flowchart, is the fact that you have no main loop in your main code(Function) this means the code will start to run until it reaches the end, then it will remain there ,and your macro's which should get called does not get called any longer (locking up)
secondly a while(1) loop in a macro is a blocking function, in my opinion you should re-think your program flow
The first major error I saw in your Flowchart, is the fact that you have no main loop in your main code(Function) this means the code will start to run until it reaches the end, then it will remain there ,and your macro's which should get called does not get called any longer (locking up)
secondly a while(1) loop in a macro is a blocking function, in my opinion you should re-think your program flow

https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
Re: TIMER not working ???
Peter,
The intent of the program is to demonstrate whether I am using the TImer feature correctly. Thus, the purpose of the While(1) loop within the program to continually see the increase of the counter variable. But the increase in value is not happening and thus the purpose of my original post.
As a side note to the purpose of my original post, you state that if the end of the main program was reached, the macros would no longer function. Why? The program is still operating whether going in the smallest circle or a much larger circle of programming. Help me to understand my wrong thinking. Thank you.
The intent of the program is to demonstrate whether I am using the TImer feature correctly. Thus, the purpose of the While(1) loop within the program to continually see the increase of the counter variable. But the increase in value is not happening and thus the purpose of my original post.
As a side note to the purpose of my original post, you state that if the end of the main program was reached, the macros would no longer function. Why? The program is still operating whether going in the smallest circle or a much larger circle of programming. Help me to understand my wrong thinking. Thank you.
- 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: TIMER not working ???
Hello,
The C code inside the TIMER_1_COUNT macro should not be needed. the interrupt flag should be being reset for you when you leave the interrupt macro.
I think I see what is happening.
On an 8-bit PIC device there is a single interrupt vector. On a 16-bit device there are multiple vectors but if they are all at the same priority as by default then the processor will wait for the current interrupt to end before servicing the next.
You are inside the interrupt macro TIMER_TEST in a while 1 loop and so no other interrupts are allowed to file.
It would be better if you can move your main loop away from the interrupt macro and then the interrupts should be free to fire as expected.
The C code inside the TIMER_1_COUNT macro should not be needed. the interrupt flag should be being reset for you when you leave the interrupt macro.
I think I see what is happening.
On an 8-bit PIC device there is a single interrupt vector. On a 16-bit device there are multiple vectors but if they are all at the same priority as by default then the processor will wait for the current interrupt to end before servicing the next.
You are inside the interrupt macro TIMER_TEST in a while 1 loop and so no other interrupts are allowed to file.
It would be better if you can move your main loop away from the interrupt macro and then the interrupts should be free to fire 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