Initial Measurements: With my baseline Teensy Hearing Aid, I measuring the current being drawn from the battery during normal operation. At this early stage of development, the Teensy isn't doing very much -- it is simply applying digital gain to the audio stream. Because it is doing so little, I am hoping that we'll see the lowest power consumption. My results are below. Note that I measured the power consumption across a range of processor speeds. You can set the speed of the processor via the Arduino IDE when you compile the sketch.
Sleep During Idle: Luckily, I have a friend who is experienced with low power embedded systems. He suggested that I could save a lot of power by putting the processor to sleep during idle periods. Knowing that I'm working with an ARM processor (the heart of the Teensy board), he suggested that I insert the ARM-specific command asm(" WFI") into my main loop (yes, you do need the space before the W). When the processor hits this command, it'll go to sleep and consume less power. It'll stay asleep and "Wait For Interrupt" (hence "WFI") before waking to resume its work.
Wait for Interrupt: Since I don't want it to sleep forever, I need to make sure that there is an interrupt (such as a timer) that'll wake the system periodically so that it can do its work. As I don't know how to do this, I have a problem. Luckily, I know that the Teensy Audio Library already uses interrupts to do its work. I know that it fires at least one interrupt every 128 audio samples. As any interrupt will trigger the WFI to wake up, I don't need to do anything more. I can just add the WFI command and rely upon the Audio Library to wake the system. The system will automatically go back and forth between sleep and wake. One line of code -- what a simple solution.
It Works! After adding the WFI command (my code is here), I measured the current draw again. The WFI command works! At the default speed of 180 MHz, the system now draws only 57 mA, instead of 91 mA as seen before. That's a 34 mA savings with no impact on system performance. Fantastic.
Battery Life: By adding the WFI command, power consumption has dropped to 2/3 of its original value. My system will now have 50% more battery life. Using my 350 mA-hr battery, I'll now get 6 hours of life instead of 4 hours. That's a great improvement for adding just a single line of code.
More Power Savings? While increasing my battery life by 50% is great, I went back to my friend asking if more savings could be had so easily. He said that I could save more power, but not nearly as easily. He said that the next step would be to identify and disable peripherals that I don't need. But, to do this, I'd have to read through and understand my processor's datasheet, which is not an easy task for a newbie such as myself. So, for now, I think that I'll be content with the easy savings provided by the WFI command.
For Fellow Nerds...My Raw Data: For anyone who is really interested, my raw data is in the table below (or here). It is interesting that, even at very slow processor speeds, I still see power savings when using the WFI command. Clearly, my "Gain Only" audio processing algorithm requires very little effort from the processor. That Teensy 3.6 sure is fast!
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteVery interesting. I'm in Auckland, trying to use Teensy (3.1 for now) and the Teensy Audio board and library to develop a passive sonar capable of detecting fishing boats that are actually fishing. I have taken notes from several of your blog pages already, please keep them up!
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete