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 3656959e0..7e93ea16d 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 @@ -560,84 +560,8 @@ static void SWVCurve(){ } } -/* -//working DPV curve -static void DPVCurve(){ - - static uint8_t ramp0; - static uint8_t ramp1; - static uint16_t outputV; - static uint8_t counter; - static bool direction_up; - static bool current_direction_up; - float VoltValue; - - // reset origin volt at the begin - if (DACreset){ - outputV = VoltOrigin; - if (VoltFinal > VoltOrigin ) { - direction_up = true; - current_direction_up = true; - } - else { - direction_up = false; - current_direction_up = false; - } - ramp0 = (uint8_t) (VoltOrigin & 0x00FF); //right byte - ramp1 = (uint8_t) ((VoltOrigin>>8) & 0x00FF); //left byte - DACreset = false; - - } - - // output a certain volt - DAC_outputV(outputV); - - 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; - - if (direction_up) { - if (outputV >= VoltFinal) { - current_direction_up = false; //problem occurs when origin == 0000 final == ffff!!!!!! - } - else if (outputV <= VoltOrigin) { - current_direction_up = true; - if (INSTRUCTION.CycleNumber == 0) { - PeriodicEvent = false; //periodic event end - DACreset = true; - return; - } - INSTRUCTION.CycleNumber--; - } - } - else { - if (outputV <= VoltFinal) { - current_direction_up = true; //problem occurs when origin == 0000 final == ffff!!!!!! - } - else if (outputV >= VoltOrigin) { - current_direction_up = false; - if (INSTRUCTION.CycleNumber == 0) { - PeriodicEvent = false; //periodic event end - DACreset = true; - return; - } - INSTRUCTION.CycleNumber--; - } - - } - - - - if(current_direction_up) outputV = outputV + Amplitude; - else outputV = outputV - Amplitude; - - - -} -*/ +/* static void DPVCurve(){ static uint8_t counter; static uint16_t Volt1; @@ -698,6 +622,63 @@ static void DPVCurve(){ else Volt2 = Volt2 - Step; } +} +*/ +static void DPVCurve(){ + static uint8_t counter; + static uint16_t Volt1; + static uint16_t Volt2; + static uint16_t outputV; + static bool direction_up; + float VoltValue; + + // reset origin volt at the begin + if (DACreset){ + + if ( VoltOrigin < VoltFinal ) direction_up = true; + else direction_up = false; + + Volt1 = VoltOrigin; + if (direction_up) Volt2 = VoltOrigin + Amplitude; + else Volt2 = VoltOrigin - Amplitude; + + counter = 1; + DACreset = false; + } + + if(counter == PulsePeriod) counter = 1; + else counter ++; + + // output a certain volt + if( counter <= (PulsePeriod - PulseWidth)) outputV = Volt1; + else outputV = Volt2; + + DAC_outputV(Volt1); + + // record the output voltage + int32_t Vout = 0; + int16_t decode = outputV; + VoltValue = decode * (-2.9780379) + 5920.324416; + Vout = (int32_t) (VoltValue / 1); + // VoltValue = (ramp1*16 + ramp0/16) * 3.05; + + + // check if we reach the final volt + /* + if ( (( outputV >= VoltFinal) && direction_up ) || (( outputV <= VoltFinal) && !direction_up)) { + PeriodicEvent = false; + DACreset = true; + return; + }*/ + + //check overflow/underflow and prepare for next output + if (direction_up) { + Volt1 = Volt1 + Amplitude; + } + else { + Volt1 = Volt1 - Amplitude; + } + }