Teensy 3.2 Snooze sleep_all_wakeups problems?

Status
Not open for further replies.

paynterf

Well-known member
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
 
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.
 
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,

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
 
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
 
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.
 
duff,

It looks like it is (mostly) working now. Here's a printout from your 'sleep_all_wakeups' example:

Code:
Opening port
Port open
Port open
Timer Driver number indicator: 36 | index: 0
Port open
Timer Driver number indicator: 36 | index: 1
Port open
Timer Driver number indicator: 34 | index: 2
Port open
Port open
Timer Driver number indicator: 34 | index: 4
Port open
Timer Driver number indicator: 34 | index: 5
Port open
Port open
Timer Driver number indicator: 34 | index: 7
Port open
Port open
Timer Driver number indicator: 34 | index: 9
Port open
Port open
Timer Driver number indicator: 34 | index: 11
Port open
Starting...
Port open
Timer Driver number indicator: 36 | index: 0
Port open
Timer Driver number indicator: 36 | index: 1
Port open
Timer Driver number indicator: 36 | index: 2
Port open
Timer Driver number indicator: 34 | index: 3
Port open
Timer Driver number indicator: 34 | index: 5
Port open
Port open
Timer Driver number indicator: 36 | index: 7
Port open
Starting...
Port open
Timer Driver number indicator: 36 | index: 0
Port open
Timer Driver number indicator: 36 | index: 1
Port open
Timer Driver number indicator: 22 | index: 2
Port open
Port open
Timer Driver number indicator: 36 | index: 4
Port open
Timer Driver number indicator: 22 | index: 5
Port open
Timer Driver number indicator: 22 | index: 6
Port open
Timer Driver number indicator: 36 | index: 7
Port open
Timer Driver number indicator: 21 | index: 8
Port open
Timer Driver number indicator: 21 | index: 9

However, I think there might still be a buglet floating around somewhere; on a couple of occasions the program seemed to hang and the timer 'wakup' never occurred after that. I had to recycle power on the Teensy 3.2 to get it going again.

Thanks for all the work you have done on this wonderful library!

Frank
 
I didn't see any lockups but maybe there is something I missed, I'll take look at this after the holidays.
 
Status
Not open for further replies.
Back
Top