Proto Drive / Mbed 2 deprecated Protodrive

Dependencies:   RPCInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers power_sources.h Source File

power_sources.h

00001 /*****************************************************************************/
00002 /*Constants                                                                  */
00003 /*****************************************************************************/
00004 
00005 #define SCAP_MIN_VOLTAGE 0.607      //Switch to batt below this value (supercap)
00006 #define SCAP_MAX_VOLTAGE 0.845      //Switch to batt above this value (supercap)
00007 #define BATT_MIN_VOLTAGE 0.71       //Shutoff below this value (battery)
00008 #define BATT_MAX_VOLTAGE 0.825      //Shutoff above this value (battery)
00009 
00010 /*****************************************************************************/
00011 /*Pin Setup                                                                  */
00012 /*****************************************************************************/
00013 
00014 DigitalOut relay(p23);          //Pin from which the relay coil is triggered
00015 
00016 /*****************************************************************************/
00017 /*Subroutines                                                                */
00018 /*****************************************************************************/
00019 
00020 //Checks battery and supercap voltages, returning 1 if the system needs to be shut down.
00021 int checkBattVoltages() {
00022     //Check to see if batteries are out of proper voltage range
00023 #ifdef DUT_BATT_ENABLE
00024     //check DUT batt
00025     if (v_DUT_batt_measure < BATT_MIN_VOLTAGE
00026             || v_DUT_batt_measure> BATT_MAX_VOLTAGE) { //check if voltage out of range
00027         relay = 1; //switch to cap
00028         return 1;
00029     }
00030 #endif
00031 
00032 #ifdef DUT_BATT_CAP_ENABLE
00033     //check DUT batt
00034     if (v_DUT_batt_measure < BATT_MIN_VOLTAGE
00035             || v_DUT_batt_measure> BATT_MAX_VOLTAGE) { //check if voltage out of range
00036         relay = 1; //switch to cap
00037         return 1;
00038     }
00039 #endif
00040 
00041 #ifdef LOAD_BATT_ENABLE
00042     //check load batt
00043     if ( v_load_batt_measure < BATT_MIN_VOLTAGE
00044             ||  v_load_batt_measure> BATT_MAX_VOLTAGE) { //check if voltage out of range
00045         return 1;
00046     }
00047 #endif
00048     return 0; //return 0 if all batts are in the correct voltage range
00049 }
00050 
00051 #ifdef DUT_BATT_CAP_ENABLE
00052 void superCapControl() {
00053     if (v_cap_measure <= SCAP_MIN_VOLTAGE && !regen
00054             || 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.
00055         relay = 0; //switch to battery
00056     } else relay = 1; //switch to cap
00057 }
00058 #endif