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 Ticker changer; 00015 int count=1; 00016 00017 DigitalIn sw(p5); 00018 PwmOut led(p25); 00019 00020 void change(){ 00021 count = count << 1; 00022 if (count > 0x08) count = 0x01; 00023 if (1) { 00024 for (float p = 0.0f; p < 1.0f; p += 0.1f) { 00025 led = p; 00026 wait(0.1); 00027 } 00028 } 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 00039 //PHY_PowerDown(); 00040 00041 // If you don't need the PC host USB interface.... 00042 // Power down magic USB interface chip - saves around 150mW 00043 // Needs new firmware (URL below) and USB cable not connected 00044 // http://mbed.org/users/simon/notebook/interface-powerdown/ 00045 // Supply power to mbed using Vin pin 00046 //result = semihost_powerdown(); 00047 // Power consumption is now around half 00048 00049 // Turn off clock enables on unused I/O Peripherals (UARTs, Timers, PWM, SPI, CAN, I2C, A/D...) 00050 // To save just a tiny bit more power - most are already off by default in this short code example 00051 // See PowerControl.h for I/O device bit assignments 00052 // Don't turn off GPIO - it is needed to blink the LEDs 00053 //Peripheral_PowerDown(0xFFFF7FFF); 00054 00055 // use Ticker interrupt and Sleep instead of a wait for time delay - saves up to 70mW 00056 // Sleep halts and waits for an interrupt instead of executing instructions 00057 // power is saved by not constantly fetching and decoding instructions 00058 // Exact power level reduction depends on the amount of time spent in Sleep mode 00059 changer.attach(&change, 0.0625); 00060 while (1) { 00061 Sleep(); 00062 } 00063 }
Generated on Thu Jul 14 2022 23:48:57 by
1.7.2