Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
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 myled1(LED1); 00015 DigitalOut myled2(LED2); 00016 DigitalOut myled3(LED3); 00017 DigitalOut myled4(LED4); 00018 00019 Ticker blinker; 00020 int count=1; 00021 00022 void blink() { 00023 count = count << 1; 00024 if (count > 0x08) count = 0x01; 00025 myled1 = count & 0x01; 00026 myled2 = count & 0x02; 00027 myled3 = count & 0x04; 00028 myled4 = count & 0x08; 00029 } 00030 00031 int main() { 00032 int result; 00033 // Normal mbed power level for this setup is around 690mW 00034 // assuming 5V used on Vin pin 00035 // If you don't need networking... 00036 // Power down Ethernet interface - saves around 175mW 00037 // Also need to unplug network cable - just a cable sucks power 00038 PHY_PowerDown(); 00039 00040 // If you don't need the PC host USB interface.... 00041 // Power down magic USB interface chip - saves around 150mW 00042 // Needs new firmware (URL below) and USB cable not connected 00043 // http://mbed.org/users/simon/notebook/interface-powerdown/ 00044 // Supply power to mbed using Vin pin 00045 result = semihost_powerdown(); 00046 // Power consumption is now around half 00047 00048 // Turn off clock enables on unused I/O Peripherals (UARTs, Timers, PWM, SPI, CAN, I2C, A/D...) 00049 // To save just a tiny bit more power - most are already off by default in this short code example 00050 // See PowerControl.h for I/O device bit assignments 00051 // Don't turn off GPIO - it is needed to blink the LEDs 00052 Peripheral_PowerDown(0xFFFF7FFF); 00053 00054 // use Ticker interrupt and Sleep instead of a wait for time delay - saves up to 70mW 00055 // Sleep halts and waits for an interrupt instead of executing instructions 00056 // power is saved by not constantly fetching and decoding instructions 00057 // Exact power level reduction depends on the amount of time spent in Sleep mode 00058 blinker.attach(&blink, 0.0625); 00059 while (1) { 00060 Sleep(); 00061 } 00062 }
Generated on Thu Jul 14 2022 19:51:48 by
1.7.2