From 1e834cfb4547f8b9e0944a658ee042cbf5caffbc Mon Sep 17 00:00:00 2001 From: alan Date: Fri, 16 Aug 2019 16:40:09 +0800 Subject: [PATCH] Elite 1.4-re ADC current correction --- .../cc26xx/app/headstage/EliteDAC.h | 8 +- .../cc26xx/app/headstage/impedance_meter.h | 89 ++++++++----------- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h index 6753e3669..ea61f4b6a 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h @@ -58,11 +58,17 @@ static void DAC_outputV(uint16_t voltLV) { // User will enter -5V~+5V in UI. // websever and controler use 0~50000 represent -5~+5V // this function should turn 0~50000 into DACcode which output the exactly voltage user want -static uint16_t DACCorrectionDecode(uint16_t usercode){ +static uint16_t DACCorrectionDecode(uint16_t usercode) +{ // DACcode to real_voltage correction function + int32_t usercode_32; uint16_t DACcode = 0; + int16_t coeff = (-1054), offset = 60597718; + usercode_32 = (int32_t)(usercode); + + DACcode = (uint16_t) (coeff * usercode_32 + offset)/1000; return DACcode; } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h index de38a20f4..8ba8fddfc 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h @@ -129,21 +129,17 @@ static void VoltScan(){ DAC_outputV(VoltOrigin); // record the output voltage - float VoltValue; - int16_t decode = (int16_t)(ramp1 << 8) | (uint16_t)(ramp0); - int32_t Vout = 0; - VoltValue = decode * (-2.9780379) + 5920.324416; - Vout = (int32_t) (VoltValue / 1); -// VoltValue = (ramp1*16 + ramp0/16) * 3.05; - - NotifyVolt[0] = (uint8_t) (Vout >> 24) & (0xFF); - NotifyVolt[1] = (uint8_t) (Vout >> 16) & (0xFF); - NotifyVolt[2] = (uint8_t) (Vout >> 8) & (0xFF); - NotifyVolt[3] = (uint8_t) (Vout) & (0xFF); - - NotifyImpedance[1] = ramp0; - NotifyImpedance[2] = ramp1; - + /* + * int32_t RealVolt = 0; + * RealVolt = DACCode2RealVolt(VoltOrigin); + * + * NotifyVolt[0] = (uint8_t) (RealVolt >> 24); + * NotifyVolt[1] = (uint8_t) ((RealVolt & 0x00FF0000) >> 16); + * NotifyVolt[2] = (uint8_t) ((RealVolt & 0x0000FF00) >> 8); + * NotifyVolt[3] = (uint8_t) (RealVolt & 0x000000FF); + * + * SendNotify(); + */ PeriodicEvent = false; } else if (INSTRUCTION.eliteFxn == squarewavevoltammetry) { @@ -627,27 +623,18 @@ static void IVCurve_T(){ ramp = (int16_t)(ramp1 << 8) | (uint16_t)(ramp0); DAC_outputV(ramp); - // record the output voltage - int32_t Vout = 0; - int16_t decode = (int16_t)(ramp1 << 8) | (uint16_t)(ramp0); - VoltValue = decode * (-2.9780379) + 5920.324416; - Vout = (int32_t) (VoltValue / 1); - // VoltValue = (ramp1*16 + ramp0/16) * 3.05; - - - NotifyVolt[0] = (uint8_t) (Vout >> 24) & (0xFF); - NotifyVolt[1] = (uint8_t) (Vout >> 16) & (0xFF); - NotifyVolt[2] = (uint8_t) (Vout >> 8) & (0xFF); - NotifyVolt[3] = (uint8_t) (Vout) & (0xFF); - - NotifyImpedance[1] = ramp0; - NotifyImpedance[2] = ramp1; - - -// NotifyVolt[0] = VoltValue/1000; -// NotifyVolt[1] = VoltValue/100 - NotifyVolt[0]*10; -// NotifyVolt[2] = VoltValue/10 - NotifyVolt[0]*100 - NotifyVolt[1]*10; -// NotifyVolt[3] = VoltValue/1 - NotifyVolt[0]*1000 - NotifyVolt[1]*100 - NotifyVolt[2]*10; + // record the output voltage + /* + * int32_t RealVolt = 0; + * RealVolt = DACCode2RealVolt(ramp); + * + * NotifyVolt[0] = (uint8_t) (RealVolt >> 24); + * NotifyVolt[1] = (uint8_t) ((RealVolt & 0x00FF0000) >> 16); + * NotifyVolt[2] = (uint8_t) ((RealVolt & 0x0000FF00) >> 8); + * NotifyVolt[3] = (uint8_t) (RealVolt & 0x000000FF); + * + * SendNotify(); + */ // check if we reach the final volt ramp = ( (uint16_t) (ramp1)<<8 ) | ( (uint16_t) (ramp0) ); @@ -692,24 +679,18 @@ static void IVCurve_T2(){ ramp = (int16_t)(ramp1 << 8) | (uint16_t)(ramp0); DAC_outputV(ramp); - // record the output voltage - int32_t Vout = 0; - int16_t decode = (int16_t)(ramp1 << 8) | (uint16_t)(ramp0); - VoltValue = decode * (-2.9780379) + 5920.324416; - Vout = (int32_t) (VoltValue / 1); -// VoltValue = (ramp1*16 + ramp0/16) * 3.05; - - NotifyVolt[0] = (uint8_t) (Vout >> 24) & (0xFF); - NotifyVolt[1] = (uint8_t) (Vout >> 16) & (0xFF); - NotifyVolt[2] = (uint8_t) (Vout >> 8) & (0xFF); - NotifyVolt[3] = (uint8_t) (Vout) & (0xFF); - - NotifyImpedance[1] = ramp0; - NotifyImpedance[2] = ramp1; -// NotifyVolt[0] = VoltValue/1000; -// NotifyVolt[1] = VoltValue/100 - NotifyVolt[0]*10; -// NotifyVolt[2] = VoltValue/10 - NotifyVolt[0]*100 - NotifyVolt[1]*10; -// NotifyVolt[3] = VoltValue/1 - NotifyVolt[0]*1000 - NotifyVolt[1]*100 - NotifyVolt[2]*10; + // record the output voltage + /* + * int32_t RealVolt = 0; + * RealVolt = DACCode2RealVolt(ramp); + * + * NotifyVolt[0] = (uint8_t) (RealVolt >> 24); + * NotifyVolt[1] = (uint8_t) ((RealVolt & 0x00FF0000) >> 16); + * NotifyVolt[2] = (uint8_t) ((RealVolt & 0x0000FF00) >> 8); + * NotifyVolt[3] = (uint8_t) (RealVolt & 0x000000FF); + * + * SendNotify(); + */ // check if we reach the final volt ramp = ( (uint16_t) (ramp1)<<8 ) | ( (uint16_t) (ramp0) );