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

Global Interrupt Usage

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



Joined: 23 Jun 2011
Posts: 31
Location: UK

View user's profile Send private message

Global Interrupt Usage
PostPosted: Thu May 23, 2013 8:27 am     Reply with quote

This is a pretty fundamental question, but I've wondered for a while and although there examples of how to use it, and the pitfalls involved, I'd like to understand the usage of Global Interrupts a bit better.

I guess the main thing I'm concerned with is the context saving you have to perform manually. It is clear that you have to save the STATUS and accumulator (W REGISTER), but there is also a mention on the Pic datasheets that...

Quote:
If additional locations need to be saved before executing the Interrupt Service Routine (ISR)
code, they should be saved after the STATUS register is saved (step 2), and restored before the
STATUS register is restored (step 4).


I'm just wondering what other locations you would NEED to be saving?

I know that certain Pics do some automatic context saving (anyone used these?) but I'm just after general thoughts here.

If anyone would be kind enough to enlighten me on this issue, I'd be grateful :-)

Tom
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu May 23, 2013 8:50 am     Reply with quote

You need to save every register used in the routines you call in the interrupt.
So the 'answer' depends on what you do.

If (for instance) you perform an array look up, the table index registers have to be saved.

All the PIC 18's automatically save the Wreg, BSR, and status, but only one copy. The compiler uses this ability in it's standard handler, or if high priority interrupts are enabled, the ability is used for these instead. However comment below.

What 'may' have to be saved, depends completely on what operations you perform in the interrupt. Safe way is to write the code for this, compile it, then look at the assembler listing, and record every SFR/scratch register that is used.

Expect:
WREG
BSR
STATUS - minimum

FSR0/FSR1/FSR2 (two registers each)
PROD (if maths is used)
TBLPTR (table access)
Scratch registers (logical operations and maths).

Some of the PIC18's have errata preventing the automatic save/restore of the first registers from being used.

Best Wishes
Tom Jetland



Joined: 23 Jun 2011
Posts: 31
Location: UK

View user's profile Send private message

PostPosted: Thu May 23, 2013 9:45 am     Reply with quote

Hmmm... Reminds me why I've not tried it before! I think I will take a gander at the assembly listing like you suggested Ttelmah and try to glean information from it. I think I'll take the plunge at some stage as fast entry into interrupts is damned handy at times.

Thanks

Tom
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu May 23, 2013 2:27 pm     Reply with quote

It is generally only worth doing, if you have one, or at most two interrupt handlers, both of which are very small.
I've done it with (for instance), a quadrature encoder, which since it only has to decode the quadrature states and increment a counter, doesn't use any of the extra registers, and a timer, that just increments some counters.
If you start doing array accesses, or accessing structures in the interrupt, you run into using the basic 8*8 multiply for the location calculations, and the index registers. At this point you are only a couple of instructions off what CCS do....

Best Wishes
Tom Jetland



Joined: 23 Jun 2011
Posts: 31
Location: UK

View user's profile Send private message

PostPosted: Thu May 30, 2013 3:28 am     Reply with quote

Thanks Telmah
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