简体   繁体   中英

Time1 Interrupt wakes up Microcontroller from sleep

I added an external 32KHz crystal to be used with Timer1 as a real time clock on PIC18F87J11 . Everything works good and Timer1 is able to increment even during sleep mode. However, I noticed that upon every interrupt period the MicroController wakes up. My ultimate goal is to reduce power consumption and at the same time be able to accurately keep track of time. I know it only wakes up for less than a second but is there a way to prevent it from waking up unless I want it to and still be able to keep track of time? I basically want to keep the Microcontroller in sleep mode for few hours, then wake up to do something and go back to sleep.

These are my Timer1 settings:

 // Timer 1 Settings
    RCONbits.IPEN = 1; // Enable interrupt system priority feature
    INTCONbits.GIEL = 1; // Enable low priority interrupts

    // 1:1 Prescale value
    T1CONbits.T1CKPS1 = 0;
    T1CONbits.T1CKPS0 = 0;
    T1CONbits.RD16 = 1; // Enables register read/write of TImer1 in one 16-bit operation
    T1CONbits.T1RUN = 1; // Device clock is derived from Timer1 oscillator
    T1CONbits.T1OSCEN = 1; // Timer1 oscillator is enabled
    T1CONbits.TMR1CS =1; // Use Internal Clock
    T1CONbits.T1SYNC =1; // Do not synchronize external clock input

    PIE1bits.TMR1IE = 1;
    IPR1bits.TMR1IP = 0; // Timer 1 -> Low priority interrupt group
    PIE1bits.TMR1IE = 1; // Enable Timer1 interrupt

   // To get 1 second interrut period
    TMR1H = 0x80 ;     // preset for timer1 MSB register
    TMR1L = 0x00 ;     // preset for timer1 LSB register

    // Enable Timer 1
    T1CONbits.TMR1ON = 1;

It depends how long you can have the timer interrupt period set to. If it could be set to an hour, for example, you could have it wake every hour, increment the time, then sleep. Chose the maximum timer prescale value and maximum compare value for the timer. Calculate what that gives as that longest time between interrupts.

However, it is quite normal to wake once as second, update the timer, check if anything needs doing then go back to sleep if not. The MSP430, which is particularly good at ultra low power stuff, can work like this and take an average current in the region of hundreds of nano Amps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM