CodeShare

Dependencies:   mbed

Fork of PowerControl by Michael Wei

Revision:
1:5de2b210531a
Parent:
0:9bd5f1bdb845
--- a/main.cpp	Sat Jan 30 02:23:30 2010 +0000
+++ b/main.cpp	Sun Sep 25 20:19:34 2016 +0000
@@ -1,15 +1,89 @@
 #include "mbed.h"
 #include "PowerControl/PowerControl.h"
 #include "PowerControl/EthernetPowerControl.h"
+// Need PowerControl *.h files from this URL
+// http://mbed.org/users/no2chem/notebook/mbed-power-controlconsumption/
 
-int main() {
-    //turn OSC1 down
-     PHY_PowerDown();
-     wait(5);
-     LPC_GPIO1->FIODIR = 0x8000000;
-     LPC_GPIO1->FIOCLR = 0x8000000;
-     wait(5);
-     LPC_GPIO1->FIOSET = 0x8000000;
-     wait(5);
-     PHY_PowerUp();
+// Function to power down magic USB interface chip with new firmware
+#define USR_POWERDOWN    (0x104)
+int semihost_powerdown()
+{
+    uint32_t arg;
+    return __semihost(USR_POWERDOWN, &arg);
+}
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+
+PwmOut LED(p21); // normal LED
+DigitalIn Button1(p29); // Pushbutton1 input
+DigitalIn Button2(p25); // Pushbutton2 input
+
+
+
+Ticker blinker;
+int count=1;
+
+// setup for PWN LED output
+float dc = 0.4; // 40% duty cycle
+
+
+
+void blink()
+{
+    count = count << 1;
+    if (count > 0x08) count = 0x01;
+    myled1 = count & 0x01;
+    myled2 = count & 0x02;
+    myled3 = count & 0x04;
+    myled4 = count & 0x08;
+}
+
+int main()
+{
+    LED.period(0.01f);      // 4 second period
+    LED.write(1);
+
+    int result;
+    
+// Normal mbed power level for this setup is around 690mW
+// assuming 5V used on Vin pin
+// If you don't need networking...
+// Power down Ethernet interface - saves around 175mW
+// Also need to unplug network cable - just a cable sucks power
+    
+    
+    
+    PHY_PowerDown();
+
+
+// If you don't need the PC host USB interface....
+// Power down magic USB interface chip - saves around 150mW
+// Needs new firmware (URL below) and USB cable not connected
+// http://mbed.org/users/simon/notebook/interface-powerdown/
+// Supply power to mbed using Vin pin
+    
+    
+    result = semihost_powerdown();
+
+// Power consumption is now around half
+
+// Turn off clock enables on unused I/O Peripherals (UARTs, Timers, PWM, SPI, CAN, I2C, A/D...)
+// To save just a tiny bit more power - most are already off by default in this short code example
+// See PowerControl.h for I/O device bit assignments
+// Don't turn off GPIO - it is needed to blink the LEDs
+
+
+    Peripheral_PowerDown(0xFFFF7FFF);
+
+// use Ticker interrupt and Sleep instead of a wait for time delay - saves up to 70mW
+// Sleep halts and waits for an interrupt instead of executing instructions
+// power is saved by not constantly fetching and decoding instructions
+// Exact power level reduction depends on the amount of time spent in Sleep mode
+    blinker.attach(&blink, 0.0625);
+    while (1) {
+        Sleep();
+    }
 }
\ No newline at end of file