[CC mode] read Vin

This commit is contained in:
weiting2
2019-11-11 10:26:13 +08:00
parent c862e6790f
commit f5796e8ac5
2 changed files with 38 additions and 17 deletions
@@ -6,7 +6,7 @@ static void CCModeDACControl(int32_t IUC_Measure_Difference);
static int32_t CCModeReadCurrent(CCMode *CC){
static bool IVSwitch = false;
static uint8_t VoltCurrentSwitch = 0;
CCModeDACEnable = 1; // This flag will control DAC working
@@ -14,8 +14,15 @@ static int32_t CCModeReadCurrent(CCMode *CC){
CCCurrent2IUC(CC);
// decode ADC value and put it into notify buffer
// if(IVSwitch){
IVSwitch = false;
// Use 9-th measure value as real-measure value
// because some value in the begin are garbage
if(VoltCurrentSwitch < 9){
ReadCurrent(spi_ADC_rxbuf);
VoltCurrentSwitch ++;
}
else if(VoltCurrentSwitch == 9){
// read current
if(INSTRUCTION.AutoGainEnable){
CC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
}
@@ -23,21 +30,35 @@ static int32_t CCModeReadCurrent(CCMode *CC){
ReadCurrent(spi_ADC_rxbuf);
CC->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
// }
// else{
// IVSwitch = true;
// /** read battery voltage **/
// // read ADC volt
// ReadVolt(spi_ADC_rxbuf);
VoltCurrentSwitch ++;
}
else if(VoltCurrentSwitch <18){
// read volt
ReadVolt(spi_ADC_rxbuf);
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 18){
// read volt
ReadVolt(spi_ADC_rxbuf);
CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
VoltCurrentSwitch++;
}
else{
VoltCurrentSwitch = 0;
}
// /** read battery voltage **/
// // read ADC volt
// ReadVolt(spi_ADC_rxbuf);
//
// // decode ADC value and put it into notify buffer
// CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
// }
// // decode ADC value and put it into notify buffer
// CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
//
// NotifyVolt[0] = (uint8_t) (CC->BatteryV >> 24);
// NotifyVolt[1] = (uint8_t) ((CC->BatteryV & 0x00FF0000) >> 16);
// NotifyVolt[2] = (uint8_t) ((CC->BatteryV & 0x0000FF00) >> 8);
// NotifyVolt[3] = (uint8_t) (CC->BatteryV & 0x000000FF);
NotifyVolt[0] = (uint8_t) (CC->BatteryV >> 24);
NotifyVolt[1] = (uint8_t) ((CC->BatteryV & 0x00FF0000) >> 16);
NotifyVolt[2] = (uint8_t) ((CC->BatteryV & 0x0000FF00) >> 8);
NotifyVolt[3] = (uint8_t) (CC->BatteryV & 0x000000FF);
return CC->_MeasureData;
}
@@ -879,7 +879,7 @@ static void update_ZM_instruction(uint8 *ins) {
case CONSTANT_CURRENT:{
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.SampleRate = 10;
INSTRUCTION.SampleRate = 6;
INSTRUCTION.ConstantCurrent = ( (uint32_t) (ins[3])<<24 | (uint32_t) (ins[4])<<16 | (uint32_t) (ins[5])<<8 | (uint32_t) (ins[6]) );
INSTRUCTION.NotifyRate = 1000;
// GetInstructionParameter(ins+2);