View previous topic :: View next topic |
Author |
Message |
Micro_Guy
Joined: 06 Aug 2015 Posts: 10
|
Count How many times program goes into interrupt |
Posted: Wed Sep 07, 2016 3:29 am |
|
|
Hi guys,
I'm trying to figure out a way how to count how many times a program executes an ISR.
Here's the best I could come up with, but it's not working.
Any help/mentoring is greatly appreciated. I'm new to interrupts so I'm experimenting.
Thanks in advance!
Code: | #include <16F877A.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4M)
int8 Count=0;
#INT_TIMER2
void control_timer_isr() {
output_toggle(pin_C2);
Count++;
}
void main() {
setup_timer_2(T2_DIV_BY_16, 245, 5);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
while(1);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Wed Sep 07, 2016 4:41 am |
|
|
What you post will work.
How are you testing this?.
The interrupt will be called just over 50* per second.
4000000/(4*246*5*16) = 50.813 |
|
|
Micro_Guy
Joined: 06 Aug 2015 Posts: 10
|
|
Posted: Thu Sep 08, 2016 12:54 am |
|
|
I'm testing this by running the program in Step mode and monitoring the value of "Count".
I think something weird was going on with my compiler because the code seems to update "Count" just fine now.
Thanks for the quick reply Ttelmah!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Thu Sep 08, 2016 1:45 am |
|
|
I actually 'guessed' you might be in a debugger.
These can sometimes introduce slight 'oddities'. This is why sometimes it is better to actually do things like have the code run for a second, and then print 'count', to fully understand how things work. |
|
|
|