Merge branch 'Elite_ZTcurve' of https://gitlab.com/bioproscientific/bioprocc2650 into Elite_ZTcurve

This commit is contained in:
Benny Liu
2019-10-04 15:08:43 +08:00
7 changed files with 124 additions and 59 deletions
@@ -133,15 +133,13 @@ static uint16_t DPVCurve() {
}
static uint16_t CVCurve() {
static uint8_t ramp0;
static uint8_t ramp1;
static uint16_t outputV;
static uint16_t DACOutCode;
static bool direction_up;
static bool current_direction_up;
// reset origin volt at the begin
if (DACReset) {
outputV = INSTRUCTION.VoltOrigin;
DACUserCode = INSTRUCTION.VoltOrigin;
if (INSTRUCTION.VoltFinal > INSTRUCTION.VoltOrigin) {
direction_up = true;
current_direction_up = true;
@@ -149,51 +147,98 @@ static uint16_t CVCurve() {
direction_up = false;
current_direction_up = false;
}
ramp0 = (uint8_t)(INSTRUCTION.VoltOrigin & 0x00FF); // right byte
ramp1 = (uint8_t)((INSTRUCTION.VoltOrigin >> 8) & 0x00FF); // left byte
DACReset = false;
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
DAC_outputV(DACOutCode); // output VOLT_ORIGIN
DACReset = false;
return DACOutCode;
}
// output a certain volt
DAC_outputV(outputV);
if (StepTimeCounter == INSTRUCTION.StepTime) {
if (direction_up) {
if (outputV >= INSTRUCTION.VoltFinal) {
current_direction_up = false; // problem occurs when origin == 0000 final == ffff!!!!!!
} else if (outputV <= INSTRUCTION.VoltOrigin) {
current_direction_up = true;
if (INSTRUCTION.CycleNumber == 0) {
PeriodicEvent = false; // periodic event end
DACReset = true;
// Next direction
if (direction_up) {
if (DACUserCode >= INSTRUCTION.VoltFinal) {
current_direction_up = false; // problem occurs when origin == 0000 final == ffff!!!!!!
} else if (DACUserCode <= INSTRUCTION.VoltOrigin) {
current_direction_up = true;
if (INSTRUCTION.CycleNumber == 0) {
PeriodicEvent = false; // periodic event end
DACReset = true;
}
INSTRUCTION.CycleNumber--;
}
INSTRUCTION.CycleNumber--;
}
} else {
if (outputV <= INSTRUCTION.VoltFinal) {
current_direction_up = true; // problem occurs when origin == 0000 final == ffff!!!!!!
} else if (outputV >= INSTRUCTION.VoltOrigin) {
current_direction_up = false;
if (INSTRUCTION.CycleNumber == 0) {
PeriodicEvent = false; // periodic event end
DACReset = true;
} else {
if (DACUserCode <= INSTRUCTION.VoltFinal) {
current_direction_up = true; // problem occurs when origin == 0000 final == ffff!!!!!!
} else if (DACUserCode >= INSTRUCTION.VoltOrigin) {
current_direction_up = false;
if (INSTRUCTION.CycleNumber == 0) {
PeriodicEvent = false; // periodic event end
DACReset = true;
}
INSTRUCTION.CycleNumber--;
}
INSTRUCTION.CycleNumber--;
}
}
if (current_direction_up) {
if (outputV + INSTRUCTION.Step < outputV)
outputV = 0xffff;
else
outputV = outputV + INSTRUCTION.Step;
} else {
if (outputV - INSTRUCTION.Step > outputV)
outputV = 0x0000;
else
outputV = outputV - INSTRUCTION.Step;
}
// Next output voltage
if (direction_up) {
if (current_direction_up) {
if (DACUserCode + INSTRUCTION.Step < DACUserCode) {
DACUserCode = 0xffff;
}
else if (DACUserCode + INSTRUCTION.Step > INSTRUCTION.VoltFinal) {
DACUserCode = INSTRUCTION.VoltFinal;
}
else {
DACUserCode = DACUserCode + INSTRUCTION.Step;
}
}
else {
if (DACUserCode - INSTRUCTION.Step > DACUserCode) {
DACUserCode = 0x0000;
}
else if (DACUserCode + INSTRUCTION.Step < INSTRUCTION.VoltOrigin) {
DACUserCode = INSTRUCTION.VoltOrigin;
}
else {
DACUserCode = DACUserCode - INSTRUCTION.Step;
}
}
}
else {
if (current_direction_up) {
if (DACUserCode + INSTRUCTION.Step < DACUserCode) {
DACUserCode = 0xffff;
}
else if (DACUserCode + INSTRUCTION.Step > INSTRUCTION.VoltOrigin) {
DACUserCode = INSTRUCTION.VoltOrigin;
}
else {
DACUserCode = DACUserCode + INSTRUCTION.Step;
}
}
else {
if (DACUserCode - INSTRUCTION.Step > DACUserCode) {
DACUserCode = 0x0000;
}
else if (DACUserCode + INSTRUCTION.Step < INSTRUCTION.VoltFinal) {
DACUserCode = INSTRUCTION.VoltFinal;
}
else {
DACUserCode = DACUserCode - INSTRUCTION.Step;
}
}
}
return outputV;
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
DAC_outputV(DACOutCode);
}
return DACOutCode;
}
#endif
@@ -447,7 +447,7 @@ 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) {
if ( (INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
ADCRealCurrent_long += DecodeADCCurrent(ADCGain, ADC_measure);
avg_number++;
@@ -13,7 +13,7 @@ static uint16_t VoltScan() {
Voltage = SWVCurve();
} else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) {
Voltage = DPVCurve();
} else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) {
} else if (INSTRUCTION.eliteFxn == CV_CURVE) {
Voltage = CVCurve();
}
@@ -29,7 +29,7 @@ static void WorkModeLED() {
WORKLED();
break;
}
case CYCLIC_VOLTAMMETRY: {
case CV_CURVE: {
WORKLED();
break;
}
@@ -82,7 +82,7 @@ static void KeyWorkModeLED() {
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case CYCLIC_VOLTAMMETRY:{
case CV_CURVE:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
@@ -30,6 +30,8 @@ static void ZT_Plot() {
}
ADCGainControl(INSTRUCTION.ADCGainLevel);
// Use 9-th measure value as real-measure value
// because some value in the begin are garbage
if(VoltCurrentSwitch < 9){
ADCChannelSelect(ADC_CH_CURRENT);
CPUdelay(10);
@@ -579,7 +579,7 @@ static void set_update_instruction_callback(update_instruction_callback_type cal
// real instruction
#define IV_CURVE 0b00010000
#define CYCLIC_VOLTAMMETRY 0b00100000
#define CV_CURVE 0b00100000
#define VOLT_OUTPUT 0b00110000
#define ZT_CURVE 0b01000000
#define VT_CURVE 0b01010000
@@ -801,18 +801,18 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case CYCLIC_VOLTAMMETRY: {
case CV_CURVE: {
CleanBuffer();
INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY;
INSTRUCTION.eliteFxn = CV_CURVE;
DACReset = true;
if (ins[3] | ins[4]) {
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
// INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
}
if (ins[5] | ins[6]) {
INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
// INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
}
if (ins[7] | ins[8]) {
@@ -830,6 +830,7 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case VOLT_OUTPUT: {
INSTRUCTION.eliteFxn = VOLT_OUTPUT;
INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
@@ -902,15 +903,27 @@ static void update_ZM_instruction(uint8 *ins) {
int32_t ADCRealValue = 0;
uint8_t CIS_buf[9] = {0};
ADCGainControl(ins[3]);
ADCChannelSelect(ins[4]);
CPUdelay(1600);
ADC_read(spi_ADC_rxbuf);
uint16_t ADCValueTemp = 0;
uint32_t ADCValueAVG = 0;
for(int i=0 ; i<10 ; i++){
ADCGainControl(ins[3]);
ADCChannelSelect(ins[4]);
CPUdelay(10);
ADC_read(spi_ADC_rxbuf);
CPUdelay(10);
ADCValueTemp = spi_ADC_rxbuf[0] << 8 | spi_ADC_rxbuf[1];
ADCValueAVG = ADCValueAVG + ADCValueTemp;
}
ADCValueAVG = ADCValueAVG / 10;
ADCValueTemp = (uint16_t) (ADCValueAVG);
CIS_buf[0] = chip_ID;
for (int i = 0; i < 4; i++) {
CIS_buf[i + 1] = spi_ADC_rxbuf[i];
}
CIS_buf[1] = (uint8_t) (ADCValueTemp & 0xFF00 >> 8);
CIS_buf[2] = (uint8_t) (ADCValueTemp & 0x00FF);
CIS_buf[3] = spi_ADC_rxbuf[2];
CIS_buf[4] = spi_ADC_rxbuf[3];
// decode ADC measure value
ADCRealValue = DecodeADCValue(ins[3], ins[4], spi_ADC_rxbuf);
@@ -72,6 +72,7 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
#define IsPeriodicMode() ( \
(INSTRUCTION.eliteFxn == IV_CURVE) || \
(INSTRUCTION.eliteFxn == CV_CURVE) || \
(INSTRUCTION.eliteFxn == IT_CURVE) || \
(INSTRUCTION.eliteFxn == VT_CURVE) || \
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
@@ -122,7 +123,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(CURRENT_USER_CODE *CurrentUs
}
static void EliteDACControl(CURRENT_USER_CODE *CurrentUserCode) {
if (INSTRUCTION.eliteFxn == IV_CURVE) {
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
// output a certain voltage and put it into NotifyVolt
DACCode2Real2Notify(VoltScan());
}
@@ -156,6 +157,10 @@ static void EliteADCControl(CURRENT_USER_CODE *CurrentUserCode) {
IT_Plot();
break;
}
case CV_CURVE:{
IT_Plot();
break;
}
case IT_CURVE:{
IT_Plot();
break;
@@ -181,7 +186,7 @@ static void EliteADCControl(CURRENT_USER_CODE *CurrentUserCode) {
}
static void EliteNotifyControl() {
if ((INSTRUCTION.eliteFxn == IV_CURVE)) {
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
// output the last notify, and reset Elite
if (!PeriodicEvent) {
SendNotify();