Extra problem 4 for HW 1

Dependencies:   mbed

Committer:
lzzcd001
Date:
Wed Feb 18 14:49:06 2015 +0000
Revision:
0:febabd1da7f4
Extra problem 4 for HW 1

Who changed what in which revision?

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