• AVR Freaks

Hot!PIC does not wake up everytime

Author
Simlock
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2017/03/27 08:15:33
  • Location: 0
  • Status: offline
2019/06/24 06:17:25 (permalink)
0

PIC does not wake up everytime

Hello,
 
I use a PIC18F66K40 and I want to put my PIC in standby and wake it up only when the state changes on some pins.
 
But I can't understand why the alarm clock doesn't work all the time.
 
My interrupt config :
void HARD_EnableInterrupts (void)
{
    INTCONbits.GIE = 1; // Global Interrupt Enable bit
    INTCONbits.PEIE = 1; // Peripheral Interrupt Enable bit
    
    PIE3bits.RC1IE = 1; // EUSART1 Receive Interrupt Enable bit
    PIE0bits.IOCIE = 1; // Interrupt-on-Change Enable bit
    PIE5bits.TMR1IE = 1; // TMR1 to PR1 Match Interrupt Enable bit
    
    // Interrupt On Change configuration
    IOCCPbits.IOCCP0 = 1; // Interrupt on positive edge on RC0
    IOCCNbits.IOCCN1 = 1; // Interrupt on negative edge on RC1
    IOCCPbits.IOCCP2 = 1; // Interrupt on positive edge on RC2
    IOCBNbits.IOCBN1 = 1; // Interrupt on negative edge on RB1
    
}

 
My interrupt code :
void __interrupt() ISR (void)
{
    
    /*
     * Interrupt On Change
     */
    if(PIE0bits.IOCIE == 1 && PIR0bits.IOCIF == 1)
    {
        
        // Interrupt from BP CONFIG
        if (IOCCFbits.IOCCF1)
        {
            IOCCFbits.IOCCF1 = 0;
            cptConfig_l = 0;
            reveil_t = CONFIG;
        }
        // Interrupt from Sensor 1
        else if (IOCCFbits.IOCCF2)
        {
            IOCCFbits.IOCCF2 = 0;
            reveil_t = SENSOR1;
        }
        // Interrupt from Sensor 2
        else if (IOCCFbits.IOCCF0)
        {
            IOCCFbits.IOCCF0 = 0;
            reveil_t = SENSOR2;
        }
        // Interrupt from RTC
        else if (IOCBFbits.IOCBF1)
        {
            IOCBFbits.IOCBF1 = 0;
            reveil_t = BATTERY;
        }
        else
        {
            reveil_t = NOTHING;
        }
    }
    
    
    /*
     * Interrupt On UART 1
     */
    if(PIE3bits.RC1IE == 1 && PIR3bits.RC1IF == 1)
    {
        reveil_t = PC_COMM;
        data_l = RC1REG;
        
    }
    
    
    /*
     * Interrupt on Timer 1
     */
    if (PIE5bits.TMR1IE && PIR5bits.TMR1IF)
    {
        PIR5bits.TMR1IF = 0;
        TMR1H = 0xE0;
        TMR1L = 0xC0;
        
        
        // Increment all counters
        PC_IncrementCounter ();
        GSM_IncrementCounters ();
        MP3_IncrementCounters ();
        cptSeconds_l++;
        cptConfig_l++;
        
        // Every seconds
        if (cptSeconds_l >= 1000)
        {
            CAPT_IncrementCounter ();
            cptGoSleep_l++;
            cptSeconds_l = 0;
        }
        
    }
    
}

 
Do you have a idea ? Thank you for your help !
#1

2 Replies Related Threads

    Simlock
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2017/03/27 08:15:33
    • Location: 0
    • Status: offline
    Re: PIC does not wake up everytime 2019/06/24 07:50:06 (permalink)
    0
    Okay, I'm sorry I posted a message for nothing.
     
    When I wake up the PIC, my circuit returns the power to my FTDI. And so I receive data that distorts the start of my program.
    #2
    pcbbc
    Super Member
    • Total Posts : 1373
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: PIC does not wake up everytime 2019/06/24 07:57:34 (permalink)
    0
    Most likely because if you have an interrupt on change, and then at the same time, or while you are dealing with checking the IOC flags, you have a UART1 receive interrupt, and that then overwrites the variable reveil_t = PC_COMM.  Now you have missed whatever IOC event you had flagged as being detected: CONFIG, SENSOR1, SENSOR2 or BATTERY.
     
    Also, where are you checking reveil_t?  In your "main" function?  What does that code look like?
    How quickly can you check reveil_t?  What happens if you get another interrupt, and the ISR then updates reveil_t, before you get around to checking the first one?
     
    However we are only guessing, because you have not posted you complete code.  If you have a problem with some code and need to ask for help you are not qualified to decide which code you should/should not post for others to be able to help you.
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5