|
|
View previous topic :: View next topic |
Author |
Message |
Tom Jetland
Joined: 23 Jun 2011 Posts: 31 Location: UK
|
Global Interrupt Usage |
Posted: Thu May 23, 2013 8:27 am |
|
|
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: 19535
|
|
Posted: Thu May 23, 2013 8:50 am |
|
|
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
|
|
Posted: Thu May 23, 2013 9:45 am |
|
|
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: 19535
|
|
Posted: Thu May 23, 2013 2:27 pm |
|
|
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
|
|
Posted: Thu May 30, 2013 3:28 am |
|
|
Thanks Telmah |
|
|
|
|
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
|