[IV] Try AutoGain

This commit is contained in:
weiting2
2019-11-16 10:32:35 +08:00
parent fb58112ba7
commit 47af16a2e2
2 changed files with 20 additions and 5 deletions
@@ -725,7 +725,8 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
// return real current to controller
else if(ADCChannel == ADC_CH_CURRENT){
if ( (INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
// if ( (INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
if ( (INSTRUCTION.eliteFxn == CV_CURVE)) {
// wait 0.1 sec until circuit stable => discard first data means wait 0.1 sec
if(DiscardIVFirstData){
DiscardIVFirstData ++;
@@ -88,6 +88,7 @@ static uint16_t OneWayVoltScan(IVMode *IV) {
static void IV_Plot(IVMode *IV) {
static uint8_t VoltCurrentSwitch = 0;
static uint8_t PreviousGain = GAIN_200R;
uint16_t ADC_measure = 0;
if(VoltCurrentSwitch < 5){
@@ -96,10 +97,23 @@ static void IV_Plot(IVMode *IV) {
}
else if(VoltCurrentSwitch == 5){
// read current
ReadCurrent(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
IV->_MeasureData = DecodeADCCurrent(INSTRUCTION.ADCGainLevel, ADC_measure);
VoltCurrentSwitch ++;
if(INSTRUCTION.AutoGainEnable){
IV->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
while(PreviousGain != INSTRUCTION.ADCGainLevel){
PreviousGain = INSTRUCTION.ADCGainLevel;
IV->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
}
}
else{
ReadCurrent(spi_ADC_rxbuf);
IV->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
// ReadCurrent(spi_ADC_rxbuf);
// ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// IV->_MeasureData = DecodeADCCurrent(INSTRUCTION.ADCGainLevel, ADC_measure);
// VoltCurrentSwitch ++;
}
else if(VoltCurrentSwitch <9){
// read volt