4180 lab 1
Dependencies: mbed MCP23S17 PinDetect USBDevice
powermanagement_ec.h@11:2cfdab516b21, 2020-01-21 (annotated)
- Committer:
- emilywilson
- Date:
- Tue Jan 21 21:06:20 2020 +0000
- Revision:
- 11:2cfdab516b21
- Child:
- 12:cc5bda248946
power management extra credit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilywilson | 11:2cfdab516b21 | 1 | #include "mbed.h" |
emilywilson | 11:2cfdab516b21 | 2 | #include "PowerControl/PowerControl.h" |
emilywilson | 11:2cfdab516b21 | 3 | #include "PowerControl/EthernetPowerControl.h" |
emilywilson | 11:2cfdab516b21 | 4 | // Need PowerControl *.h files from this URL |
emilywilson | 11:2cfdab516b21 | 5 | // http://mbed.org/users/no2chem/notebook/mbed-power-controlconsumption/ |
emilywilson | 11:2cfdab516b21 | 6 | |
emilywilson | 11:2cfdab516b21 | 7 | // Function to power down magic USB interface chip with new firmware |
emilywilson | 11:2cfdab516b21 | 8 | #define USR_POWERDOWN (0x104) |
emilywilson | 11:2cfdab516b21 | 9 | int semihost_powerdown() { |
emilywilson | 11:2cfdab516b21 | 10 | uint32_t arg; |
emilywilson | 11:2cfdab516b21 | 11 | return __semihost(USR_POWERDOWN, &arg); |
emilywilson | 11:2cfdab516b21 | 12 | } |
emilywilson | 11:2cfdab516b21 | 13 | |
emilywilson | 11:2cfdab516b21 | 14 | DigitalOut myled(p26); |
emilywilson | 11:2cfdab516b21 | 15 | DigitalIn pb(p22); |
emilywilson | 11:2cfdab516b21 | 16 | |
emilywilson | 11:2cfdab516b21 | 17 | int run_powermanagementEC() { |
emilywilson | 11:2cfdab516b21 | 18 | int result; |
emilywilson | 11:2cfdab516b21 | 19 | // Normal mbed power level for this setup is around 690mW |
emilywilson | 11:2cfdab516b21 | 20 | // assuming 5V used on Vin pin |
emilywilson | 11:2cfdab516b21 | 21 | // If you don't need networking... |
emilywilson | 11:2cfdab516b21 | 22 | // Power down Ethernet interface - saves around 175mW |
emilywilson | 11:2cfdab516b21 | 23 | // Also need to unplug network cable - just a cable sucks power |
emilywilson | 11:2cfdab516b21 | 24 | PHY_PowerDown(); |
emilywilson | 11:2cfdab516b21 | 25 | |
emilywilson | 11:2cfdab516b21 | 26 | // If you don't need the PC host USB interface.... |
emilywilson | 11:2cfdab516b21 | 27 | // Power down magic USB interface chip - saves around 150mW |
emilywilson | 11:2cfdab516b21 | 28 | // Needs new firmware (URL below) and USB cable not connected |
emilywilson | 11:2cfdab516b21 | 29 | // http://mbed.org/users/simon/notebook/interface-powerdown/ |
emilywilson | 11:2cfdab516b21 | 30 | // Supply power to mbed using Vin pin |
emilywilson | 11:2cfdab516b21 | 31 | result = semihost_powerdown(); |
emilywilson | 11:2cfdab516b21 | 32 | // Power consumption is now around half |
emilywilson | 11:2cfdab516b21 | 33 | |
emilywilson | 11:2cfdab516b21 | 34 | // Turn off clock enables on unused I/O Peripherals (UARTs, Timers, PWM, SPI, CAN, I2C, A/D...) |
emilywilson | 11:2cfdab516b21 | 35 | // To save just a tiny bit more power - most are already off by default in this short code example |
emilywilson | 11:2cfdab516b21 | 36 | // See PowerControl.h for I/O device bit assignments |
emilywilson | 11:2cfdab516b21 | 37 | // Don't turn off GPIO - it is needed to blink the LEDs |
emilywilson | 11:2cfdab516b21 | 38 | Peripheral_PowerDown(0xFFFF7FFF); |
emilywilson | 11:2cfdab516b21 | 39 | |
emilywilson | 11:2cfdab516b21 | 40 | // use Ticker interrupt and Sleep instead of a wait for time delay - saves up to 70mW |
emilywilson | 11:2cfdab516b21 | 41 | // Sleep halts and waits for an interrupt instead of executing instructions |
emilywilson | 11:2cfdab516b21 | 42 | // power is saved by not constantly fetching and decoding instructions |
emilywilson | 11:2cfdab516b21 | 43 | // Exact power level reduction depends on the amount of time spent in Sleep mode |
emilywilson | 11:2cfdab516b21 | 44 | // blinker.attach(&blink, 0.0625); |
emilywilson | 11:2cfdab516b21 | 45 | while (1) { |
emilywilson | 11:2cfdab516b21 | 46 | // Sleep(); |
emilywilson | 11:2cfdab516b21 | 47 | myled = !pb; |
emilywilson | 11:2cfdab516b21 | 48 | } |
emilywilson | 11:2cfdab516b21 | 49 | } |