I want to also explore circuit design, commonly used chips and such related to low power also with this thread, that current sticky thread has a lot of good info but is really cumbersome to find the useful nuggets. I'm planning on consolidating it here. The first bunch of pages are speculations on how to put the teeny into a low power state which is already well established now.Your wonderful library is already referenced in a Sticky thread in the "Project Gudance" section of the forum, called "Teensy Quick Reference, Code Examples, Tips & Tricks".
Q1: Yes, the Snooze library currently configures the pin and attaches a interrupt handler inside the library. You will most likely have to reconfigure that pin with the IR library after sleeping this is a known limitation, I'm looking at how to solve this issue with new version of Snooze with trying to save the current state of the pin (registers and irq handler) before sleeping and reconfiguring it after waking to not have these types of issues. It's actually kinda hard but I'm trying.I have questions as well. I looked through the examples and it seems to relatively straight forward how to wake up the Teensy LC I am using in my project.
What I am trying to do is easy to describe. I am designing a little IR remote controlled lighting system. hte last three posts on that blog pertain to this project.
Currntly when turned off it uses 13-14 mA of current when turned off.
I'd like to put the Teesny into sleep/hibernate when turned off and would like to have the IR pin wake the Teesny up when it receiveds a signal from the remote. Ultimately I want to be able to run this light using rechareable batteries.
It seems I'd simply have to confirure the pin using config.pinMode(PIN, INPUT_PULLUP, RISING);
Question 1: If the Infrared Library already useses an Interrupt - not sure if it dues - on this pin would this conflict or can this be resolved using differnt Interrupt priorities. ?
Question 2: It is not apparent to me what code actually puts the Teesny into sleep mode other han the Snooze block in loop(). I don't see in the example code how I could the teensy into sleep mode using code that is only executed when I press the corresponding "off" button on the remote ?
Yes, configure the SnoozeBlock for the "setTimer" wakeup. It uses the Low Power Timer (16bit) with the LPO clock so you have 1 ms resolution.Glad to see this...I tried to use your library a few months ago, maybe I succeeded but I wasn't sure about a few things and didn't have time to ask.
I think making this capability easily accessible will be very valuable (for me at least) since power usage is a critical issue with wearable and other appallingly small devices and Teensy 3.1 uses ~20 mA in its natural state. I'd like to learn how to put the K20 to sleep for x milliseconds, wake it up either periodically or on interrupt and when it's done its work go back to sleep.
I don't know if this kind of feedback is what you had in mind, but I look forward to seeing more info and a how-to on Low Power operations in one place.
Ummm maybe, I'm working on a new version that will add some hooks for before and after sleeping the teensy that could be used for this for the time being. These hooks would be new c++ classes that you write for user specific things like this that get called through inheritance through the Snooze library. If I get one of these I would consider adding it to Snooze's core structure but since its totally different chip the low power instructions are probably much different, is this at least an arm chip?The ESP8266 is an obvious choice for attention here with the wifi being quite a power hog. It is quite a versatile chip capable of performing many of the same tasks as the Teensy as a host to sensors, etc. but it only has 9 or so GPIOs. It can be programmed via an Arduino IDE...I am starting to se it as a standalone host for flight control and robotics. I wonder if your Snooze library could be adapted to work with this chip?
I want to also explore circuit design, commonly used chips and such related to low power also with this thread, that current sticky thread has a lot of good info but is really cumbersome to find the useful nuggets. I'm planning on consolidating it here. The first bunch of pages are speculations on how to put the teeny into a low power state which is already well established now.
Q1: Yes, the Snooze library currently configures the pin and attaches a interrupt handler inside the library. You will most likely have to reconfigure that pin with the IR library after sleeping this is a known limitation, I'm looking at how to solve this issue with new version of Snooze with trying to save the current state of the pin (registers and irq handler) before sleeping and reconfiguring it after waking to not have these types of issues. It's actually kinda hard but I'm trying.
Q2: There are three functions currently, sleep, deepSleep and hibernate. The SnoozeBlock is to configure what will wake it up, pin, timer, rtc, tsi , etc. The deepSleep and hibernate put the processor into a real low power state but is limited in what can wake it, "sleep" on the other hand is very versatile and can use any interrupt to wake it. While saying that about the sleep function I tried to keep the wake ups similar for all three functions. My new version I'm hoping will open up so new avenues for configuring the teensy for better integration into peoples projects.
Is this the IRremote library from the teensy install? Can I run it without any hardware?I have a checkIR() routine in my loop(). Once it receives the "off" signal this checkIR() routine calls a routine to fade out the LEDs and then do I call SnoozeBlock to put the Teensy to sleep , or doss SnoozeBlock() have to remain in loop(): and another command is used to enter sleep mode ?
#include <Snooze.h>
SnoozeBlock config;[COLOR=#ff0000]// <--- defined globally here[/COLOR]
void setup() {
config.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type [COLOR=#ff0000]<--- configure the wakeup type to use through out the program now[/COLOR]
}
void loop() {
//IR code......
Snooze.deepSleep(config);// [COLOR=#ff0000]<--- sleep[/COLOR]
}
So this pin is being toggled by the timer? You could use another pin but if you use the "sleep" function then it could start firing its pin interrupt before it powers down, deepSleep and hibernate should be fine though since the they use a different internal interrupt controller of the teensy and should not fire before it goes to sleep but I can't say for sure since this timer is running pretty fast. Is there a way to stop the timer before a call the any of the power down functions (Snooze) in this IR library?I looked at IRLIB, the infrared library I am using and it does use a 50us timer driven interrupt code. Please forgive the following noobish question as I don't have much experience with interrupts.
I've got plenty of pins left on the Teensy LC. Instead of re-configuring the pin used in the Infrared library, could I not connect that same signal from the IR receiver to another pin and have a wakeup interrupt triggered from it so I would not have to reconfigure that other pin ?
void IRrecv::enableIRIn(void) {
IRrecvBase::enableIRIn();
// setup pulse clock timer interrupt
cli();
IR_RECV_CONFIG_TICKS();
IR_RECV_ENABLE_INTR;
IR_RECV_PWM_RESET;
sei();
}
Well if ever have a use for this chip i might see about adding support for this.No, not an ARM chip, I believe it is made by Tensilica or some such. It is a 32-bit chip and has an SDK. But might be more trouble than it's worth?
duff,I'm starting this thread in hopes people will find it and use it for all things related to low power for the Teensy 3.x/LC/++ and peripherals. This will help me and other find info in one place and can we stick this thread into the Quick Reference also?
Someday I might look at this but now my time is limited for any code dev and I want to finish up the update to Snooze for the Teensy first then try to finish my Guitar Tuner.@duff - I've been working with the ESP8266 - mostly the onehorse modules bonded over the small half of the Teensy 3.2 - very cool. I'm doing all my work from Arduino 1.6.7 IDE and it is going well. Apparently it has the means to reset to disable the WiFi and other power modes with docs I haven't looked at yet. The official ESP8266 GitHub site esp8266/Arduino doesn't show ready reference info to setting modes and restarting but it is around if you ever see the need for an onboard WiFi radio and second CPU. Having a good programmatic way to keep this running and select radio and power mode would be a big win since it eats over 200 mA feeding the radio.
void system_restore(void);
void system_restart(void);
bool system_deep_sleep_set_option(uint8 option);
void system_deep_sleep(uint32 time_in_us);
typedef enum {
NONE_SLEEP_T = 0,
LIGHT_SLEEP_T,
MODEM_SLEEP_T
} sleep_type_t;
bool wifi_set_sleep_type(sleep_type_t type);
sleep_type_t wifi_get_sleep_type(void);
sint8 wifi_fpm_do_sleep(uint32 sleep_time_in_us);
void wifi_fpm_set_sleep_type(sleep_type_t type);
sleep_type_t wifi_fpm_get_sleep_type(void);
yes that is correct micros will not reflect the sleep duration. If your using the timer to wake up then you can update the "systick_millis_count" variable by the timer amount.Thanks for your great library. I have started using it with a Teensy LC and was able to reach about 4.4 uA in hibernate for the Teensy LC itself. I'm using it for a LoRa node as mentioned here configured as described here (see how to build a Teensy TTN node). The node is working fine without sleep / hibernate. I tried adding some sleep / hibernate pauses in onEvent routine at the case EV_TXCOMPLETE
In itself this works OK, but jobs are delayed by the amount of time spent in deepsleep / hibernate. As the LMIC library uses the micros() function to determine if a job needs to be scheduled,I guess during a (deep)sleep or hibernate time according to micros() is "stopped" as the CPU goes to sleep? I guess I would need a RTC and adjustments to the hal.cpp to get the correct time?.
In short: do we "loose time" during sleep/hibernate and what would be the best way to solve this aspect of low power sleeps/hibernate in a library as mentioned (I don't expect you to provide a complete solution but would like some guidance how to cope with this issue).
Nice info, 450 mA cc and 18 microAmp Iq is nice, have you pushed that much current through the NCP161 yet?I started with the MIC5528 since it is super small, 500 mA continuous current and only 38 microamp Iq (current draw with zero current load. But even this is too much for the electric Imp (Iq ~ 4 microA) and the STM32L4 (several power modes < 1 microAmp). So I switched to the NCP161, also super small, 450 mA continuous current and only 18 microAmp Iq. Still more than I would like. The STM32L4 has a shutdown mode which draw just 300 nA with the RTC and backup registers active, and 30 nA without. For ultra low Iq, the standard solution is to use a switching Buck converter, which can achieve Iq of ~5 microAmp, but at the cost of much larger board footprint. So the NCP161 is a nice compromise, which takes just a few square mm of board space at 18 microAmp minimum device current. I use the NCP161 on all of my custom Teensys.
I wonder if it has to be disbaled for the bypass to work
So I switched to the NCP161, also super small, 450 mA continuous current and only 18 microAmp Iq.