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-/#

Files at this revision

API Documentation at this revision

Comitter:
steniu01
Date:
Sat Aug 02 16:01:23 2014 +0000
Parent:
1:571258908570
Commit message:
a test code to test LP1768 power mode.

Changed in this revision

ClockControl/ClockControl.cpp Show annotated file Show diff for this revision Revisions of this file
ClockControl/ClockControl.h Show annotated file Show diff for this revision Revisions of this file
Pulses.lib Show diff for this revision Revisions of this file
RTC.lib Show diff for this revision Revisions of this file
WakeUp.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
steven_powercontrol.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 571258908570 -r 15d9501bf5b3 ClockControl/ClockControl.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ClockControl/ClockControl.cpp	Sat Aug 02 16:01:23 2014 +0000
@@ -0,0 +1,37 @@
+#include "ClockControl.h"
+
+void setPLL0Frequency(unsigned char clkSrc, unsigned short M, unsigned char N)
+{
+      LPC_SC->CLKSRCSEL = clkSrc;
+      LPC_SC->PLL0CFG   = (((unsigned int)N-1) << 16) | M-1;
+      LPC_SC->PLL0CON   = 0x01;             
+      LPC_SC->PLL0FEED  = 0xAA;
+      LPC_SC->PLL0FEED  = 0x55;
+      while (!(LPC_SC->PLL0STAT & (1<<26)));
+    
+      LPC_SC->PLL0CON   = 0x03;
+      LPC_SC->PLL0FEED  = 0xAA;
+      LPC_SC->PLL0FEED  = 0x55;
+}
+
+void setPLL1Frequency(unsigned char clkSrc, unsigned short M, unsigned char N)
+{
+      LPC_SC->CLKSRCSEL = clkSrc;
+      LPC_SC->PLL1CFG   = (((unsigned int)N-1) << 16) | M-1;
+      LPC_SC->PLL1CON   = 0x01;             
+      LPC_SC->PLL1FEED  = 0xAA;
+      LPC_SC->PLL1FEED  = 0x55;
+      while (!(LPC_SC->PLL1STAT & (1<<26)));
+    
+      LPC_SC->PLL1CON   = 0x03;
+      LPC_SC->PLL1FEED  = 0xAA;
+      LPC_SC->PLL1FEED  = 0x55;
+}
+
+unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short M, unsigned char N)
+{
+    setPLL0Frequency(clkSrc, M, N);
+    LPC_SC->CCLKCFG = clkDivider - 1;
+    SystemCoreClockUpdate();
+    return SystemCoreClock;
+}
\ No newline at end of file
diff -r 571258908570 -r 15d9501bf5b3 ClockControl/ClockControl.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ClockControl/ClockControl.h	Sat Aug 02 16:01:23 2014 +0000
@@ -0,0 +1,14 @@
+/* mbed PowerControl Library
+  * Copyright (c) 2010 Michael Wei
+  */ 
+  
+//shouldn't have to include, but fixes weird problems with defines
+//#include "LPC1768/LPC17xx.h"
+#include "mbed.h"
+#ifndef MBED_CLOCKCONTROL_H 
+#define MBED_CLOCKCONTROL_H 
+
+unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short M, unsigned char N);
+void setPLL0Frequency(unsigned char clkSrc, unsigned short M, unsigned char N);
+void setPLL1Frequency(unsigned char clkSrc, unsigned short M, unsigned char N);
+#endif
\ No newline at end of file
diff -r 571258908570 -r 15d9501bf5b3 Pulses.lib
--- a/Pulses.lib	Thu Jul 24 08:53:44 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/jocis/code/Pulses/#36dd0d59fdc8
diff -r 571258908570 -r 15d9501bf5b3 RTC.lib
--- a/RTC.lib	Thu Jul 24 08:53:44 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/Sissors/code/RTC/#1569766a1db5
diff -r 571258908570 -r 15d9501bf5b3 WakeUp.lib
--- a/WakeUp.lib	Thu Jul 24 08:53:44 2014 +0000
+++ b/WakeUp.lib	Sat Aug 02 16:01:23 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Sissors/code/WakeUp/#542c0ca509e5
+http://mbed.org/users/steniu01/code/WakeUp/#542c0ca509e5
diff -r 571258908570 -r 15d9501bf5b3 main.cpp
--- a/main.cpp	Thu Jul 24 08:53:44 2014 +0000
+++ b/main.cpp	Sat Aug 02 16:01:23 2014 +0000
@@ -1,115 +1,52 @@
 #include "mbed.h"
-#include "RTC.h"
 #include "PowerControl.h"
 #include "EthernetPowerControl.h"
 #include "WakeUp.h"
-#include "steven_powercontrol.h"
-#include "Pulses.h"
+#include "powercontrol.h"
+#include "ClockControl/ClockControl.h"
 
 
 DigitalOut myled1(LED1);
 DigitalOut myled2(LED2) ;
 DigitalOut myled3(LED3) ;
-Serial pc (USBTX, USBRX);
-Timer t;
-//CPU_Usage cpu(t, 1);
-
-AnalogOut multimeter(p18);
-
-// Example for energy meter with SO interface.
-// SO output of energy meter is connected (over opto-coppler) to pin 8
-#define SO_PULSES 2000 // SO interface of energy meter with 2000 pulses per kWh
-Pulses pulses(p8, Pulses::FALL);
-
-void steven_get_string(){
-   char input[50]; 
-   int num=0;
-   while (1){
-        char ret=pc.getc();
-        pc.putc(ret);
-        if (num >=50){
-            pc.printf("Overflow \n");
-            break;
-        }
-        if (ret!=(char)NULL)
-            input[num++]=ret;
-        if(ret==(char)13)
-            break; 
-    }
-    pc.printf ("\n");
-    pc.printf ("you have input %s \n",input);
-}
 
-void power_measurement(void){
-    pulses.setFactor ( 3600.0f/SO_PULSES );   // Scale to kW; kWh
-    float averagePower = 0;    // Average energy since last call of get()
-    float minPower = 0;        // Min. energy since last call of get()
-    float maxPower = 0;        // Max. energy since last call of get()
-    float sumEnergy = 0;       // Sum of energy over all since start of mbed
-    
-    while(1) {
-        
-        pulses.get ( &averagePower, &minPower, &maxPower, &sumEnergy );
-        
-        pc.printf ( "Power: %.3f (%.3f...%.3f) [kW]   Energy: %.3f [kWh]   SO-pulses=%d\r\n", 
-            averagePower,
-            minPower,
-            maxPower,
-            sumEnergy / 3600.0f,
-            pulses.getCounter() );
+Timer t;
 
-        // wait(6);   // Example 6 seconds; typical 1 minute (60 sec) sample time
-        
-        // Additional feature: Output of actual power as analog voltage (1V==1kW; max3.3kW). Connect a multimeter to pin 18 and GND
-        for ( int i=0; i<20; i++ ) {
-            multimeter = pulses.getAct() / 3.3f;   // Scale to 1V==1kW
-            wait(0.3);   // Example 6 seconds; typical 1 minute (60 sec) sample time
-        }
-    }     
-}
-void profiling_PHY_PowerDown (void)
-{
-    //PHY_PowerUp();
-    if (!Peripheral_GetStatus(LPC1768_PCONP_PCENET))
-        EMAC_Init(); //init EMAC if it is not already init'd
-    
-    unsigned int regv;
-    wait (10);
-    myled1=1;
-    myled2=0;
-    myled2=0;
-    regv = read_PHY(PHY_REG_BMCR);
-    write_PHY(PHY_REG_BMCR, regv | (1 << PHY_REG_BMCR_POWERDOWN));
-    regv = read_PHY(PHY_REG_BMCR);
-    wait (10);
-    myled1=0;
-    myled2=1;
-    myled3=0;
-    //shouldn't need the EMAC now.
-    LPC_SC->PCONP &=~LPC1768_PCONP_PCENET;
-    wait (10);
-    myled1=0;
-    myled2=0;
-    myled3=1;
-    //and turn off the PHY OSC
-    LPC_GPIO1->FIODIR |= 0x8000000;
-    LPC_GPIO1->FIOCLR = 0x8000000;
-    while(1);
 
-}
 
 int main()
 {
     //profiling_PHY_PowerDown();
     //PHY_PowerUp();// power up PHY because it was powerred up as default. We might power it down when test "Turn off PHY".
+    
     myled1=1;
     wait(0.5);
     myled1=0;
     char char_get=0;
     int num_get=0;
     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"};
+    
+    
+    printf("Which frequency you want to run \r\n");
+    printf("[1] 96MHz \r\n");
+    printf("[2] 48MHz \r\n");
+    char_get=getchar();
+    num_get=char_get-48;
+   
+    
+    switch (num_get){
+        case 1: setSystemFrequency(0x3, 0x1, 12, 1);break;
+        case 2: setSystemFrequency(0x3, 0x1, 12, 2);break;
+        default: setSystemFrequency(0x3, 0x1, 12, 1);break;
+    }
+     Serial pc (USBTX, USBRX);
+    pc.printf ("num_get is %d \r\n", num_get);
+    wait (3);
+    num_get=0;
+    char_get=0;
+    
     while (num_get>7 || num_get<1){
-        printf("Which power mode you want to choose: \r\n");
+        pc.printf("Which power mode you want to choose: \r\n");
         for (int a=0;a<7;a++)
             pc.printf("%s \r\n", powermode[a]);
         char_get=pc.getc(); // get char from serial
@@ -121,8 +58,8 @@
     myled2=1;
     wait(0.5);
     myled2=0;
-    //WakeUp::set(10);
-    WakeUp::set(70);
+    WakeUp::set(10);
+    //WakeUp::set(70);
     switch (num_get){
         case  1: break;
         case  2: steven_Sleep();break;
@@ -130,7 +67,7 @@
         case  4: steven_PowerDown();break;
         case  5: steven_BOGD_PowerDown();break;
         case  6: steven_DeepPowerDown(); break;
-        case  7: profiling_PHY_PowerDown(); break;
+        case  7: PHY_PowerDown(); break;
         default: pc.printf("Not valid input\n"); break;          
     }     
    while (1);
diff -r 571258908570 -r 15d9501bf5b3 steven_powercontrol.lib
--- a/steven_powercontrol.lib	Thu Jul 24 08:53:44 2014 +0000
+++ b/steven_powercontrol.lib	Sat Aug 02 16:01:23 2014 +0000
@@ -1,1 +1,1 @@
-steven_powercontrol#fc6cd61e7460
+http://mbed.org/users/steniu01/code/steven_powercontrol/#2976b5aa967b