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 CCS Technical Support

Interrupt Accuracy Question

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



Joined: 08 Sep 2008
Posts: 21

View user's profile Send private message

Interrupt Accuracy Question
PostPosted: Mon May 11, 2009 7:55 am     Reply with quote

I'm currently working with the PIC18F4685, and I have an interrupt that executes every 0.5 milliseconds (i.e. 2000 times per second). What I'm finding in my code is that sometimes instead of happening every 0.5 ms, my interrupt is only getting called every 5 ms. That interrupt is the highest priority interrupt and therefore should interrupt the other (lower priority) interrupts.

I'm doing a handful of log() formula's in my code, so is it possible that the interrupts wait until the end of that computation to execute the interrupt?

What can cause an interrupt to execute less often? The interrupt routine itself is fairly lean, although I have no real way to determine how long the code takes.

So for all you PIC experts - what can cause an interrupt to execute less often than it should?
Ttelmah
Guest







PostPosted: Mon May 11, 2009 8:57 am     Reply with quote

What is actually 'done' in your ISR?.
Basically, if you call _any_ code in the ISR, that is also called in the external program, then interrupts _will_ be disabled round the external code. Delays are a 'classic', though this can be avoided (search here for how to use separate delay routines inside an ISR).
Second reason, is things like functions to write to the program memory, that will disable all interrupts while they execute.
Also, be aware, that though you 'think' this is the only high priority ISR, are you _sure_ this is the case?. If you are using the RB0 interrupt, this is _always_ made high priority when interrupt priorities are enabled (hardware 'feature'....), and if this was being used, it'd interfere with the handling of the other interrupt....

Best Wishes
seidleroni



Joined: 08 Sep 2008
Posts: 21

View user's profile Send private message

PostPosted: Mon May 11, 2009 9:19 am     Reply with quote

Ttelmah, I'm not sure I understand your first sentence. Do you mean that if I am calling a function in my ISR (let's say function MovePiston() ), then each time my code OUTSIDE of the ISR calls MovePiston(), all the interrupts would be disabled when it is executed?

I dont have any code that writes to the program memory, just really to EEPROM. I do have H/W interrupts (for CAN), but they are lower priority than the one I'm using above, and should be interrupted, right?
Ttelmah
Guest







PostPosted: Mon May 11, 2009 10:04 am     Reply with quote

Yes.
The PIC, does not support re-entrancy. So code can never be called inside itself. Hence if a function is used in the interrupt, interrupts _must_ be disabled if the same function is used in the 'main' code. If you are doing this, then this is your answer. In fact if you are calling something that performs a 'move' operation, you would need to rethink anyway. What would happen if the external code asked for a move in one direction, then in the middle of this, and interrupt asked for a move the other way!....

Best Wishes
seidleroni



Joined: 08 Sep 2008
Posts: 21

View user's profile Send private message

PostPosted: Mon May 11, 2009 11:20 am     Reply with quote

Does that mean that the CCS compiler automatically disables interrupts during those functions, or do I need to do that separately?

Also, I'm not doing any 'move' operations, I don't think.
Ttelmah
Guest







PostPosted: Mon May 11, 2009 12:40 pm     Reply with quote

The compiler will disable interrupts automatically.
You gave as an example 'name', for a function you might be calling both inside, and outside the ISR, 'MovePiston', which implies some possibly mechanical operation...

Best Wishes
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