Hot![Solved] Timers not working in sleep mode

Author
stu1232
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2012/06/07 23:14:48
  • Location: 0
  • Status: offline
2012/10/25 21:58:10 (permalink)
0

[Solved] Timers not working in sleep mode

Hello all,
 
I have a PIC24FJ128GA306 on which I have a magnetic reed switch connected to an input assigned to T2CLK. The timer is essentially operating as a counter. However, it refuse to count when sleeping. If I replace the sleep instruction with a delay sequence then it will count fine. I am using this pic in a low power situation and would like to be able to go into sleep mode (having delays is not really a viable option). Sleep uses the watchdog timer to wake up.
 
The data sheet clearly states all timers will run in sleep mode either from LPRC or external clocking source (ie reed switch). Clearly I'm doing something wrong but I just can't figure it out. Extensive searching on the net reveals nothing. The pin shares functionality with RTCC out and an LCD controller pin but I have disabled both features (RTCC is running but output is disabled)
 
Here's the relevant code:
Initialisation:
void init_pulse(){  
RPINR3bits.T2CKR = 2; //RD8
T2CONbits.T32 = 1; //32 bit mode
T2CONbits.TCS = 1; //External source
PR2 = 0xff; PR3 = 0xff;
T2CONbits.TON = 1; //on
TMR2 = 0;
TMR3 = 0;
}
 

 
Reading value:
pulse_count = TMR3HLD;  
pulse_count  = pulse_count << 16;
pulse_count += TMR2;
TMR2 = 0;
TMR3HLD = 0;
volume = pulse_count * pulse_scalingf;

 
Sleep and/or delay:
for(i=0;i<sleep_cycles;i++)  
{
asm volatile ( "CLRWDT\n" 
"BSET RCON, #5\n" //wdt en
"NOP\n" 
"NOP\n" 
"NOP\n" 
"PWRSAV #0");
}
// for(i=0;i<35;i++)
// __delay_ms(250);

 
Any help/hints would be greatly appreciated
post edited by stu1232 - 2012/10/28 18:10:03
#1

3 Replies Related Threads

    Batgoy
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2004/06/15 04:33:51
    • Status: offline
    Re:Timers not working in sleep mode 2012/10/26 06:19:50 (permalink)
    2 (1)
    In DS39704A-page 14-21:
     
    "When the device enters Sleep mode, the system clock is disabled. If the timer module is running
    from the internal clock source (FOSC/2), it will also be disabled.
    A Type A timer is different from the other timer modules because it can operate asynchronously
    from the system clock source. Because of this distinction, the Type A time base module can
    continue to operate during Sleep mode."
     
    i.e. use Timer 1 Smile
    #2
    stu1232
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2012/06/07 23:14:48
    • Location: 0
    • Status: offline
    Re:Timers not working in sleep mode 2012/10/28 18:12:41 (permalink)
    0
    Batgoy, you are correct it seems. I tested with Timer 1 and it works in sleep mode. It seems the sync block in the diagrams are the limiting factor. The datasheet threw me with this text in the timer 2/3 and 4/5 section:
    They also support these features:
    • Timer Gate Operation
    • Selectable Prescaler Settings
    Timer Operation during Idle and Sleep modes
     • Interrupt on a 32-Bit Period Register Match

    I don't see how timers 2/3 and 4/5 can run in sleep mode because they is a sync step in every possible configuration. It looks to me like a datasheet typo.
     
    Well, it is solved now, although I don't get to use a 32bit timer/counter but I can work around that easily.
    #3
    RDS Cliff
    Junior Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2016/09/23 11:50:05
    • Location: 0
    • Status: offline
    Re:Timers not working in sleep mode 2018/11/05 23:29:05 (permalink)
    0
    Deleted
    post edited by RDS Cliff - 2018/11/05 23:45:23
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5