test battery(not ok)

This commit is contained in:
YiChin
2020-06-29 18:47:14 +08:00
parent 07ebae4f64
commit fac1427eb6
6 changed files with 42 additions and 22 deletions
@@ -157,11 +157,9 @@ static void ReadCurrent(uint8_t *buf){
static void ReadBatVolt(uint8_t *buf){
// Read data twice since the first data we get is previous data
ADCChannelSelect(ADC_CH_BAT);
CPUdelay(10);
ADC_read(buf);
ADCChannelSelect(ADC_CH_BAT);
CPUdelay(10);
ADC_read(buf);
}
@@ -1852,7 +1852,7 @@ static int32_t DecodeADCBatVolt(uint16_t ADC_measure){
long long ADCBatVolt = 0;
ADCBatVolt = (12571991860 * ADC_measure + 3314058604700);
ADCBatVolt = ADCBatVolt / 1e11;
ADCBatVolt = ADCBatVolt / 1e8;
return (int32_t) (ADCBatVolt);
}
@@ -37,17 +37,39 @@ static uint8_t headstage_battery_volt2() {
return battery_volt;
}
static uint8_t headstage_battery_volt3() {
uint8_t internal_battery_percent;
uint16_t bat_volt = 0;
ReadBatVolt(spi_ADC_rxbuf);
uint32_t internal_batt_sense = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_BAT, spi_ADC_rxbuf);
internal_batt_sense = internal_batt_sense * 32 / 1000 / 125;
internal_battery_percent = internal_batt_sense & 0xFF;
battery_volt = internal_battery_percent;
return battery_volt;
}
static uint8_t headstage_battery_volt4() {
uint8_t internal_battery_percent;
uint16_t bat_volt = 0;
ReadBatVolt(spi_ADC_rxbuf);
uint32_t internal_batt_sense = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_BAT, spi_ADC_rxbuf);
internal_batt_sense = internal_batt_sense * 32 / 1000 / 125;
internal_battery_percent = (internal_batt_sense >> 8) & 0xFF;
battery_volt = internal_battery_percent;
return battery_volt;
}
static uint8_t headstage_battery_volt(){
uint16_t bat_volt = 0;
ReadBatVolt(spi_ADC_rxbuf);
bat_volt = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// Battery voltage < 3V, turn off Elite.
if(bat_volt < 8500 && bat_volt > 200) {
PIN_setOutputValue(pin_handle, enable_5v, 0);
}else{
PIN_setOutputValue(pin_handle, enable_5v, 1);
}
// if(bat_volt < 8500 && bat_volt > 200) {
// PIN_setOutputValue(pin_handle, enable_5v, 0);
// }else{
// PIN_setOutputValue(pin_handle, enable_5v, 1);
// }
return battery_volt;
}
@@ -5,8 +5,8 @@
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 6
#define VERSION_DATE_DAY 29
#define VERSION_DATE_HOUR 15
#define VERSION_DATE_MINUTE 35
#define VERSION_DATE_HOUR 18
#define VERSION_DATE_MINUTE 47
// this is NOT the version hash !!
// it's the last version hash
@@ -1376,8 +1376,8 @@ static void update_ZM_instruction(uint8 *ins) {
case CIS_VOLT: {
cis_buf[0] = CIS_VOLT;
cis_buf[1] = headstage_battery_volt1();
cis_buf[2] = headstage_battery_volt2();
cis_buf[1] = headstage_battery_volt3();
cis_buf[2] = headstage_battery_volt4();
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
@@ -629,16 +629,16 @@ uint16_t bat_counter = 0;
// }
// #undef THREE_POINT_THREE_VOLT
uint16_t bat_volt = 0;
ReadBatVolt(spi_ADC_rxbuf);
bat_volt = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// Battery voltage < 3V, turn off Elite.
if(bat_volt < 8500 && bat_volt > 200) {
PIN_setOutputValue(pin_handle, enable_5v, 0);
}else{
PIN_setOutputValue(pin_handle, enable_5v, 1);
}
// uint16_t bat_volt = 0;
// ReadBatVolt(spi_ADC_rxbuf);
// bat_volt = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
//
// // Battery voltage < 3V, turn off Elite.
// if(bat_volt < 8500 && bat_volt > 200) {
// PIN_setOutputValue(pin_handle, enable_5v, 0);
// }else{
// PIN_setOutputValue(pin_handle, enable_5v, 1);
// }
bat_counter = 0;
} else {
bat_counter++;