CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Count How many times program goes into interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Micro_Guy



Joined: 06 Aug 2015
Posts: 10

View user's profile Send private message

Count How many times program goes into interrupt
PostPosted: Wed Sep 07, 2016 3:29 am     Reply with quote

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: 19328

View user's profile Send private message

PostPosted: Wed Sep 07, 2016 4:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 08, 2016 12:54 am     Reply with quote

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: 19328

View user's profile Send private message

PostPosted: Thu Sep 08, 2016 1:45 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group