Menu

Wake up from sleep using timer1

Help
2016-04-11
2016-04-12
  • David Stephenson

    Is this possible? I am using a 16F1705 and I want to use a clock crystal to wake up the processor from sleep after an accurate (and precise) number of seconds (the watch dog timer is just is proving to be not accurate enough).

     
  • tony golding

    tony golding - 2016-04-12

    as per the datasheet it should be possible with external clock source/xtal.

    page 250

    25.8 Timer1 Operation During Sleep
    Timer1 can only operate during Sleep when setup in
    Asynchronous Counter mode. In this mode, an external
    crystal or clock source can be used to increment the
    counter. To set up the timer to wake the device:
    • TMR1ON bit of the T1CON register must be set
    • TMR1IE bit of the PIE1 register must be set
    • PEIE bit of the INTCON register must be set
    • T1SYNC bit of the T1CON register must be set
    • TMR1CS bits of the T1CON register must be
    configured
    • T1OSCEN bit of the T1CON register must be
    configured
    The device will wake-up on an overflow and execute
    the next instructions. If the GIE bit of the INTCON
    register is set, the device will call the Interrupt Service
    Routine.

    tony

     
  • David Stephenson

    Yes that works, thanks. I was looking for a GCBasic solution, but this is an unusual thing to want to do so I suspose it is not covered. So just to summarize the following lines are needed.

    t1con=b'10111101' 'timer1 1:8
    intcon.6=1
    pie1.0=1
    .
    .
    sleep
    nop
    pir1.0=0 'reset interrupt

    Yes don't forget to reset the interrupt flag.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.