Author Topic: About multiple interrupt ISR (PIC)  (Read 6047 times)

0 Members and 1 Guest are viewing this topic.

Offline danielksTopic starter

  • Contributor
  • Posts: 19
  • Country: my
  • Newbie from Malaysia
About multiple interrupt ISR (PIC)
« on: October 24, 2011, 04:49:53 pm »
Can anyone teach me how to write the coding for Interrupt polling type in Hi-tech C ?

For example Timer Interrupt and CCP interrupt together...  :'(
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11705
  • Country: my
  • reassessing directives...
Re: About multiple interrupt ISR (PIC)
« Reply #1 on: October 24, 2011, 08:12:42 pm »
loop:
   if (PIR1[CCP1IF]) doMe();
   if (PIR1[TMR1IF]) doYou();
goto loop;

something like that?
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline danielksTopic starter

  • Contributor
  • Posts: 19
  • Country: my
  • Newbie from Malaysia
Re: About multiple interrupt ISR (PIC)
« Reply #2 on: October 25, 2011, 05:01:31 am »
Now I have a coding which consist of 5 interrupts in the ISR. But i only try with 1 timer interrupt and 1 CCP interrupt. I set the timer interrupt priority to high and CCP to low but when ever CCP interrupt happen, the program hang. if I set more than 1 CCP interrupt non of the interrupt will works and program Hang.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11705
  • Country: my
  • reassessing directives...
Re: About multiple interrupt ISR (PIC)
« Reply #3 on: October 25, 2011, 01:41:35 pm »
your code pls? ... this topic should be moved to microcontroller section.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline danielksTopic starter

  • Contributor
  • Posts: 19
  • Country: my
  • Newbie from Malaysia
Re: About multiple interrupt ISR (PIC)
« Reply #4 on: October 25, 2011, 02:25:36 pm »
sorry about that..  :-[

my coding..

void interrupt ISR()
{   
      if(TMR0IE==1&&TMR0IF==1)         
         {
            t++;            //increase counter by 1
            if(t<s1){
               motor1=1;
            }
            if(t<s2){
               motor2=1;
            }
            if(t<s3){
               motor3=1;
            }
            if(t<s4){
               motor4=1;
            }
                                                                                                                    
            if(t==s1){
               motor1=0;
            }
            if(t==s2){
               motor2=0;
            }
            if(t==s3){
               motor3=0;
            }
            if(t==s4){
               motor4=0;
            }
   
            if(t==1000) //Reset counter to 0
            {
               t=0;
            }
         
         TMR0IF=0;  //Reset interrupt flag to 0   
         TMR0=250;
         
      }
      
if (CCP4IE==1&&CCP4IF==1)
   {
   count1++;
   CCP4IF=0;
      if (count1==1)
         {
         t1=TMR1;
         count1==1;
         CCP4CON=0b00000100;     //falling edge detection
         }
      if (count1==2)
         {
         t2=TMR1;
         count1=0;
         CCP4CON=0b00000101;   //rising edge detection
         }
         TMR1=0;
         
   }
   
   
   if(CCP5IE==1 && CCP5IF==1)
   {
   count++;
   CCP5IF=0;
      if (count==1)
         {
         t11=TMR1;
         count==1;
         CCP5CON=0b00000100;     //falling edge detection
         }
      if (count==2)
         {
         t22=TMR1;
         count=0;
         CCP5CON=0b00000101;   //rising edge detection
         }
         TMR1=0;
   }
}

With the CCP5 interrupt in the coding just wont run. it hangs.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11705
  • Country: my
  • reassessing directives...
Re: About multiple interrupt ISR (PIC)
« Reply #5 on: October 25, 2011, 06:14:12 pm »
first you put ambiguity to the compiler... CCP5IE==1 && CCP5IF==1 could be...
Code: [Select]
((CCP5IE==1) && CCP5IF)==1
(CCP5IE==(1 && CCP5IF))==1
CCP5IE==((1 && CCP5IF)==1)
this semantics ambiguity is very hard to acertain. maybe there's operator's presedence that make it right, but its safer practice to clearly state what you want, ie i think it should be... if ((CCP5IE==1) && (CCP5IF==1)), note the bracketting.

second... whats this? 4th line (arrowed)? i cannot compile that. i dont think thats necessary.
Code: [Select]
if (count==1)
{
t11=TMR1;
count==1;     //      <---------------- ????????????
CCP5CON=0b00000100;     //falling edge detection
}
i cannot trace the hanging procedure, try clearing up your code as stated above and see if its working.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf