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
Diff: main.cpp
- Revision:
- 1:b1921e153d21
- Parent:
- 0:17ad5a30ff25
- Child:
- 2:c08efa9effc8
--- a/main.cpp Thu May 16 07:31:47 2013 +0000 +++ b/main.cpp Fri May 17 10:42:54 2013 +0000 @@ -1,19 +1,5 @@ #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 +#include "WiGo_BattCharger.h" #define RGB_LED_ON 0 #define RGB_LED_OFF 1 @@ -24,37 +10,24 @@ 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); +WiGo_BattCharger Batt( BATT_LOW, BATT_MED, BATT_FULL, CHRG_EN1, CHRG_EN2, CHRG_SNS_EN, CHRG_SNS, CHRG_POK, CHRG_CHG); float max_batt; -float min_batt; float batt_lvl; int main() { - - //100mA Charge - ChargeEN1 = 0; - ChargeEN2 = 0; + Batt.init(); + Batt.sense_en(1); - ChargeSenseEN = 0; wait(0.5); - max_batt = ChargeSense; - min_batt = ChargeSense; + max_batt = Batt.read(); + while(1) { //If charging then blink Blue led to show we are alive - if( Charging == CHARGING ) { + if( Batt.charging() == CHARGING ) { myled2 = RGB_LED_OFF; myled3 = RGB_LED_OFF; @@ -65,7 +38,7 @@ } //If no power applied (via USB) then turn all on, blink Bled led off - if( SupplyOk != POWER_OK ) { + if( Batt.supply() != POWER_OK ) { myled2 = RGB_LED_ON; myled3 = RGB_LED_ON; @@ -75,37 +48,13 @@ wait(0.9); } - batt_lvl = ChargeSense; + Batt.LEDupdate(); - 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; - } - + batt_lvl = Batt.read(); if( batt_lvl > max_batt ) { max_batt = batt_lvl; } - pc.printf(">%f Min:%f Max:%f\n\r", batt_lvl, min_batt, max_batt); + pc.printf(">%f Max:%f\n\r", batt_lvl, max_batt); } }