1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

mplabx wont debug

Discussion in 'Microcontrollers' started by Dr_Doggy, Aug 24, 2016.

  1. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,154
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    You have to physically read the port so the IOC interrupt can latch.
    Code (c):

    void interrupt interupt(void)
    {
    unsigned char dummy;
    setRELAY(1);
    LED(1);
    __delay_ms(300);
    setRELAY(0);
    LED(0);
    Interrupt_occured = 1;
    dummy = PORTA;
    RAIF= 0; // clear flag
    GIE = 1; // enable global interrupts
     
     
    • Like Like x 1
  2. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,011
    Likes:
    317
    Location:
    Brisbane Australia
    Not sure which chip you're using but you may need to set PIE bit as well.

    Mike.
     
  3. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    thanks! was the dummy bit!
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37

    figured better to revive this thread since it s another interrupt problem and i have feeling it will be solved in blink of eye, ie Error Code# ID10T!
    16f688 still, but now using int0/RA2 interrupt -- triggered by IR receiver

    Problem is that when sending ir pulse(RC5), the int0 still triggers, even though i have disabled it and reset flags after, i have created delays and checked hardware for noise:
    ... the second chunk of code is just to show how functions are called and things are setup
    ... the first chunk of code is more of the problem:


    Code (text):

    unsigned int getIR(void)
    {  
        if (RA2 == 0) /// IR DETected on INT0
    {      
            PerimeterDelay = 1200;            // reset IR flag
            if (IRmode > 0){rawLED(IRmode);}  // display on RGB output without timer0 since we are already on interrupt routine
        delayMS(200);                                 // stall a little bit for now, function will soon get alot bigger
        }          
        return 1;                                          // default respnose for now
    }


    void PulseIR(unsigned char count)
    {      
        unsigned char  dummy;
        INTCONbits.INTE = 0;      // THIS LINE SHOULD SHUT INT0 OFF but it dont!
        delayMS(count);           // DELAY SO INT0 can shut off, finish up, and not catch any echos



        PORTC |= 0b00100000;       // turn on IR pulseRC5
    //hardware is tied to 40khz multivibrator
    // scope show IR to be turning on and off  properly

    // removing this line device works properly where leD turns green until
    // (PerimeterDelay=0 then turns magenta, turns green again when
    // triggered  by external IR pulses (tv remote)


    // LEAVING this line in causes the RC5 IR to trigger INT0, causing
    // PerimeterDelay to reset and LED never turns magenta
    // even though previous line clearly says INTE=0;




        delayMS(count);                 // leave IR running for a bit
        PORTC &= 0b11011111;      // IR LED is shutting off properly
        delayMS(count);   // wait for IR echos and maybe circuit noise to disipate
        dummy = PORTA;            // just in case
        INTCONbits.INTF = 0;      /// clear flag
        INTCONbits.INTE = 1;    // reenable    
    }


    void ModePerimeter(void)
    {      
        if (PerimeterDelay == 0)
        {
            setColorB(8-color);       // MAGENTA on timer0 routine
        }
        else if(PerimeterDelay == PerimeterAlert/2)
        {    
            PulseIR(200);               // problematic fucntion
            PerimeterDelay--;      
        }
        else    
        {
            setColorB(color);          //GREEN on timer0 routine
            PerimeterDelay--;
        }  
    }
     



    Code (text):


    void interrupt  INTERRUPT()
    {    
        unsigned char  dummy;
        if(INTCONbits.INTF == 1)   { Remote = getIR(); dummy = PORTA;  }
        else if (INTCONbits.T0IF == 1)
        {      
           runLED(Red,Green,Blue);    // runs RGB led with TMR0
           TMR0 = 200;                        
        }      
           INTCONbits.INTF = 0;
           INTCONbits.T0IF = 0;
    }

    void setup(void)
    {  
        TRISA = 0b11111111;
        PORTA = 0b00000000;
        TRISC = 0b11000011;
        PORTC = 0b00011100;
        ANSEL = 0b00011000;
         
        CMCON0= 0b00000000;
     
     
        OSCCONbits.SCS = 1;
        OSCCONbits.IRCF0 = 1;
        OSCCONbits.IRCF1 = 1;
        OSCCONbits.IRCF2 = 1;
       
     
        ADCON1bits.ADCS  = 6;   //Selecting the clk division factor = FOSC/2
        ADCON0bits.ADFM = 1;    //Result right justified
        ADCON0bits.VCFG = 0;    //Result right justified  
     
     
        OPTION_REGbits.INTEDG  = 0; //cause interrupt at falling edge
        OPTION_REGbits.T0CS = 0;  
        TMR0 = 0;
     
        INTCONbits.INTF = 0; //reset interrupt flag
        INTCONbits.T0IF = 0;
       
       
        delayMS(3000);
     

        INTCONbits.INTE = 1; //enable Interrupt 0 (RA2 as interrupt)
     
        setColorB(color = 2);   // green
        setColorB(0);               // clear it for now
        IRmode = 3;                // Blue

        ei();    // This is like fliping the master switch to enable interrupt
    }
    int main(int argc, char** argv)
    {  
        setup();
        while (1)      
        {      
    ModePerimeter();
     
        }    
        }    
     
     
    Last edited: Jan 14, 2017
  6. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,011
    Likes:
    317
    Location:
    Brisbane Australia
    The INTF bit will still get set and the timer interrupt will still occur. Change if(INTCONbits.INTF == 1) to if(INTF == 1 && INTE==1) and all should be well.

    Mike.
     
    • Like Like x 1
  7. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    thanks, worked like a charm
     

Share This Page