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:
Mon Jul 21 13:46:49 2014 +0000
Revision:
0:5c4169623549
Child:
1:571258908570
the first workrable version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
steniu01 0:5c4169623549 1 #include "mbed.h"
steniu01 0:5c4169623549 2 #include "CPU_Usage.h"
steniu01 0:5c4169623549 3 #include "RTC.h"
steniu01 0:5c4169623549 4 #include "PowerControl.h"
steniu01 0:5c4169623549 5 #include "EthernetPowerControl.h"
steniu01 0:5c4169623549 6 #include "WakeUp.h"
steniu01 0:5c4169623549 7 #include "steven_powercontrol.h"
steniu01 0:5c4169623549 8 DigitalOut myled1(LED1);
steniu01 0:5c4169623549 9 DigitalOut myled2(LED2) ;
steniu01 0:5c4169623549 10 DigitalOut myled3(LED3) ;
steniu01 0:5c4169623549 11 Serial pc (USBTX, USBRX);
steniu01 0:5c4169623549 12 Timer t;
steniu01 0:5c4169623549 13 CPU_Usage cpu(t, 1);
steniu01 0:5c4169623549 14
steniu01 0:5c4169623549 15 class Watchdog {
steniu01 0:5c4169623549 16 public:
steniu01 0:5c4169623549 17 // Load timeout value in watchdog timer and enable
steniu01 0:5c4169623549 18 void kick(float s) {
steniu01 0:5c4169623549 19 LPC_WDT->WDCLKSEL = 0x02; // Set CLK src to RTC for DeepSleep wakeup
steniu01 0:5c4169623549 20 LPC_WDT->WDTC = (s/4.0)*32768;
steniu01 0:5c4169623549 21 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
steniu01 0:5c4169623549 22 kick();
steniu01 0:5c4169623549 23 }
steniu01 0:5c4169623549 24 // "kick" or "feed" the dog - reset the watchdog timer
steniu01 0:5c4169623549 25 // by writing this required bit pattern
steniu01 0:5c4169623549 26 void kick() {
steniu01 0:5c4169623549 27 LPC_WDT->WDFEED = 0xAA;
steniu01 0:5c4169623549 28 LPC_WDT->WDFEED = 0x55;
steniu01 0:5c4169623549 29 }
steniu01 0:5c4169623549 30 };
steniu01 0:5c4169623549 31
steniu01 0:5c4169623549 32
steniu01 0:5c4169623549 33 Watchdog wdt;
steniu01 0:5c4169623549 34
steniu01 0:5c4169623549 35 //test PLL***
steniu01 0:5c4169623549 36
steniu01 0:5c4169623549 37 // Define the register names that haven't been defined
steniu01 0:5c4169623549 38 #define CLKSRCSEL LPC_SC->CLKSRCSEL
steniu01 0:5c4169623549 39 #define PLL0CFG LPC_SC->PLL0CFG
steniu01 0:5c4169623549 40 #define PLL0CON LPC_SC->PLL0CON
steniu01 0:5c4169623549 41 #define CCLKCFG LPC_SC->CCLKCFG
steniu01 0:5c4169623549 42 #define PLL0FEED LPC_SC->PLL0FEED
steniu01 0:5c4169623549 43 #define PLL0STAT LPC_SC->PLL0STAT
steniu01 0:5c4169623549 44
steniu01 0:5c4169623549 45 // Other defines
steniu01 0:5c4169623549 46 #define SYSCLK 96000000
steniu01 0:5c4169623549 47 #define EXTCLK 12000000
steniu01 0:5c4169623549 48 #define PLLCLK 288000000
steniu01 0:5c4169623549 49 #define PLLMULT (PLLCLK/2/EXTCLK)-1
steniu01 0:5c4169623549 50 //end test PLL***
steniu01 0:5c4169623549 51
steniu01 0:5c4169623549 52
steniu01 0:5c4169623549 53 void steven_get_string(){
steniu01 0:5c4169623549 54 char input[50];
steniu01 0:5c4169623549 55 int num=0;
steniu01 0:5c4169623549 56 while (1){
steniu01 0:5c4169623549 57 char ret=pc.getc();
steniu01 0:5c4169623549 58 pc.putc(ret);
steniu01 0:5c4169623549 59 if (num >=50){
steniu01 0:5c4169623549 60 pc.printf("Overflow \n");
steniu01 0:5c4169623549 61 exit ;
steniu01 0:5c4169623549 62 }
steniu01 0:5c4169623549 63 if (ret!=(char)NULL)
steniu01 0:5c4169623549 64 input[num++]=ret;
steniu01 0:5c4169623549 65 if(ret==(char)13)
steniu01 0:5c4169623549 66 break;
steniu01 0:5c4169623549 67 }
steniu01 0:5c4169623549 68 pc.printf ("\n");
steniu01 0:5c4169623549 69 pc.printf ("you have input %s \n",input);
steniu01 0:5c4169623549 70 }
steniu01 0:5c4169623549 71
steniu01 0:5c4169623549 72
steniu01 0:5c4169623549 73
steniu01 0:5c4169623549 74 void ledFunction( void )
steniu01 0:5c4169623549 75 {
steniu01 0:5c4169623549 76 myled1 = !myled1;
steniu01 0:5c4169623549 77 RTC::detach(RTC::Second);
steniu01 0:5c4169623549 78 }
steniu01 0:5c4169623549 79
steniu01 0:5c4169623549 80 void displayFunction( void )
steniu01 0:5c4169623549 81 {
steniu01 0:5c4169623549 82 time_t seconds = time(NULL);
steniu01 0:5c4169623549 83 printf("%s", ctime(&seconds));
steniu01 0:5c4169623549 84 }
steniu01 0:5c4169623549 85
steniu01 0:5c4169623549 86 void alarmFunction( void )
steniu01 0:5c4169623549 87 {
steniu01 0:5c4169623549 88
steniu01 0:5c4169623549 89 wait(2);
steniu01 0:5c4169623549 90 myled3=1; // add debug information
steniu01 0:5c4169623549 91 printf("Not most useful alarm function");
steniu01 0:5c4169623549 92 set_time(0000000000);
steniu01 0:5c4169623549 93 RTC::alarmOff();
steniu01 0:5c4169623549 94 }
steniu01 0:5c4169623549 95
steniu01 0:5c4169623549 96 int main()
steniu01 0:5c4169623549 97 {
steniu01 0:5c4169623549 98 PHY_PowerUp();// power up PHY because it was powerred up as default. We might power it down when test "Turn off PHY".
steniu01 0:5c4169623549 99 myled1=1;
steniu01 0:5c4169623549 100 wait(0.5);
steniu01 0:5c4169623549 101 myled1=0;
steniu01 0:5c4169623549 102 char char_get=0;
steniu01 0:5c4169623549 103 int num_get=0;
steniu01 0:5c4169623549 104 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] Turn off PHY", "[7] Deep Power Down"};
steniu01 0:5c4169623549 105 while (num_get>7 || num_get<1){
steniu01 0:5c4169623549 106 printf("Which power mode you want to choose: \r\n");
steniu01 0:5c4169623549 107 for (int a=0;a<7;a++)
steniu01 0:5c4169623549 108 pc.printf("%s \r\n", powermode[a]);
steniu01 0:5c4169623549 109 char_get=pc.getc(); // get char from serial
steniu01 0:5c4169623549 110 num_get=char_get-48;// convert char to int, minus 48 since ascii num start from 48
steniu01 0:5c4169623549 111 if (num_get>7 || num_get<1)
steniu01 0:5c4169623549 112 pc.printf("You have choosen an invalid num, please choose a correct one\r\n");
steniu01 0:5c4169623549 113 }
steniu01 0:5c4169623549 114 pc.printf ("I am going to test %s\r\n",powermode[num_get-1]);
steniu01 0:5c4169623549 115 myled2=1;
steniu01 0:5c4169623549 116 wait(0.5);
steniu01 0:5c4169623549 117 myled2=0;
steniu01 0:5c4169623549 118 WakeUp::set(10);
steniu01 0:5c4169623549 119 switch (num_get){
steniu01 0:5c4169623549 120 case 1: break;
steniu01 0:5c4169623549 121 case 2: steven_Sleep();break;
steniu01 0:5c4169623549 122 case 3: steven_DeepSleep(); break;
steniu01 0:5c4169623549 123 case 4: steven_PowerDown();break;
steniu01 0:5c4169623549 124 case 5: steven_BOGD_PowerDown();break;
steniu01 0:5c4169623549 125 case 6: PHY_PowerDown(); break;
steniu01 0:5c4169623549 126 case 7: steven_PowerDown(); break;
steniu01 0:5c4169623549 127 default: pc.printf("Not valid input\n"); break;
steniu01 0:5c4169623549 128 }
steniu01 0:5c4169623549 129 while (1);
steniu01 0:5c4169623549 130 }