View previous topic :: View next topic |
Author |
Message |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
Exit an interrupt ? |
Posted: Wed Feb 06, 2008 1:04 am |
|
|
Dear CCS members,
Take a look at the following code (Full code here):
Code: |
#INT_TIMER1
void timer_irq()
{
set_timer1(preload);
if (Intcount < 255)
{
if (Intcount == red_duty)
{
output_low(red);
}
if (Intcount == green_duty)
{
output_low(green);
}
if (Intcount == blue_duty)
{
output_low(blue);
}
}
else if(Intcount == 255)
{
Intcount = 0;
output_high(red);
output_high(green);
output_high(blue);
}
Intcount++;
}
|
Is there a way to skip the remaining Intcount++; code when i reset it to 0 better (more efficient way) than doing :
Code: |
else if(Intcount == 255)
{
restart_pwm = 1;
output_high(pin_a0);
output_high(pin_a1);
output_high(pin_a2);
}
Intcount++;
if(restart_pwm==1){
Intcount=0;
restart_pwm = 0;
}
}
|
... Like exiting the current interrupt so it would not run the rest of the interrupt code for this time only thus having a real 0 value for Intcount instead of resetting it to 0 then increasing to 1 after.
Just curious!
Best Regards,
Laurent |
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Wed Feb 06, 2008 1:24 am |
|
|
Why not just delete the line Intcount = 0; ?
This way the Intcount will overflow to 0. (as long as it is an int)
It is not the most dynamic approach, but it works in this case. |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Wed Feb 06, 2008 1:32 am |
|
|
Thanks !
I never thought of that.
Laurent |
|
|
D-Kens
Joined: 09 May 2005 Posts: 35 Location: Toulouse (France)
|
|
Posted: Wed Feb 06, 2008 2:13 am |
|
|
Guess you could also have included your "Intcount++" into the 'if(Intcount<255)', thus increasing only as long as your below 255...
|
|
|
|