Used for testing battery sense circuit, looking for max and min levels. Allow for finding true empty, half and full values for driving LEDs for example
Dependencies: mbed MPL3115A2 TSI WiGo_BattCharger
Revision 0:17ad5a30ff25, committed 2013-05-16
- Comitter:
- monpjc
- Date:
- Thu May 16 07:31:47 2013 +0000
- Child:
- 1:b1921e153d21
- Commit message:
- Basic test of max and min batt levels
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 16 07:31:47 2013 +0000 @@ -0,0 +1,111 @@ +#include "mbed.h" + +//Battery Circuit +#define BATT_FULL PTB10 +#define BATT_MED PTB9 +#define BATT_LOW PTB8 +#define CHRG_EN1 PTB2 +#define CHRG_EN2 PTB3 +#define CHRG_SNS_EN PTC2 +#define CHRG_SNS PTB1 +#define CHRG_POK PTC6 +#define CHRG_CHG PTA5 +#define POWER_OK 0 +#define CHARGING 0 +#define LED_ON 0 +#define LED_OFF 1 + +#define RGB_LED_ON 0 +#define RGB_LED_OFF 1 + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); + +Serial pc(USBTX, USBRX); + +//Battery +DigitalOut BattFull(BATT_FULL); +DigitalOut BattMed(BATT_MED); +DigitalOut BattLow(BATT_LOW); +DigitalOut ChargeEN1(CHRG_EN1); +DigitalOut ChargeEN2(CHRG_EN2); +DigitalOut ChargeSenseEN(CHRG_SNS_EN); +DigitalIn SupplyOk(CHRG_POK); +DigitalIn Charging(CHRG_CHG); +AnalogIn ChargeSense(CHRG_SNS); + +float max_batt; +float min_batt; +float batt_lvl; + +int main() +{ + + //100mA Charge + ChargeEN1 = 0; + ChargeEN2 = 0; + + ChargeSenseEN = 0; + wait(0.5); + max_batt = ChargeSense; + min_batt = ChargeSense; + + while(1) { + + //If charging then blink Blue led to show we are alive + if( Charging == CHARGING ) { + myled2 = RGB_LED_OFF; + myled3 = RGB_LED_OFF; + + myled1 = RGB_LED_ON; + wait(0.1); + myled1 = RGB_LED_OFF; + wait(0.9); + } + + //If no power applied (via USB) then turn all on, blink Bled led off + if( SupplyOk != POWER_OK ) { + myled2 = RGB_LED_ON; + myled3 = RGB_LED_ON; + + myled1 = RGB_LED_OFF; + wait(0.1); + myled1 = RGB_LED_ON; + wait(0.9); + } + + batt_lvl = ChargeSense; + + if( batt_lvl <= 0.53 ) { + BattLow = LED_OFF; + BattMed = LED_OFF; + BattFull = LED_OFF; + } + if( batt_lvl > 0.53 && batt_lvl <= 0.605 ) { + BattLow = LED_ON; + BattMed = LED_OFF; + BattFull = LED_OFF; + } + if( batt_lvl > 0.605 && batt_lvl <= 0.67 ) { + BattLow = LED_ON; + BattMed = LED_ON; + BattFull = LED_OFF; + } + if( batt_lvl > 0.67 ) { + BattLow = LED_ON; + BattMed = LED_ON; + BattFull = LED_ON; + } + + if( batt_lvl < min_batt ) { + min_batt = batt_lvl; + } + + if( batt_lvl > max_batt ) { + max_batt = batt_lvl; + } + + pc.printf(">%f Min:%f Max:%f\n\r", batt_lvl, min_batt, max_batt); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 16 07:31:47 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17 \ No newline at end of file