AnsweredHot!PIC24FJ128GA204, Can Timer 4 be setup to wake from sleep using the LPRC clock?

Author
awolfe
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2009/08/20 09:52:07
  • Location: Ashland, OH
  • Status: offline
2018/02/09 15:29:37 (permalink)
0

PIC24FJ128GA204, Can Timer 4 be setup to wake from sleep using the LPRC clock?

I've looked through the datasheet and the reference manual, and I don't have a clear understanding still.  I have the WDT enabled, using the LPRC as the clock source, so the LPRC should still be running during sleep mode.  Timer 4 block diagram seems to indicate that the LPRC should be able to run Timer 4 during sleep.  I have Timer4 setup as follows:
#define HardwareUpdate_Timebase 500 //Hz (2mS interval)
#define TmrLPRC 2 // TECS bits to select a LPRC clock source

    //Setup interrupt driver using Timer
    _T4ON = OFF; //Turn off
    _T4SIDL = OFF; //Turn off in IDLE mode
    _T4GATE = OFF; //Turn off Gated Time Accumulation Enable bit
    _T4CS = ON; //Clock source selected by TECS bits
    _T4TECS = TmrLPRC;

    //ISR Freq = ((LPRC freq.) / Prescaler) / PR4)
    //Set pre-scaler
    //11 = 1:256
    //10 = 1:64
    //01 = 1:8
    //00 = 1:1
    _T4CKPS0 = 0;
    _T4CKPS1 = 0;

    PR4 = (int)(31000/HardwareUpdate_Timebase);

    _T4IF = Clear; //Clear Interrupts
    _T4IE = Enable; //Turn on Interrupt
    _T4ON = ON; //Turn on timer

 
When I go to sleep the Timer 4 stops, I get woken up by the WDT instead.
 
The family reference manual indicates that the only way a timer can wake up the chip is for Timer 1 to be configured with an external clock source.  Is that right?  The only way to time the wake up period using an internal source is with the WDT?
 
Thanks for any feedback.

A Wolfe
#1
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2765
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: PIC24FJ128GA204, Can Timer 4 be setup to wake from sleep using the LPRC clock? 2018/02/09 16:05:34 (permalink)
0
In sleep mode the module is disabled so will not do nothing.
In idle mode the timer continues.
 
Download this document from MC, it explains more about sleep and idle modes.
Section 11. Timers

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#2
RISC
Super Member
  • Total Posts : 5355
  • Reward points : 0
  • Status: offline
Re: PIC24FJ128GA204, Can Timer 4 be setup to wake from sleep using the LPRC clock? 2018/02/09 16:39:22 (permalink) ☼ Best Answerby awolfe 2018/02/12 09:53:23
5 (1)
Hi,
 
You can indeed wake up the CPU in SLEEP mode because LPRC is a separate oscillator (see figure 9-1 of the datasheet).
However, the trick is that the timer you want to use MUST be asynchronous, i.e. not synchronized by the internal clock as it is stopped.
If you look carefully at the figure 13-1, you will notice a small bloc called SYNC between PRESCALER and TMR2 (TMR4). Due to this SYNC box, TMR2 and TMR4 cannot wake up this device in SLEEP mode.
you will need to use either TMR1 / TMR3 or TMR5 which are asynchronous (they don't have this SYNC unit) figure 12-1 and 13-3.
 
Regards
#3
awolfe
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2009/08/20 09:52:07
  • Location: Ashland, OH
  • Status: offline
Re: PIC24FJ128GA204, Can Timer 4 be setup to wake from sleep using the LPRC clock? 2018/02/12 10:04:07 (permalink)
0
Thank you for the feedback... I had missed noticing that SYNC block in the diagram, I was focused on the gate sync control.  I switched to TMR1 and it is indeed working now.
 
As a side note... I think the Family reference manual should be updated with this information...  "Section 14 Timers, 14.12.1 Timer Operation in Sleep Mode" (DS39704A-page 14-21) is not correct with this information in mind.

A Wolfe
#4
Jump to:
© 2018 APG vNext Commercial Version 4.5