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

Exit an interrupt ?

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



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

Exit an interrupt ?
PostPosted: Wed Feb 06, 2008 1:04 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Wed Feb 06, 2008 1:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 06, 2008 1:32 am     Reply with quote

Thanks !

I never thought of that.

Laurent
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

PostPosted: Wed Feb 06, 2008 2:13 am     Reply with quote

Guess you could also have included your "Intcount++" into the 'if(Intcount<255)', thus increasing only as long as your below 255...

Wink
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