diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h index 44e4db2cc..48a8f12f5 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h @@ -125,19 +125,20 @@ static void ADCChannelSelect(uint8_t ADCChannel){ // this function turn ADC measure value (0xXXXX) into real voltage // unit should be mV -static float DecodeADCVolt(uint16_t ADC_measure){ - float ADCRealVolt = 0; - float coeff = -0.629056, offset = 15447.740744; +static int32_t DecodeADCVolt(uint16_t ADC_measure){ + int32_t ADCRealVolt = 0; + int32_t coeff = -62905, offset = 1544774074; ADCRealVolt = (coeff * ADC_measure + offset); + ADCRealVolt = ADCRealVolt / 100000; return ADCRealVolt; } // this function turn ADC measure value (0xXXXX) into real current // unit should be pA -static float DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){ - float ADCRealCurrent = 0; - float coeff[3] = {0}, offset[3] = {0}; +static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){ + int32_t ADCRealCurrent = 0; + int32_t coeff[3] = {0}, offset[3] = {0}; coeff[0] = 1; coeff[1] = 2; @@ -152,30 +153,27 @@ static float DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){ } // Decode ADC measure value (could be a volt or current) and put it into notify buffer -static float DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){ +static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){ uint16_t ADC_measure = (uint16_t) (ADC_raw[0] << 8) | (uint16_t) (ADC_raw[1]); - uint32_t ret = 0, ADCRealVolt = 0, ADCRealCurrent = 0; - int32_t Vout; + int32_t ret = 0, ADCRealCurrent = 0, ADCRealVolt = 0; // return real volt to controller if(ADCChannel == ADC_CH_VOLT){ ADCRealVolt = DecodeADCVolt(ADC_measure); - Vout = (int32_t) (ADCRealVolt / 1); - NotifyVolt[0] = (uint8_t) (Vout >> 24); - NotifyVolt[1] = (uint8_t) ((Vout & 0x00110000) >> 16); - NotifyVolt[2] = (uint8_t) ((Vout & 0x00001100) >> 8); - NotifyVolt[3] = (uint8_t) (Vout & 0x00000011); + NotifyVolt[0] = (uint8_t) (ADCRealVolt >> 24); + NotifyVolt[1] = (uint8_t) ((ADCRealVolt & 0x00110000) >> 16); + NotifyVolt[2] = (uint8_t) ((ADCRealVolt & 0x00001100) >> 8); + NotifyVolt[3] = (uint8_t) (ADCRealVolt & 0x00000011); ret = ADCRealVolt; } // return real current to controller else if(ADCChannel == ADC_CH_CURRENT){ ADCRealCurrent = DecodeADCCurrent(ADCGain, ADC_measure); - Vout = (int32_t) (ADCRealCurrent / 1); - NotifyCurrent[0] = (uint8_t) (Vout >> 24); - NotifyCurrent[1] = (uint8_t) ((Vout & 0x00110000) >> 16); - NotifyCurrent[2] = (uint8_t) ((Vout & 0x00001100) >> 8); - NotifyCurrent[3] = (uint8_t) (Vout & 0x00000011); + NotifyCurrent[0] = (uint8_t) (ADCRealCurrent >> 24); + NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent & 0x00110000) >> 16); + NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent & 0x00001100) >> 8); + NotifyCurrent[3] = (uint8_t) (ADCRealCurrent & 0x00000011); ret = ADCRealCurrent; } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h index cd2053df9..219b61971 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h @@ -593,9 +593,9 @@ static void ADC_read(uint8_t *ADCdata); static void ADCGainControl(uint8_t ADCLevel); static void ADCChannelSelect(uint8_t ADCChannel); -static float DecodeADCVolt(uint16_t ADC_measure); -static float DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure); -static float DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw); +static int32_t DecodeADCVolt(uint16_t ADC_measure); +static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure); +static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw); // DAC function static uint16_t DACCorrectionDecode(uint16_t usercode); @@ -866,7 +866,7 @@ static void update_ZM_instruction(uint8 *ins) { case ADCTEST:{ INSTRUCTION.eliteFxn = ADCTEST; - float ADCRealValue = 0; + int32_t ADCRealValue = 0; uint8_t CIS_buf[9] = {0}; CIS_buf[0] = chip_ID;