Dependencies:   RPCInterface mbed

Committer:
protodriveev
Date:
Mon May 07 16:14:45 2012 +0000
Revision:
0:2dbd366be5fd

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
protodriveev 0:2dbd366be5fd 1 /*****************************************************************************/
protodriveev 0:2dbd366be5fd 2 /*Constants */
protodriveev 0:2dbd366be5fd 3 /*****************************************************************************/
protodriveev 0:2dbd366be5fd 4
protodriveev 0:2dbd366be5fd 5 #define SCAP_MIN_VOLTAGE 0.607 //Switch to batt below this value (supercap)
protodriveev 0:2dbd366be5fd 6 #define SCAP_MAX_VOLTAGE 0.845 //Switch to batt above this value (supercap)
protodriveev 0:2dbd366be5fd 7 #define BATT_MIN_VOLTAGE 0.71 //Shutoff below this value (battery)
protodriveev 0:2dbd366be5fd 8 #define BATT_MAX_VOLTAGE 0.825 //Shutoff above this value (battery)
protodriveev 0:2dbd366be5fd 9
protodriveev 0:2dbd366be5fd 10 /*****************************************************************************/
protodriveev 0:2dbd366be5fd 11 /*Pin Setup */
protodriveev 0:2dbd366be5fd 12 /*****************************************************************************/
protodriveev 0:2dbd366be5fd 13
protodriveev 0:2dbd366be5fd 14 DigitalOut relay(p23); //Pin from which the relay coil is triggered
protodriveev 0:2dbd366be5fd 15
protodriveev 0:2dbd366be5fd 16 /*****************************************************************************/
protodriveev 0:2dbd366be5fd 17 /*Subroutines */
protodriveev 0:2dbd366be5fd 18 /*****************************************************************************/
protodriveev 0:2dbd366be5fd 19
protodriveev 0:2dbd366be5fd 20 //Checks battery and supercap voltages, returning 1 if the system needs to be shut down.
protodriveev 0:2dbd366be5fd 21 int checkBattVoltages() {
protodriveev 0:2dbd366be5fd 22 //Check to see if batteries are out of proper voltage range
protodriveev 0:2dbd366be5fd 23 #ifdef DUT_BATT_ENABLE
protodriveev 0:2dbd366be5fd 24 //check DUT batt
protodriveev 0:2dbd366be5fd 25 if (v_DUT_batt_measure < BATT_MIN_VOLTAGE
protodriveev 0:2dbd366be5fd 26 || v_DUT_batt_measure> BATT_MAX_VOLTAGE) { //check if voltage out of range
protodriveev 0:2dbd366be5fd 27 relay = 1; //switch to cap
protodriveev 0:2dbd366be5fd 28 return 1;
protodriveev 0:2dbd366be5fd 29 }
protodriveev 0:2dbd366be5fd 30 #endif
protodriveev 0:2dbd366be5fd 31
protodriveev 0:2dbd366be5fd 32 #ifdef DUT_BATT_CAP_ENABLE
protodriveev 0:2dbd366be5fd 33 //check DUT batt
protodriveev 0:2dbd366be5fd 34 if (v_DUT_batt_measure < BATT_MIN_VOLTAGE
protodriveev 0:2dbd366be5fd 35 || v_DUT_batt_measure> BATT_MAX_VOLTAGE) { //check if voltage out of range
protodriveev 0:2dbd366be5fd 36 relay = 1; //switch to cap
protodriveev 0:2dbd366be5fd 37 return 1;
protodriveev 0:2dbd366be5fd 38 }
protodriveev 0:2dbd366be5fd 39 #endif
protodriveev 0:2dbd366be5fd 40
protodriveev 0:2dbd366be5fd 41 #ifdef LOAD_BATT_ENABLE
protodriveev 0:2dbd366be5fd 42 //check load batt
protodriveev 0:2dbd366be5fd 43 if ( v_load_batt_measure < BATT_MIN_VOLTAGE
protodriveev 0:2dbd366be5fd 44 || v_load_batt_measure> BATT_MAX_VOLTAGE) { //check if voltage out of range
protodriveev 0:2dbd366be5fd 45 return 1;
protodriveev 0:2dbd366be5fd 46 }
protodriveev 0:2dbd366be5fd 47 #endif
protodriveev 0:2dbd366be5fd 48 return 0; //return 0 if all batts are in the correct voltage range
protodriveev 0:2dbd366be5fd 49 }
protodriveev 0:2dbd366be5fd 50
protodriveev 0:2dbd366be5fd 51 #ifdef DUT_BATT_CAP_ENABLE
protodriveev 0:2dbd366be5fd 52 void superCapControl() {
protodriveev 0:2dbd366be5fd 53 if (v_cap_measure <= SCAP_MIN_VOLTAGE && !regen
protodriveev 0:2dbd366be5fd 54 || regen && v_cap_measure >= SCAP_MAX_VOLTAGE) { //if cap is drained, and regen is not engaged, switch back to battery. Or if cap is at its max voltage, and regen is engaged, switch to batt to prevent overcharging of cap.
protodriveev 0:2dbd366be5fd 55 relay = 0; //switch to battery
protodriveev 0:2dbd366be5fd 56 } else relay = 1; //switch to cap
protodriveev 0:2dbd366be5fd 57 }
protodriveev 0:2dbd366be5fd 58 #endif