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

Thread: Teensy 3.2 Snooze sleep_all_wakeups problems?

  1. #1

    Teensy 3.2 Snooze sleep_all_wakeups problems?

    Hi,

    I recently downloaded and installed Duff's nice Snooze library for a Teensy 3.2 application, and I'm trying to understand the 'sleep_all_wakeups' example. No matter what I do, I seem to only get the '3 blink' response from the built-in LED, which *should* mean that it is getting waked up by the COMPARE trigger on pin 11. However, I have tied pin 11 both HIGH and LOW and still get the same response. Moreover, the 3-blink sequence repeats at almost exactly 5-second intervals, which strongly suggests the trigger is the timer, not the compare pin. If I change the timer parameter from 5000 (ms) to 1000, then the 3-blink sequence occurs every 2 seconds (I'm assuming here that one trigger is lost while the Teensy is awake), which pretty much nails it down. So, it's pretty clear that it is the block labelled "//compare wakeup value" that is triggered rather than the one labelled "lptmr wakeup value".

    Next I changed the timer value from 5000 to 20,000 ms, and noted that the 3-blink sequence now occurs every 20 sec. In between I can cause the same 3-blink sequence to occur by momentarily connecting pin 21 to GND, verifying that the 'digital (pin 21)' trigger is active. However, according to the example code, the digital(21) trigger is supposed to cause the LED to blink only once - not 3 times.

    Am I missing something obvious about this example? Is there any documentation for the return values for SnoozeClass::sleep()?

    Code Follows:

    Code:
    /***************************************
     This shows all the wakeups for sleep
     Expect IDD of  around 1.2mA (Teensy 3.x)
     and IDD of around 900uA for (Teensy LC).
    
     Sleep is the most flexable and any
     interrupt can wake the processor.
    
     Touch interface does not work in sleep
     mode.
     ****************************************/
    #include <Snooze.h>
     // Load drivers
    SnoozeDigital digital;
    SnoozeCompare compare;
    SnoozeTimer timer;
    SnoozeAlarm  alarm;
    // configures the lc's 5v data buffer (OUTPUT, LOW) for low power
    Snoozelc5vBuffer  lc5vBuffer;
    /***********************************************************
     Teensy 3.6/LC can't use Timer Driver with either Touch or
     Compare Drivers and Touch can't be used with Compare.
    
     Teensy 3.x/LC touch interface does not work with sleep.
    
     Teensy LC does not have a rtc so Alarm driver can't be
     used as of yet.
    
     Teensy 3.2 can use any Core Drivers together.
     ***********************************************************/
    #if defined(__MK66FX1M0__)
    SnoozeBlock config_teensy36(digital, alarm, compare);
    #elif defined(__MK64FX512__)
    SnoozeBlock config_teensy35(digital, timer, compare);
    #elif defined(__MK20DX256__)
    SnoozeBlock config_teensy32(digital, timer, compare);
    #elif defined(__MK20DX128__)
    SnoozeBlock config_teensy30(digital, timer, compare);
    #elif defined(__MKL26Z64__)
    SnoozeBlock config_teensyLC(digital, timer, lc5vBuffer);
    #endif
    
    void setup() {
    	pinMode(LED_BUILTIN, OUTPUT);
    	/********************************************************
    	 Define digital pins for waking the teensy up. This
    	 combines pinMode and attachInterrupt in one function.
    
    	 Teensy 3.x
    	 Digtal pins: all pins
    
    	 Teensy LC
    	 Digtal pins: all interrupt able pins
    	 ********************************************************/
    	digital.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type
    	digital.pinMode(22, INPUT_PULLUP, RISING);//pin, mode, type
    
    	/********************************************************
    	 Teensy 3.x only currently.
    
    	 Set RTC alarm wake up in (hours, minutes, seconds).
    	 ********************************************************/
    	alarm.setRtcTimer(0, 0, 10);// hour, min, sec
    
    	/********************************************************
    	 Set Low Power Timer wake up in milliseconds.
    	 ********************************************************/
    	//timer.setTimer(5000);// milliseconds
    	timer.setTimer(20000);// milliseconds
    
    	/********************************************************
    	 Values greater or less than threshold will trigger CMP
    	 wakeup. Threshold value is in volts (0-3.3v) using a 64
    	 tap resistor ladder network at 0.0515625v per tap.
    
    	 parameter "type": LOW & FALLING are the same.
    	 parameter "type": HIGH & RISING are the same.
    
    	 Teensy 3.x/LC
    	 Compare pins: 11,12
    	 ********************************************************/
    	 // trigger at threshold values greater than 1.65v
    	 //compare.pinMode(11, HIGH, 1.65);//pin, type, threshold(v)
    	 // trigger at threshold values less than 1.65v
    	compare.pinMode(11, LOW, 1.65);//pin, type, threshold(v)
    }
    
    void loop() {
    	int who;
    	/********************************************************
    	 feed the sleep function its wakeup parameters. Then go
    	 to deepSleep.
    	 ********************************************************/
    #if defined(__MK66FX1M0__)
    	who = Snooze.sleep(config_teensy36);// return module that woke processor
    #elif defined(__MK64FX512__)
    	who = Snooze.sleep(config_teensy35);// return module that woke processor
    #elif defined(__MK20DX256__)
    	who = Snooze.sleep(config_teensy32);// return module that woke processor
    #elif defined(__MK20DX128__)
    	who = Snooze.sleep(config_teensy30);// return module that woke processor
    #elif defined(__MKL26Z64__)
    	who = Snooze.sleep(config_teensyLC);// return module that woke processor
    #endif
    
    	if (who == 21) { // pin wakeup source is its pin value
    		for (int i = 0; i < 1; i++) {
    			digitalWrite(LED_BUILTIN, HIGH);
    			delay(200);
    			digitalWrite(LED_BUILTIN, LOW);
    			delay(200);
    		}
    	}
    
    	if (who == 22) { // pin wakeup source is its pin value
    		for (int i = 0; i < 2; i++) {
    			digitalWrite(LED_BUILTIN, HIGH);
    			delay(200);
    			digitalWrite(LED_BUILTIN, LOW);
    			delay(200);
    		}
    	}
    
    	if (who == 34) { // compare wakeup value
    		for (int i = 0; i < 3; i++) {
    			digitalWrite(LED_BUILTIN, HIGH);
    			delay(200);
    			digitalWrite(LED_BUILTIN, LOW);
    			delay(200);
    		}
    	}
    
    	if (who == 35) { // rtc wakeup value
    		for (int i = 0; i < 4; i++) {
    			digitalWrite(LED_BUILTIN, HIGH);
    			delay(200);
    			digitalWrite(LED_BUILTIN, LOW);
    			delay(200);
    		}
    	}
    
    	if (who == 36) { // lptmr wakeup value
    		for (int i = 0; i < 5; i++) {
    			digitalWrite(LED_BUILTIN, HIGH);
    			delay(200);
    			digitalWrite(LED_BUILTIN, LOW);
    			delay(200);
    		}
    	}
    }
    TIA,

    Frank

  2. #2
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    921
    If you take the compare out does it work then, it could be that the compare pin is floating around the trip voltage. Or you can ground it.

  3. #3
    Duff,

    I think I mentioned in my original post that I tied the compare line HIGH and LOW both, and neither condition affected the behavior of the code. Just to confirm, I get the same exact behavior with pin 11 tied HIGH and with it tied LOW. The COMPARE block executes whenever the timer times out OR immediately after either pin 21 or pin 22 make a LOW to HIGH transition.

    It appears if the line

    who = Snooze.sleep(config_teensy32);// return module that woke processor

    returns 34 regardless of the actual trigger source.

    Frank

  4. #4
    Quote Originally Posted by paynterf View Post
    Duff,

    I think I mentioned in my original post that I tied the compare line HIGH and LOW both, and neither condition affected the behavior of the code. Just to confirm, I get the same exact behavior with pin 11 tied HIGH and with it tied LOW. The COMPARE block executes whenever the timer times out OR immediately after either pin 21 or pin 22 make a LOW to HIGH transition.

    It appears if the line

    who = Snooze.sleep(config_teensy32);// return module that woke processor

    returns 34 regardless of the actual trigger source.

    Frank
    Duff, am I still missing something here?

    TIA,

    Frank

  5. #5
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    921
    Quote Originally Posted by paynterf View Post
    Duff, am I still missing something here?

    TIA,

    Frank
    If you haven't already done so can you go to my GitHub page and download and install the latest Snooze version, https://github.com/duff2013/Snooze? I'm currently busy with family now but will test this out soon.

  6. #6
    Duff,

    I first downloaded your library about a month ago. I just checked, and the only thing that has changed since then is the addition of a single constant identifier

    (Updated (11/20/18 v6.3.3)

    Added F_CPU 256MHz.

    I can't see how that could possibly affect the problem I'm seeing, but I'm willing to re-download if you think it is necessary ;-).

    Frank

  7. #7
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    921
    I'll be looking at this tomorrow.

  8. #8
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    921
    Thanks for letting me know about this, I have fix for the 3.2 need to test the others then I'll update my GitHub account.

Posting Permissions

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