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

question about "multiple pwm outputs" by Mark

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







question about "multiple pwm outputs" by Mark
PostPosted: Tue Jul 11, 2006 6:11 am     Reply with quote

In the post: "multiple pwm outputs" there is a c code that has multiple pwm outputs. I see these instructions:

/****************************************************************************
* DESCRIPTION: The int handler for high priority interrupts
* PARAMETERS: none
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void Int_Handler_High(void)
{
/* Currently these ints only use FSR0 and register 3
so that is all that we need to save */
fsr0_save = FSR0;
SCRATCH3_save = *(0x03);

/* Check for a CCP2 interrupt */
if ((PIE2bits.CCP2IE) && (PIR2bits.CCP2IF))
ccp2_isr();

/* Check for a CCP1 interrupt */
if ((PIE1bits.CCP1IE) && (PIR1bits.CCP1IF))
ccp1_isr();

/* restore data */
FSR0 = fsr0_save;
*(0x03) = SCRATCH3_save;

#asm
retfie 1
#endasm

}

#org 0x08,0x0A
/****************************************************************************
* DESCRIPTION: Wrapper for the high priority interrupt
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void Int_Handler_High_Wrapper(void)
{
Int_Handler_High();
}

/****************************************************************************
* DESCRIPTION: The int handler for low priority interrupts
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#org 0x18,0x48
void Int_Handler_Low(void)
{
#asm
movwf W_save
#endasm
STATUS_save = STATUS;
fsr0_save = FSR0;
BSR_save = BSR;

if ((PIR1bits.RCIF) && (PIE1bits.RCIE))
dmx_rcv();


BSR = BSR_save;
FSR0 = fsr0_save;
#asm
movf W_save,W
#endasm
STATUS = STATUS_save;
#asm
retfie 0
#endasm

}

I would like to know what they mean.
Where can I find some explanations about saving registers using interrupts?
I thought that CCS compiler does this job without needing these instructions.
Without using assembler it is possible in CCS to setup high and low priority interrupts?

Thank you
Ttelmah
Guest







PostPosted: Tue Jul 11, 2006 6:45 am     Reply with quote

Unless you need the ultimate in speed, then use the compiler's own functions. If you add the keyword 'high' to an interrupt handler, it will do all the work of setting this handler to be a 'high priority' interrupt. Without this the interrupt will be supported as a low priority interrupt.
However there are a lot of caveats. The first is in hardware. In most chips, if _any_ interrupt is high priority, then if INT0 is used, it too will be high priority. As soon as more than one interrupt is used on either the high priority vector or the low priority vector, then there has to be added code to determine which interrupt has occured (which the compiler will add automatically). Also the compiler 'fails safe', and saves _everything_ that may be used in an interrupt handler.
The 'point' of the routines posted, is that if you know exactly what you are doing, and want the ultimate in speed, then you elect instead, to only save the minimum number of registers in use. To do this, you need to look at the assembler generated for the C code in the handler, and then save every register used in this. In order to generate multiple PWM outputs, with the least possible interrupt latency, the poster has elected to do this.
For 95% of interrupt applications, you can use the compiler's standard code, and not wrry about assembler at all. However, the people who have the greatest 'success' in using interrupts, will be those who understand the abilities an limitations of the chip, which following through some of the MicroChip application notes on individual peripherals, may well help.

Best Wishes
Frank
Guest







Thank you
PostPosted: Tue Jul 11, 2006 8:24 am     Reply with quote

Thank You

but I can't understand how I can use priority (low and high) interrupts in CCS using CCS instructions that is to say without setting priority register bits
Ttelmah
Guest







Re: Thank you
PostPosted: Tue Jul 11, 2006 9:26 am     Reply with quote

Frank wrote:
Thank You

but I can't understand how I can use priority (low and high) interrupts in CCS using CCS instructions that is to say without setting priority register bits


You define the interrupt handlers, with:
Code:

#int_timer0
void your_interrupt_handler(void) {
   //Interrupt handler code here
}

#int_timer1 high
void your_high_priority_handler(void) {
   //interrupt handler code here
}


Note the 'high' keyword for timer1 (or any other interrupt you want to make 'high priority'). The compiler will then automatically set the priority bit for this interrupt
However the 'caveat' comes if you do this:

Code:

#int_timer0
void your_interrupt_handler(void) {
   //Interrupt handler code here
}

#int_timer1 high
void your_high_priority_handler(void) {
   //interrupt handler code here
}

#int_EXT
void ext_interrupt_handler(void) {
   //You need to check the data sheet, but on most chips, this
   //interrupt will also be 'high priority' if 'high' is used for any other
   //interrupt
}

The compiler will handle this correctly, but INT_EXT, is often 'automatically' a high priority interrupt if the priority feature is used.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jul 11, 2006 10:23 am     Reply with quote

What he said Smile
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