SnoozeSleepPWM does not work

Status
Not open for further replies.

Joegi

Well-known member
I just tried the example code "SnoozeSleepPWM" of the snooze library on a Teensy LC, but is does not work! The (pwm-)pin seems to be either high or low when the Teensy enters sleep mode. I connected a motor driver with motor and set the timer value to "3000" (When I'm using "analogWrite(3, x)" the motor is running at the desired speed)!
I'm using Arduino-IDE V1.8.5 together with Teensyduino 1.40 Beta #2 and Snooze V6.3.0!
Thanks for the answers in advance!
 
I just tried the example code "SnoozeSleepPWM" of the snooze library on a Teensy LC, but is does not work! The (pwm-)pin seems to be either high or low when the Teensy enters sleep mode. I connected a motor driver with motor and set the timer value to "3000" (When I'm using "analogWrite(3, x)" the motor is running at the desired speed)!
I'm using Arduino-IDE V1.8.5 together with Teensyduino 1.40 Beta #2 and Snooze V6.3.0!
Thanks for the answers in advance!
I never tested the Teensy LC with PWM but if I find a fix Teensyduino 1.40 will NOT have the fix since Paul just updated to the latest version of Snooze (v6.3.1). Probably looking at two weeks before I can get to this since I'm I will be traveling for the next two weeks. If you have a github account can you sumit "issue" so I don't forget about this?
 
Thanks!
(You may ask why I care about the amount of power the Teensy uses when a Motor is connected, but the Motor only draws ~50mA!)
 
The problem may be the way that FTMx_SC is reset in the ISR. It differs between LC TPM and T3* FTM. On LC you actually have to write a 1 to reset it. so *FTMx_SC = FTMx_SC_VALUE; probably won't work on LC, though it may not matter since TPM interrupts are not enabled. There may be other issues ...

another brief discussion of TPM vs FTM at https://forum.pjrc.com/threads/4382...cies-Teensy-LC?p=142514&viewfull=1#post142514

EDIT: well, despite not changing the FTMx_SC logic, I could get the example sketch to work on LC (hack) by commenting out
// while (*FTMx_MOD != DEFAULT_FTM_MOD);
in the ISR. ?? Well, i think it's working. It's not hanging, and LED on pin 3 is cycling through different periods and LED_BUILTIN is flashing. It looks the same as when i run the example on T3.2

EDIT 2
: alas, using logic analyzer, PWM doesn't look right on the LC, frequency 5.86khz instead of 488 hz. no PWM during Snooze.sleep() on LC. Duty cycle is changing. The 5.86khz (12*488 ?) might suggest the LC clock didn't get reduced to 2mhz, or the PWM regs didn't get restored when returning to full speed ... further study required

EDIT 3: The LC TPM timer is clocked from PLL and not from F_BUS, and I think max bus speed is 1mhz for LC in VLPW (vs 2mhz for T3*), so DEFAULT_FTM_02_MOD should be 2048-1. Moving the clearIsrFlags() logic into disableDriver(), does properly reset the frequency to 488 hz and the while() doesn't hang, but still no output on pin 3 during Snooze.sleep().

FWIW, here is plot of LC current (ma) with PWM (300ms) and sleep/PWM (100ms, though no output on pin 3). Sampling current every 10 ms.
lcpwmsleep.gif
For T3.2, high's were around 40 ma
 
Last edited:
Thanks for your effort, but I now compared the current consumption of the Teensy LC in sleep-mode and in normal-mode (@24MHz) and the difference is ~5mA. That would be around 10% difference in current consumption of the whole circuit, which is not nothing, but I think I can live with it for now!
 
Ok back home and just started looking at this and I concur with what manitou said so far. The problem as far as I can see is the TPM clock is not active during wait mode (Snooze -> sleep)? Another issue is the LC's TPM registers share the same address as the 3.2 FTM registers but there are slight differences that matter I think. One being the SC register in the LC does not have an option for different clock domains to run the TPM like the FTM in the 3.2. I'm trying to figure out how to run the TPM off the MCGIRLK clock but haven't had any success yet. The LC should be able to keep the system clock running during wait mode like the 3.2 so the MCGIRCLK is probably the wrong path but I just want to see something work!
 
Got it working... But the changes effect other parts of the library that I need to figure a workaround for which might require a substantial change to the way Snooze works but I had thought I would have to do anyway at some point. Really all these different mcu's require different driver code that I might just decouple all of the Teensy's into their own library of sorts, still only one folder. I have feeling in the long run alot of libraries would benefit from this since trying to debug with all these if def statements for KINETISK or KINETISL is real pain in the ass especially when dealing with such low level code. Even my own code I spend to much time on trying kludge together hardware drivers that are mostly the same but different enough that making all the Teensy's work becomes to costly of my time.
 
Got it working... But the changes effect other parts of the library that I need to figure a workaround for which might require a substantial change to the way Snooze works but I had thought I would have to do anyway at some point. Really all these different mcu's require different driver code that I might just decouple all of the Teensy's into their own library of sorts, still only one folder. I have feeling in the long run alot of libraries would benefit from this since trying to debug with all these if def statements for KINETISK or KINETISL is real pain in the ass especially when dealing with such low level code. Even my own code I spend to much time on trying kludge together hardware drivers that are mostly the same but different enough that making all the Teensy's work becomes to costly of my time.

Thank you very much for your effort!
 
Just FYI, I updated Snooze last night so Sleep pwm example should work now with the TeensyLC, there are few details I still need to figure out but it does run.
 
Status
Not open for further replies.
Back
Top