a test code to implement and test LP1768 power control mode

Dependencies:   mbed

This code implemented some LP1768 power mode : Sleep(), DeepSleep(), PowerDown(), DeepPowerDown(), BOGD_PowerDown(). It also has a test code to test these power modes and wakeup using watch dog. The wakeup part is based on Erik's code but add implementation for LP1768. As LP1768 has debug enabled in default, it cannot be waked up in DeepSleep mode. Therefore this code use WDC reset to wake up the chips from deep sleep. The test code also allow test the power under two clock frequency (96 MHz and 48MHz). Inspired by Paul and Michael Wang, I also tested the power reduction by power off PHY. The analysis could be found in http://mbed.org/users/steniu01/notebook/lp1768-power-mode-implementation-and-measurement-/#

Committer:
steniu01
Date:
Sat Aug 02 16:01:23 2014 +0000
Revision:
2:15d9501bf5b3
Parent:
1:571258908570
a test code to test LP1768 power mode.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
steniu01 0:5c4169623549 1 #include "mbed.h"
steniu01 0:5c4169623549 2 #include "PowerControl.h"
steniu01 0:5c4169623549 3 #include "EthernetPowerControl.h"
steniu01 0:5c4169623549 4 #include "WakeUp.h"
steniu01 2:15d9501bf5b3 5 #include "powercontrol.h"
steniu01 2:15d9501bf5b3 6 #include "ClockControl/ClockControl.h"
steniu01 1:571258908570 7
steniu01 1:571258908570 8
steniu01 0:5c4169623549 9 DigitalOut myled1(LED1);
steniu01 0:5c4169623549 10 DigitalOut myled2(LED2) ;
steniu01 0:5c4169623549 11 DigitalOut myled3(LED3) ;
steniu01 0:5c4169623549 12
steniu01 2:15d9501bf5b3 13 Timer t;
steniu01 0:5c4169623549 14
steniu01 1:571258908570 15
steniu01 1:571258908570 16
steniu01 0:5c4169623549 17 int main()
steniu01 0:5c4169623549 18 {
steniu01 1:571258908570 19 //profiling_PHY_PowerDown();
steniu01 1:571258908570 20 //PHY_PowerUp();// power up PHY because it was powerred up as default. We might power it down when test "Turn off PHY".
steniu01 2:15d9501bf5b3 21
steniu01 0:5c4169623549 22 myled1=1;
steniu01 0:5c4169623549 23 wait(0.5);
steniu01 0:5c4169623549 24 myled1=0;
steniu01 0:5c4169623549 25 char char_get=0;
steniu01 0:5c4169623549 26 int num_get=0;
steniu01 1:571258908570 27 char* powermode[7]={ "[1] no low power", "[2] sleep mode", "[3] deep sleep mode", "[4] power down mode", "[5] Brown-out Reduced Power mode", "[6] Deep Power Down", "[7] Turn off PHY"};
steniu01 2:15d9501bf5b3 28
steniu01 2:15d9501bf5b3 29
steniu01 2:15d9501bf5b3 30 printf("Which frequency you want to run \r\n");
steniu01 2:15d9501bf5b3 31 printf("[1] 96MHz \r\n");
steniu01 2:15d9501bf5b3 32 printf("[2] 48MHz \r\n");
steniu01 2:15d9501bf5b3 33 char_get=getchar();
steniu01 2:15d9501bf5b3 34 num_get=char_get-48;
steniu01 2:15d9501bf5b3 35
steniu01 2:15d9501bf5b3 36
steniu01 2:15d9501bf5b3 37 switch (num_get){
steniu01 2:15d9501bf5b3 38 case 1: setSystemFrequency(0x3, 0x1, 12, 1);break;
steniu01 2:15d9501bf5b3 39 case 2: setSystemFrequency(0x3, 0x1, 12, 2);break;
steniu01 2:15d9501bf5b3 40 default: setSystemFrequency(0x3, 0x1, 12, 1);break;
steniu01 2:15d9501bf5b3 41 }
steniu01 2:15d9501bf5b3 42 Serial pc (USBTX, USBRX);
steniu01 2:15d9501bf5b3 43 pc.printf ("num_get is %d \r\n", num_get);
steniu01 2:15d9501bf5b3 44 wait (3);
steniu01 2:15d9501bf5b3 45 num_get=0;
steniu01 2:15d9501bf5b3 46 char_get=0;
steniu01 2:15d9501bf5b3 47
steniu01 0:5c4169623549 48 while (num_get>7 || num_get<1){
steniu01 2:15d9501bf5b3 49 pc.printf("Which power mode you want to choose: \r\n");
steniu01 0:5c4169623549 50 for (int a=0;a<7;a++)
steniu01 0:5c4169623549 51 pc.printf("%s \r\n", powermode[a]);
steniu01 0:5c4169623549 52 char_get=pc.getc(); // get char from serial
steniu01 0:5c4169623549 53 num_get=char_get-48;// convert char to int, minus 48 since ascii num start from 48
steniu01 0:5c4169623549 54 if (num_get>7 || num_get<1)
steniu01 0:5c4169623549 55 pc.printf("You have choosen an invalid num, please choose a correct one\r\n");
steniu01 0:5c4169623549 56 }
steniu01 0:5c4169623549 57 pc.printf ("I am going to test %s\r\n",powermode[num_get-1]);
steniu01 0:5c4169623549 58 myled2=1;
steniu01 0:5c4169623549 59 wait(0.5);
steniu01 0:5c4169623549 60 myled2=0;
steniu01 2:15d9501bf5b3 61 WakeUp::set(10);
steniu01 2:15d9501bf5b3 62 //WakeUp::set(70);
steniu01 0:5c4169623549 63 switch (num_get){
steniu01 0:5c4169623549 64 case 1: break;
steniu01 0:5c4169623549 65 case 2: steven_Sleep();break;
steniu01 0:5c4169623549 66 case 3: steven_DeepSleep(); break;
steniu01 0:5c4169623549 67 case 4: steven_PowerDown();break;
steniu01 0:5c4169623549 68 case 5: steven_BOGD_PowerDown();break;
steniu01 1:571258908570 69 case 6: steven_DeepPowerDown(); break;
steniu01 2:15d9501bf5b3 70 case 7: PHY_PowerDown(); break;
steniu01 0:5c4169623549 71 default: pc.printf("Not valid input\n"); break;
steniu01 0:5c4169623549 72 }
steniu01 0:5c4169623549 73 while (1);
steniu01 0:5c4169623549 74 }