Emily Wilson / Mbed 2 deprecated ECE4180Lab1

Dependencies:   mbed MCP23S17 PinDetect USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers powermanagement_ec.h Source File

powermanagement_ec.h

00001 #include "mbed.h"
00002 #include "PowerControl/PowerControl.h"
00003 #include "PowerControl/EthernetPowerControl.h"
00004 // Need PowerControl *.h files from this URL
00005 // http://mbed.org/users/no2chem/notebook/mbed-power-controlconsumption/
00006  
00007 // Function to power down magic USB interface chip with new firmware
00008 #define USR_POWERDOWN    (0x104)
00009 int semihost_powerdown() {
00010     uint32_t arg;
00011     return __semihost(USR_POWERDOWN, &arg);
00012 }
00013  
00014 DigitalOut myled(p26);
00015 DigitalIn pb(p22);
00016 
00017 Ticker blinker;
00018 
00019 void blink() {
00020     myled = !pb;
00021 }
00022  
00023 int run_powermanagementEC() {
00024     int result;
00025 // Normal mbed power level for this setup is around 690mW
00026 // assuming 5V used on Vin pin
00027 // If you don't need networking...
00028 // Power down Ethernet interface - saves around 175mW
00029 // Also need to unplug network cable - just a cable sucks power
00030     PHY_PowerDown();
00031  
00032 // If you don't need the PC host USB interface....
00033 // Power down magic USB interface chip - saves around 150mW
00034 // Needs new firmware (URL below) and USB cable not connected
00035 // http://mbed.org/users/simon/notebook/interface-powerdown/
00036 // Supply power to mbed using Vin pin
00037     result = semihost_powerdown();
00038 // Power consumption is now around half
00039  
00040 // Turn off clock enables on unused I/O Peripherals (UARTs, Timers, PWM, SPI, CAN, I2C, A/D...)
00041 // To save just a tiny bit more power - most are already off by default in this short code example
00042 // See PowerControl.h for I/O device bit assignments
00043 // Don't turn off GPIO - it is needed to blink the LEDs
00044     Peripheral_PowerDown(0xFFFF7FFF);
00045  
00046 // use Ticker interrupt and Sleep instead of a wait for time delay - saves up to 70mW
00047 // Sleep halts and waits for an interrupt instead of executing instructions
00048 // power is saved by not constantly fetching and decoding instructions
00049 // Exact power level reduction depends on the amount of time spent in Sleep mode
00050     blinker.attach(&blink, 0.0625);
00051     while (1) {
00052         Sleep();
00053     }
00054 }