+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Junior Member level 3
    Points: 1,189, Level: 7

    Join Date
    Sep 2012
    Posts
    31
    Helped
    0 / 0
    Points
    1,189
    Level
    7

    Problem triggering interrupts for Motion Feedback-Input capture mode module in PIC18F

    Hi,

    I Am trying (for now just using the MPLABX simulator) to trigger an interrupt each time any of the associated PINs (CAP1,2 & 3) changes state.

    If I configure the MCU this way:

    Code:
    TRISAbits.TRISA2 = 1;
        TRISAbits.TRISA3 = 1;
        TRISAbits.TRISA4 = 1;
        
        T5CONbits.TMR5ON = 1; 
        
    
        CAP1CONbits.CAP1M0 = 0; 
        CAP1CONbits.CAP1M1 = 0;
        CAP1CONbits.CAP1M2 = 0;
        CAP1CONbits.CAP1M3 = 1;
    
        CAP2CONbits.CAP2M0 = 0; 
        CAP2CONbits.CAP2M1 = 0;
        CAP2CONbits.CAP2M2 = 0;
        CAP2CONbits.CAP2M3 = 1;
    
        CAP3CONbits.CAP3M0 = 0; 
        CAP3CONbits.CAP3M1 = 0;
        CAP3CONbits.CAP3M2 = 0;
        CAP3CONbits.CAP3M3 = 1; 
     
        
        PIR3bits.IC1IF = 0;
        PIR3bits.IC2QEIF = 0;
        PIR3bits.IC3DRIF = 0;
        
        PIE3bits.IC1IE = 1;
        PIE3bits.IC2QEIE = 1;
        PIE3bits.IC3DRIE = 1; 
    
        INTCONbits.PEIE = 1; 
        
        INTCONbits.GIE = 1;
    The ISR is this one:

    Code:
    void interrupt isr(void)
    {
       
        step();
        
        if (contador == 5)
        {
            contador = 0;
        }
        else
        {
            contador++;
        }
        
        PIR3bits.IC1IF = 0;
        PIR3bits.IC2QEIF = 0;
        PIR3bits.IC3DRIF = 0;
        
    }
    And then force a PIN change using the stimulus on any of the CAPx pins, I observe that the corresponding PIR3 bit is set, but the ISR is never triggered. I tried with a watchpoint and it is evident too due to the fact that, each time the ISR is triggered the variable "contador" is incremented, something that never happens...

    I tried to play changing the order in which each flag is activated with no success. Is anything I am missing?

    •   AltAdvertisment

        
       

  2. #2
    Junior Member level 1
    Points: 130, Level: 1

    Join Date
    Jan 2017
    Posts
    15
    Helped
    0 / 0
    Points
    130
    Level
    1

    Re: Problem triggering interrupts for Motion Feedback-Input capture mode module in PI

    Try the fonction case instade of the fonction if



    •   AltAdvertisment

        
       

  3. #3
    Junior Member level 3
    Points: 1,189, Level: 7

    Join Date
    Sep 2012
    Posts
    31
    Helped
    0 / 0
    Points
    1,189
    Level
    7

    Re: Problem triggering interrupts for Motion Feedback-Input capture mode module in PI

    Quote Originally Posted by emko123456789 View Post
    Try the fonction case instade of the fonction if

    You mean inside the ISR?. It doesn´t even reach it, it is never executed so I don´t see how that would solve anything...



    •   AltAdvertisment

        
       

  4. #4
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    125 / 125
    Points
    5,417
    Level
    17

    Re: Problem triggering interrupts for Motion Feedback-Input capture mode module in PI

    1. Which PIC18F are you using ?
    2. Does the Pins you have used for External Interrupt sensing has ADC and Or Comparator functions ?
    3. If yes, Have you disabled them ?



  5. #5
    Junior Member level 3
    Points: 1,189, Level: 7

    Join Date
    Sep 2012
    Posts
    31
    Helped
    0 / 0
    Points
    1,189
    Level
    7

    Re: Problem triggering interrupts for Motion Feedback-Input capture mode module in PI

    Quote Originally Posted by Okada View Post
    1. Which PIC18F are you using ?
    2. Does the Pins you have used for External Interrupt sensing has ADC and Or Comparator functions ?
    3. If yes, Have you disabled them ?
    The MCU is the pic18f4431.

    When I originaly posted I forgot to set the Pins to Digital (they were in their default status, as Analog). But I recently solved that with no effect. ISR is still not triggered. The code is now like this:

    Code:
     TRISAbits.TRISA2 = 1;
        TRISAbits.TRISA3 = 1;
        TRISAbits.TRISA4 = 1;
        ANSEL0bits.ANS2 = 0;
        ANSEL0bits.ANS3 = 0;
        ANSEL0bits.ANS4 = 0;
        
     
        T5CONbits.TMR5ON = 1;       
        
       
        CAP1CONbits.CAP1M0 = 0; 
        CAP1CONbits.CAP1M1 = 0;
        CAP1CONbits.CAP1M2 = 0;
        CAP1CONbits.CAP1M3 = 1;
        CAP2CONbits.CAP2M0 = 0; 
        CAP2CONbits.CAP2M1 = 0;
        CAP2CONbits.CAP2M2 = 0;
        CAP2CONbits.CAP2M3 = 1;
        CAP3CONbits.CAP3M0 = 0; 
        CAP3CONbits.CAP3M1 = 0;
        CAP3CONbits.CAP3M2 = 0;
        CAP3CONbits.CAP3M3 = 1; 
        
        PIR3bits.IC1IF = 0;
        PIR3bits.IC2QEIF = 0;
        PIR3bits.IC3DRIF = 0;
        
    
        PIE3bits.IC1IE = 1;
        PIE3bits.IC2QEIE = 1;
        PIE3bits.IC3DRIE = 1;      
    
    
        INTCONbits.PEIE = 1;     
        
    
        INTCONbits.GIE = 1;



  6. #6
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    125 / 125
    Points
    5,417
    Level
    17

    Re: Problem triggering interrupts for Motion Feedback-Input capture mode module in PI

    Have you enabled pullups on those Capture pins ? Or do you have pullup resistors on those input pins ?


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  7. #7
    Junior Member level 3
    Points: 1,189, Level: 7

    Join Date
    Sep 2012
    Posts
    31
    Helped
    0 / 0
    Points
    1,189
    Level
    7

    Re: Problem triggering interrupts for Motion Feedback-Input capture mode module in PI

    Quote Originally Posted by Okada View Post
    Have you enabled pullups on those Capture pins ? Or do you have pullup resistors on those input pins ?
    There is no circuit, I am using the MPLABX simulator. I think there are no internal pullups in PORTA, which is the one linked to the Motion Feedback module



  8. #8
    Junior Member level 3
    Points: 1,189, Level: 7

    Join Date
    Sep 2012
    Posts
    31
    Helped
    0 / 0
    Points
    1,189
    Level
    7

    Re: Problem triggering interrupts for Motion Feedback-Input capture mode module in PI

    It is apparently a limitation of the MPLABX simulator and the PIC18F series. It does not support the Motion Feedback module. Tested in a real circuit and it works.



--[[ ]]--