A blink LED demo with power management to reduce power.

Dependencies:   mbed

Committer:
4180_1
Date:
Fri Jan 28 17:31:00 2011 +0000
Revision:
0:02d7e850d7cb

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:02d7e850d7cb 1 #include "mbed.h"
4180_1 0:02d7e850d7cb 2 #include "PowerControl/PowerControl.h"
4180_1 0:02d7e850d7cb 3 #include "PowerControl/EthernetPowerControl.h"
4180_1 0:02d7e850d7cb 4 // Need PowerControl *.h files from this URL
4180_1 0:02d7e850d7cb 5 // http://mbed.org/users/no2chem/notebook/mbed-power-controlconsumption/
4180_1 0:02d7e850d7cb 6
4180_1 0:02d7e850d7cb 7 // Function to power down magic USB interface chip with new firmware
4180_1 0:02d7e850d7cb 8 #define USR_POWERDOWN (0x104)
4180_1 0:02d7e850d7cb 9 int semihost_powerdown() {
4180_1 0:02d7e850d7cb 10 uint32_t arg;
4180_1 0:02d7e850d7cb 11 return __semihost(USR_POWERDOWN, &arg);
4180_1 0:02d7e850d7cb 12 }
4180_1 0:02d7e850d7cb 13
4180_1 0:02d7e850d7cb 14 DigitalOut myled1(LED1);
4180_1 0:02d7e850d7cb 15 DigitalOut myled2(LED2);
4180_1 0:02d7e850d7cb 16 DigitalOut myled3(LED3);
4180_1 0:02d7e850d7cb 17 DigitalOut myled4(LED4);
4180_1 0:02d7e850d7cb 18
4180_1 0:02d7e850d7cb 19 Ticker blinker;
4180_1 0:02d7e850d7cb 20 int count=1;
4180_1 0:02d7e850d7cb 21
4180_1 0:02d7e850d7cb 22 void blink() {
4180_1 0:02d7e850d7cb 23 count = count << 1;
4180_1 0:02d7e850d7cb 24 if (count > 0x08) count = 0x01;
4180_1 0:02d7e850d7cb 25 myled1 = count & 0x01;
4180_1 0:02d7e850d7cb 26 myled2 = count & 0x02;
4180_1 0:02d7e850d7cb 27 myled3 = count & 0x04;
4180_1 0:02d7e850d7cb 28 myled4 = count & 0x08;
4180_1 0:02d7e850d7cb 29 }
4180_1 0:02d7e850d7cb 30
4180_1 0:02d7e850d7cb 31 int main() {
4180_1 0:02d7e850d7cb 32 int result;
4180_1 0:02d7e850d7cb 33 // Normal mbed power level for this setup is around 690mW
4180_1 0:02d7e850d7cb 34 // assuming 5V used on Vin pin
4180_1 0:02d7e850d7cb 35 // If you don't need networking...
4180_1 0:02d7e850d7cb 36 // Power down Ethernet interface - saves around 175mW
4180_1 0:02d7e850d7cb 37 // Also need to unplug network cable - just a cable sucks power
4180_1 0:02d7e850d7cb 38 PHY_PowerDown();
4180_1 0:02d7e850d7cb 39
4180_1 0:02d7e850d7cb 40 // If you don't need the PC host USB interface....
4180_1 0:02d7e850d7cb 41 // Power down magic USB interface chip - saves around 150mW
4180_1 0:02d7e850d7cb 42 // Needs new firmware (URL below) and USB cable not connected
4180_1 0:02d7e850d7cb 43 // http://mbed.org/users/simon/notebook/interface-powerdown/
4180_1 0:02d7e850d7cb 44 // Supply power to mbed using Vin pin
4180_1 0:02d7e850d7cb 45 result = semihost_powerdown();
4180_1 0:02d7e850d7cb 46 // Power consumption is now around half
4180_1 0:02d7e850d7cb 47
4180_1 0:02d7e850d7cb 48 // Turn off clock enables on unused I/O Peripherals (UARTs, Timers, PWM, SPI, CAN, I2C, A/D...)
4180_1 0:02d7e850d7cb 49 // To save just a tiny bit more power - most are already off by default in this short code example
4180_1 0:02d7e850d7cb 50 // See PowerControl.h for I/O device bit assignments
4180_1 0:02d7e850d7cb 51 // Don't turn off GPIO - it is needed to blink the LEDs
4180_1 0:02d7e850d7cb 52 Peripheral_PowerDown(0xFFFF7FFF);
4180_1 0:02d7e850d7cb 53
4180_1 0:02d7e850d7cb 54 // use Ticker interrupt and Sleep instead of a wait for time delay - saves up to 70mW
4180_1 0:02d7e850d7cb 55 // Sleep halts and waits for an interrupt instead of executing instructions
4180_1 0:02d7e850d7cb 56 // power is saved by not constantly fetching and decoding instructions
4180_1 0:02d7e850d7cb 57 // Exact power level reduction depends on the amount of time spent in Sleep mode
4180_1 0:02d7e850d7cb 58 blinker.attach(&blink, 0.0625);
4180_1 0:02d7e850d7cb 59 while (1) {
4180_1 0:02d7e850d7cb 60 Sleep();
4180_1 0:02d7e850d7cb 61 }
4180_1 0:02d7e850d7cb 62 }