Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: SnoozeSleepPWM does not work

  1. #1
    Member
    Join Date
    Jan 2014
    Location
    Cologne, germany
    Posts
    54

    SnoozeSleepPWM does not work

    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!

  2. #2
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    961
    Quote Originally Posted by Joegi View Post
    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?

  3. #3
    Member
    Join Date
    Jan 2014
    Location
    Cologne, germany
    Posts
    54
    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!)

  4. #4
    Senior Member
    Join Date
    Sep 2013
    Location
    Hamburg, Germany
    Posts
    891

  5. #5
    Member
    Join Date
    Jan 2014
    Location
    Cologne, germany
    Posts
    54
    Thanks!!!!!!

  6. #6
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,077
    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/43828...l=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.
    Click image for larger version. 

Name:	lcpwmsleep.gif 
Views:	38 
Size:	41.5 KB 
ID:	11713
    For T3.2, high's were around 40 ma
    Last edited by manitou; 10-09-2017 at 01:54 PM.

  7. #7
    Member
    Join Date
    Jan 2014
    Location
    Cologne, germany
    Posts
    54
    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!

  8. #8
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    961
    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!

  9. #9
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    961
    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.

  10. #10
    Member
    Join Date
    Jan 2014
    Location
    Cologne, germany
    Posts
    54
    Quote Originally Posted by duff View Post
    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!

  11. #11
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    961
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •