Used with KL25Z Freescale board to access the Avnet Wi-Go Battery charger
Dependents: Wi-Go_IOT_Demo IoT_World_Hackathon_WiGo_NSP_Demo Wi-Go_IOT_Demo_MKII
Fork of WiGo_BattCharger by
Modified BattCharger from https://mbed.org/users/monpjc/code/WiGo_BattCharger/ - removed LED pins and added raw read.
Revision 0:d52ea6d270c0, committed 2013-05-17
- Comitter:
- monpjc
- Date:
- Fri May 17 10:39:52 2013 +0000
- Child:
- 1:4c20371cd5c2
- Commit message:
- NEW: First release
Changed in this revision
WiGo_BattCharger.cpp | Show annotated file Show diff for this revision Revisions of this file |
WiGo_BattCharger.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WiGo_BattCharger.cpp Fri May 17 10:39:52 2013 +0000 @@ -0,0 +1,70 @@ +#include "WiGo_BattCharger.h" +#include "mbed.h" + +WiGo_BattCharger::WiGo_BattCharger( PinName battlow, PinName battmed, PinName battfull, PinName en1, PinName en2, PinName snsen, PinName sense, PinName supplystate, PinName chargestate ) : _battlow(battlow), _battmed(battmed), _battfull(battfull), _en1(en1), _en2(en2), _snsen(snsen), _sense(sense), _supplystate(supplystate), _chargestate(chargestate) +{ + _battlow = BATT_LED_OFF; //Default State + _battmed = BATT_LED_OFF; + _battfull = BATT_LED_OFF; + _en1 = 0; //100mA Charge + _en2 = 0; + _snsen = 1; //Off +} + +void WiGo_BattCharger::init( void ) +{ + //100mA Charge + _en1 = 0; + _en2 = 0; +} + +void WiGo_BattCharger::sense_en( int n) +{ + if( n == 0 ) + _snsen = 1; + else + _snsen = 0; +} + +float WiGo_BattCharger::read( void ) +{ + return _sense; +} + +int WiGo_BattCharger::charging( void ) +{ + return _chargestate; +} + +int WiGo_BattCharger::supply( void ) +{ + return _supplystate; +} + +void WiGo_BattCharger::LEDupdate( void ) +{ + float batt_level; + init(); + sense_en(1); + batt_level = read(); + if( batt_level <= BATT_0 ) { + _battlow = BATT_LED_OFF; + _battmed = BATT_LED_OFF; + _battfull = BATT_LED_OFF; + } + if( batt_level > BATT_0 && batt_level <= 0.605 ) { + _battlow = BATT_LED_ON; + _battmed = BATT_LED_OFF; + _battfull = BATT_LED_OFF; + } + if( batt_level > 0.605 && batt_level <= BATT_100 ) { + _battlow = BATT_LED_ON; + _battmed = BATT_LED_ON; + _battfull = BATT_LED_OFF; + } + if( batt_level > BATT_100 ) { + _battlow = BATT_LED_ON; + _battmed = BATT_LED_ON; + _battfull = BATT_LED_ON; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WiGo_BattCharger.h Fri May 17 10:39:52 2013 +0000 @@ -0,0 +1,55 @@ +#ifndef _WIGO_BATTCHARGER_H_ +#define _WIGO_BATTCHARGER_H_ + +#include "mbed.h" + +//Battery Circuit for Avnet PCB +#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 BATT_LED_ON 0 +#define BATT_LED_OFF 1 +#define BATT_0 0.53 +#define BATT_100 0.67 + +class WiGo_BattCharger +{ +public: + + WiGo_BattCharger( PinName battlow, PinName battmed, PinName battfull, + PinName en1, PinName en2, PinName snsen, PinName sense, + PinName supplystate, PinName chargestate ); + + void init( void ); + + void sense_en( int n); + + float read( void ); + + int charging( void ); + + int supply( void ); + + void LEDupdate( void ); + +protected: + DigitalOut _battfull; + DigitalOut _battmed; + DigitalOut _battlow; + DigitalOut _en1; + DigitalOut _en2; + DigitalOut _snsen; + DigitalIn _supplystate; + DigitalIn _chargestate; + AnalogIn _sense; +}; + +#endif