Teensy 3.0 LowPower examples don't work!

immortalSpirit

Active member
On Teensy 3.0 menu, File->Examples->LowPower contains two example programs.

When I try to use either I get: "fatal error: avr/sleep.h: No such file or directory".

Both #include "LowPower.h". I find lowPower.cpp and it says "see www.rocketscream.com/wiki for more information...". That wiki has no information at all!

1) HELP! :)

Perhaps the following belongs in a different post, but what the heck:

2) Looks like I'm gonna have to cut a trace to stick my meter in there and measure current draw. Really? Is there a simpler way? Cut the power wire on a USB cable instead maybe?

3) Anybody made any measurements yet? What is normal current draw?

4) And most important question: how will it compare to Arduino Nano (328)? Esp, how will lowest power mode with timer wakeup in a second or two compare? I need to sleep for long periods of time, wake for a moment every few seconds, and go back to sleep. Will Teensy 3.0 fare better than Nano 328?


Thanks!
 
Last edited:
I did a simple test of power consumption. The numbers are here: http://forum.pjrc.com/threads/100-Current-consumption
[edit]I hooked up the DC supply to the Vin pin on the T3 (USB not connected) and a multimeter in series with the supply.

The Low Power library hasn't been converted from the original AVR code to the T3/ARM yet. It's probably on Paul's TODO list.

Pete
 
Last edited:
I used Adafruit's "high side" I2C current monitor in series with the input supply and it reads ~27 ma. @ 96 Mhz ---> so you are very close to my measuremnt.
 
Low Power Mode

The Low Power library hasn't been converted from the original AVR code to the T3/ARM yet. It's probably on Paul's TODO list.

Paul, is this on your TODO list? Is there an ETA? Low power mode is critical for my project. I'd be willing to help in converting it.
 
BTW ... I like to add that any 32 bit ARM, including the Teensy 3, "claim to fame" is low power or battery operation. That is why Apple chose ARM processors for all their iDevices.

The Teensy 3 runs about 27 ma., at idle, and depletes batteries rather quickly.
Note: That is with nothing connected to the T3 microcontroller!!!!

The port or redesign of the "Low Power Library" for the Teensy 3 should be a HIGH PRIORITY!
 
Last edited:
I am planning to address the low power stuff.

In terms of priorities, right now I'm focusing on getting the Arduino libraries all ported and documented. Yesterday I did both of the stepper libraries. Both worked, but neither had been tested or documented.... now both are and you'll see those 2 pages now have photos with Teensy 3.0. The breadboard from the Stepper page was taken apart long ago, so I built up a permanent test board like I've done for most of the other libraries.

http://www.pjrc.com/teensy/td_libs_Stepper.html
http://www.pjrc.com/teensy/td_libs_AccelStepper.html

I also started looking at SoftwareSerial yesterday. It still needs work, but I at least made a dummy version that uses hardware serial, so people wanting to use libraries that have hard-coded dependency on SoftwareSerial can compile and (hopefully) work. I actually got some code working to transmit, except it has too much jitter with interrupts enabled. I'd hoped to make an interrupt-friendly SoftwareSerial, but that's far too much work. I might shelve any more effort on SoftwareSerial... but I think with one more good coding session I'll probably get it working at least as well as it does on AVR. At first I had not planned to work on SoftwareSerial at all, since Teensy 3.0 has 3 real serial ports. But it turns out there are lots of minor Arduino libraries and programs that have hard-coded dependency, so this really is important for good compatibility with the universe of Arduino code.

Also pretty high on my priority list is rewriting the "getting started" section of the website. Sure, there's links that point to stuff for Teensy 3.0, but some people miss those. I'm planning to work on those next week, after doing a few more of the libraries.

I also have a long list of minor things to fix or improve. They're all easy, each probably needing less than an hour to do. Before really looking into low power, I'm going to make a Teensyduino 1.14 release with as many of those as I can cram into about 1 week. I'm also planning to include IntervalTimer in the core library with 1.14. A few of the remaining Arduino libraries will be "ported" using IntervalTimer, rather than embedding native interrupt code.

So in terms of priorities, I'm considering all that stuff more urgent. I know low power matters too and I do plan to work on it.

My current thought on low power is to put the support directly into the core library, and discard the LowPower library (which has a horribly AVR-centric API). I'm still not sure exactly what API it should have. I'm open to suggestions, but I'd prefer to keep it simple. Any ideas?
 
My current thought on low power is to put the support directly into the core library

Just another thought. Could a RTOS be used to reduce the power on the K20?
I don't know of any RTOS that is "K20 specific" that would reduce power when a thread is waiting?
 
I'm open to suggestions, but I'd prefer to keep it simple. Any ideas?

In keeping power savings "very" simple, force the T3 into the "lowest power mode" and have it wake-up only on an external digital interrupt. (SLEEP_MODE_PWR_DOWN – most power savings)
 
Last edited:
There will probably end up being 2 functions, idle and sleep, where one just stops the CPU but everything keeps running normally, and the other shuts off nearly everything including the crystal. Both will wake on any interrupt, but of course with the clock shut off in sleep mode, only certain types of interrupts are possible.

These chips have many very complex low power features. I'm still holding out for some elegant ideas to leverage some of those capabilities in ways that don't expose much of the complexity.......
 
I looked at low power modes but didn't get very far. I put a waitfor interrupt instruction (WFI) in the loop() function. I had assumed that it would put the processor to sleep forever because I hadn't arranged for anything to interrupt. The code below should go to sleep forever with the LED off, but the LED keeps toggling indicating that the processor is being interrupted.
Code:
// Put the processor to sleep forever

// Pin for LED
#define LEDPIN 13

// state of led pin
volatile int ledVal;
void setup()
{
  pinMode(LEDPIN, OUTPUT);
  ledVal = 0;
  digitalWrite(LEDPIN, ledVal);  // Start with the LED off

}

void loop()
{
  // There should be no interrupts so this should sleep forever
  // but the LED pin tells a different story
  asm volatile("wfi\n"::);
  digitalWrite(LEDPIN, ledVal ^= 1);
}

If I run the equivalent code on a Nano or Teensy++2 the LED stays off.
Anyone know what is interrupting and how to shut it down? It isn't the USB because a Serial.end() in setup() makes no difference.

Pete
 
Just another thought. Could a RTOS be used to reduce the power on the K20?
I don't know of any RTOS that is "K20 specific" that would reduce power when a thread is waiting?

MQX would be one candidate. I've not used it, but it should certainly support K20 low power modes, as it's specifically designed for Kinetis CPUs. There's also MQX-Lite if you're looking for a freebie solution.

- Peter
 
If I run the equivalent code on a Nano or Teensy++2 the LED stays off.

Really? What would that equivalent code be?

I would expect Teesn++ 2.0 to do the same thing...

Anyone know what is interrupting and how to shut it down?

Almost certainly the 1ms system tick which updates the millis() count.

On ARM, that's the systick counter built into the ARM code. On ARM, timer0 is used. If you put the AVR into idle mode, it should wake up on the next timer0 interrupt, the same way the ARM chip does.

Are you actually measuring the current with an ampmeter? For working on any power saving stuff, you really do need to measure the actual power supply current. Many things do have an effect on the current, even if it's not obvious from a LED blink. Without seeing an actual number on a multimeter, it really is working blind.
 
Just another thought. Could a RTOS be used to reduce the power on the K20?
I don't know of any RTOS that is "K20 specific" that would reduce power when
a thread is waiting?

MQX would be one candidate

Thanks, but if MQX doesn't have "hooks" that will allow the Teensy 3 Arduino code to run seamlessly with it then using this RTOS would be like "shooting ourselves in the foot"

It would be awesome if the Teensy 3 had a K20 specific, extremely easy to use with "yield" RTOS. Oh well, we must be dreaming ...
now back to reality. Any solution is welcome to reduce the power consumption on the K20.
 
Last edited:
What would that equivalent code be?
Aha. The "equivalent" code on Nano or T++2 shuts down a lot of stuff before going to sleep so not equivalent at all.

Does the T++2 use timer 1 for the 1ms tick?

Pete
 
Teensy 2.0 and Teensy++ 2.0 use timer0 for the millis() ticks. It's actually a 1.024 ms interrupt rate, with code that occasionally increments by 2 to make up for it.

On Teensy 3.0, it's the ARM core's systick interrupt, configured to exactly 1ms. However, I might someday change Teensy 3.0 to a much slower interrupt rate (less overhead and resilience to code that disables interrupts for more than 1.99ms) and rewrite millis() to read the timer value.
 
I haven't fully explored the ramifications of the lower power modes on the Teensy 3.0 yet, but simply flipping bit 2 of the SCR to 1 prior to issuing the WFI will place the CPU into deep sleep. This is part of the ARMv7 standard.
 
I want to re-visit this thread one year later. I still don't see any low power library... Is there any news?

I just want to shut everything off except a single interrupt on any edge of one input signal, and/or a timeout. If some system clock or other internal condition wakes me prematurely I don't care (much). If I loose the accuracy of millis() I don't care (much). I just wanna sleep awhile between input pin edges! And I need uA's, not mA's.

Has *anybody* got any code that I could use? I don't want to get into the hardware level coding myself, I just want a simple-to-use function. Ideally,

sleepForeverAndWakeOnInterrupt(pinNumber,handler);
...
void handler() { v = digitalRead(pinNimber); etc ; return; }

With possibly also a timeOut argument to wakeup after that many usec or msec.

Thanks in advance.
 
Yes I did! Some suggestions there, but no answers! I'm not looking to develop code myself, I'm looking for developed code! (Code that is very simple to use). If none is found, I may have to break down and do the project myself, but that is currently my last resort! Surely someone has written some nice simple "sleepForeverAndWakeOnInterrupt" code? Or not. But that's what I'm askin'!
 
Yes I did! Some suggestions there, but no answers! I'm not looking to develop code myself, I'm looking for developed code! (Code that is very simple to use). If none is found, I may have to break down and do the project myself, but that is currently my last resort! Surely someone has written some nice simple "sleepForeverAndWakeOnInterrupt" code? Or not. But that's what I'm askin'!



Did you actually read that post its all there, any how here you go: https://github.com/duff2013/LowPower_Teensy3
 
Thank you! That looks very much like what I want!

Sorry, my bad, I only reviewed first couple of pages and missed that. Thanks again.
 
Back
Top