Jump to content
Sign in to follow this  
2sb18

Pic18f Interrupts

Recommended Posts

Hi Guys,

 

I have a program where I multiply ints by constants, and then in the ISR I multiply things together. I've been getting some strange problems. I was wondering, are the PRODL and PRODH registers context-saved during an ISR, or am I supposed to do that myself. I looked at the assembly code and it looks like just the STATUS, WREG, BSR and FSR are context saved. I know during an ISR you shouldn't be doing calculation-heavy operations like multiplication but in this case it's necessary.

 

I've been working with Sourceboost and BoostC and both surpass my expectations. Thanks for the great program.

Share this post


Link to post
Share on other sites

2sb18,

 

I was wondering, are the PRODL and PRODH registers context-saved during an ISR, or am I supposed to do that myself.
This is a very interesting point.

 

I don't think (I have tried it yet) you can write to PRODL and PRODH registers.

This means its impossible to restore them at the end of an interrupt routine.

 

The only answers I can see at the moment are:

 

1) Avoid multiplication in you interrupt service routine.

2) Disable interrupts around multiplication code in you main thread of execution.

 

Code that disables interrupts during a multiplication.

 

void main()
{
char a = 10;
char b = 20;
int res;

clear_bit( intcon, GIE ); // disable interrupts
res = a * b; // mul now safe
set_bit( intcon, GIE ); // restore interrupts

.......
.......
.......
}

 

The down of of this is that the maximum interrupt latency will become longer.

 

Let me know your thoughts.

 

Regards

Dave

Share this post


Link to post
Share on other sites

2sb18,

 

I have checked into this a little further and tested this on some hardware to. It turns out the PRODH and PRODL are readable and writeable. So you can implement some code to save and restore these registers in your interrupt routine, eg:

 

void interrupt( void )
{
char prodhSave = prodh;
char prodlSave = prodl;

......

prodl = prodlSave;
prodh = prodhSave;
}

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...