Compare commits

...

12 Commits

Author SHA1 Message Date
yichin a64d596e7f test 2020-01-10 18:10:35 +08:00
105042004 e98f387c82 change pulse period 2020-01-10 17:17:35 +08:00
105042004 c9bbc1aab1 test SCC 2020-01-10 17:02:10 +08:00
yichin 9e4bb038e8 testing SAC 2019-12-27 19:20:50 +08:00
105042004 ce5c87fcf7 create Square Current mode 2019-12-27 17:40:34 +08:00
royluo 78d788cab2 IV and CV mode with Vout version 2019-12-20 12:13:22 +08:00
royluo 02185083f5 Merge remote-tracking branch 'origin/Elite_OBJ_Version' into Elite_OBJ_Version 2019-12-20 12:06:34 +08:00
royluo aeca114c5f IV and CV mode with Vin version
(add ReadVout)
2019-12-20 12:04:59 +08:00
Benny Liu 7b4f2b5828 update BOARD_KUMA & BOARD_MINO calibration data. 2019-12-20 12:04:16 +08:00
YiChin 7b075f40a3 BOARD_KUMA & BOARD_MINO calibration data 2019-12-19 15:55:00 +08:00
yichin 6c68c67f0e annotation test CVcurve use led 2019-12-19 12:50:43 +08:00
Benny Liu fd9f0ef321 upload BOARD_BIGBROTHER calibration data 2019-12-17 19:01:30 +08:00
12 changed files with 8268 additions and 36 deletions
@@ -137,6 +137,17 @@ static void ReadVolt(uint8_t *buf){
ADC_read(buf);
}
static void ReadVoutVolt(uint8_t *buf){
// Read data twice since the first data we get is previous data
ADCChannelSelect(ADC_CH_DAC);
CPUdelay(10);
ADC_read(buf);
ADCChannelSelect(ADC_CH_DAC);
CPUdelay(10);
ADC_read(buf);
}
static void ReadCurrent(uint8_t *buf){
// Read data twice since the first data we get is previous data
ADCGainControl(INSTRUCTION.ADCGainLevel);
@@ -156,7 +156,6 @@ static uint16_t CVCurve(CVMode *CV) {
}
if (CT.StepTimeCounter == CV->_StepTime) {
// Decide next direction
if (CV->_VoVi_Switch == 0x00){ //user see Vout
if (direction_up) {
@@ -208,12 +207,12 @@ static uint16_t CVCurve(CVMode *CV) {
}
}
}
if (current_direction_up == true){
LED_color(DARKLED, 255, 0, 0);
}
else if (current_direction_up == false){
LED_color(DARKLED, 255, 0, 255);
}
// if (current_direction_up == true){
// LED_color(DARKLED, 255, 0, 0);
// }
// else if (current_direction_up == false){
// LED_color(DARKLED, 255, 0, 255);
// }
// Next output voltage
if (CV->_VoVi_Switch == 0x00){
@@ -365,17 +364,42 @@ static void CV_Plot(CVMode *CV){
}
VoltCurrentSwitch ++;
}
// else if(VoltCurrentSwitch < 9){
// // read volt
// ReadVolt(spi_ADC_rxbuf);
// VoltCurrentSwitch++;
// }
// else if(VoltCurrentSwitch == 9){
// /** read battery voltage **/
// ReadVolt(spi_ADC_rxbuf);
// ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// //CV->MeasureVolt = 20000;
// CV->MeasureVolt = DecodeADCVolt(ADC_measure);
// VoltCurrentSwitch++;
// }
else if(VoltCurrentSwitch < 9){
// read volt
ReadVolt(spi_ADC_rxbuf);
if(CV->_VoVi_Switch == 0x01){
// read volt
ReadVolt(spi_ADC_rxbuf);
}else if(CV->_VoVi_Switch == 0x00){
// read vout volt
ReadVoutVolt(spi_ADC_rxbuf);
}
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 9){
/** read battery voltage **/
ReadVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
//CV->MeasureVolt = 20000;
CV->MeasureVolt = DecodeADCVolt(ADC_measure);
if(CV->_VoVi_Switch == 0x01){
/** read battery voltage **/
ReadVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
//CV->MeasureVolt = 20000;
CV->MeasureVolt = DecodeADCVolt(ADC_measure);
}else if(CV->_VoVi_Switch == 0x00){
/** read vout voltage **/
ReadVoutVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
CV->MeasureVolt = DecodeADCVoutVolt(ADC_measure);
}
VoltCurrentSwitch++;
}
else{
@@ -387,7 +411,7 @@ static void CV_Plot(CVMode *CV){
NotifyCurrent[2] = (uint8_t) ((CV->_MeasureData & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t) (CV->_MeasureData & 0x000000FF);
if (CV->_VoVi_Switch == 0x01){ //user see Vin
if ((CV->_VoVi_Switch == 0x01) || (CV->_VoVi_Switch == 0x00)){ //user see Vin || user see Vout
NotifyVolt[0] = (uint8_t) (CV->MeasureVolt >> 24);
NotifyVolt[1] = (uint8_t) ((CV->MeasureVolt & 0x00FF0000) >> 16);
NotifyVolt[2] = (uint8_t) ((CV->MeasureVolt & 0x0000FF00) >> 8);
@@ -29,7 +29,7 @@
*/
#define BOARD_SATURN
#define BOARD_KUMA
typedef struct _formula{
@@ -731,6 +731,91 @@ struct _correction{
};
#endif
#ifdef BOARD_BIGBROTHER
{
.ADC_volt.coeff = (-6249254),
.ADC_volt.offset = 101825967151,
.ADC_current[0].coeff = 31064047,
.ADC_current[0].offset = -506320666330,
.ADC_current[1].coeff = 656820055,
.ADC_current[1].offset = -10700912340162,
.ADC_current[2].coeff = 31424358846,
.ADC_current[2].offset = -511986603889918,
.DAC2RealV.coeff = (-19007867),
.DAC2RealV.offset = 646316924837,
.Usercode2DAC.coeff = (-10484132),
.Usercode2DAC.offset = 559642619397,
.Gain0Boundary[0] = 0x5ECD,
.Gain0Boundary[1] = 0x5F0D,
.Gain1Boundary[0] = 0x5900,
.Gain1Boundary[1] = 0x64DD
};
#endif
#ifdef BOARD_KUMA
{
.ADC_volt.coeff = (-6284116),
.ADC_volt.offset = 102151354839,
.ADC_current[0].coeff = 31222344,
.ADC_current[0].offset = -507425541248,
.ADC_current[1].coeff = 657422161,
.ADC_current[1].offset = -10654143756362,
.ADC_current[2].coeff = 31221776879,
.ADC_current[2].offset = -506123984398184,
.DAC2RealV.coeff = (-19007867),
.DAC2RealV.offset = 646316924837,
.Usercode2DAC.coeff = (-10541828),
.Usercode2DAC.offset = 559483550210,
.Gain0Boundary[0] = 0x5ECD,
.Gain0Boundary[1] = 0x5F0D,
.Gain1Boundary[0] = 0x5900,
.Gain1Boundary[1] = 0x64DD
};
#endif
#ifdef BOARD_MINO
{
.ADC_volt.coeff = (-6242774),
.ADC_volt.offset = 101201319007,
.ADC_current[0].coeff = 31322380,
.ADC_current[0].offset = -507484324313,
.ADC_current[1].coeff = 659514123,
.ADC_current[1].offset = -10687831492393,
.ADC_current[2].coeff = 31535570993,
.ADC_current[2].offset = -511116189463173,
.DAC2RealV.coeff = (-19007867),
.DAC2RealV.offset = 646316924837,
.Usercode2DAC.coeff = (-10529707),
.Usercode2DAC.offset = 560289198229,
.Gain0Boundary[0] = 0x5ECD,
.Gain0Boundary[1] = 0x5F0D,
.Gain1Boundary[0] = 0x5900,
.Gain1Boundary[1] = 0x64DD
};
#endif
// this function turn ADC measure value (0xXXXX) into real voltage
// unit should be mV
static int32_t DecodeADCVolt(uint16_t ADC_measure){
@@ -742,6 +827,16 @@ static int32_t DecodeADCVolt(uint16_t ADC_measure){
return (int32_t) (ADCRealVolt);
}
// this function turn ADC measure value (0xXXXX) into Vout voltage
// unit should be mV
static int32_t DecodeADCVoutVolt(uint16_t ADC_measure){
long long ADCVoutVolt = 0;
ADCVoutVolt = ((-62658782380) * ADC_measure + 1020118014900000);
ADCVoutVolt = ADCVoutVolt / 1e11;
return (int32_t) (ADCVoutVolt);
}
// this function turn ADC measure value (0xXXXX) into real current
// unit should be pA
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
@@ -798,7 +893,8 @@ static int32_t DecodeResister(uint8_t ADCGainLevel, uint16_t CurrentMeasure, uin
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]);
int32_t ADCRealVolt = 0, ret = 0, ADCRealCurrent = 0;
int32_t ADCRealVolt = 0, ret = 0, ADCRealCurrent = 0, ADCVoutVolt = 0;;
// return real volt to controller
if(ADCChannel == ADC_CH_VOLT){
@@ -816,6 +912,13 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
ret = ADCRealCurrent;
}
// return real TestVolt to controller
else if(ADCChannel == ADC_CH_DAC){
ADCVoutVolt = DecodeADCVoutVolt(ADC_measure);
ret = ADCVoutVolt;
}
// 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
@@ -15,6 +15,8 @@ static uint16_t VoltScan(WorkMode *WorkModeData) {
Voltage = DPVCurve(WorkModeData);
} else if (INSTRUCTION.eliteFxn == CV_CURVE) {
Voltage = CVCurve(WorkModeData->CV);
} else if (INSTRUCTION.eliteFxn == SQUARE_CURR) {
Voltage = SCCurve(WorkModeData->SC);
}
// IV plot mode
@@ -45,7 +47,7 @@ static uint16_t OneWayVoltScan(IVMode *IV) {
// output the next output volt
INSTRUCTION.VoltConstant = INSTRUCTION.VoltConstant + IV->_Step;
// Only used in two-wire IV
// if(INSTRUCTION.VoltConstant > IV->_VStop){
// if(INSTRUCTION.VosltConstant > IV->_VStop){
// INSTRUCTION.VoltConstant = IV->_VStop;
// }
@@ -134,16 +136,40 @@ static void IV_Plot(IVMode *IV) {
}
VoltCurrentSwitch ++;
}
// else if(VoltCurrentSwitch < 9){
// // read volt
// ReadVolt(spi_ADC_rxbuf);
// VoltCurrentSwitch++;
// }
// else if(VoltCurrentSwitch == 9){
// /** read battery voltage **/
// ReadVolt(spi_ADC_rxbuf);
// ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// IV->MeasureVolt = DecodeADCVolt(ADC_measure);
// VoltCurrentSwitch++;
// }
else if(VoltCurrentSwitch < 9){
// read volt
ReadVolt(spi_ADC_rxbuf);
if(IV->_VoVi_Switch == 0x01){
// read volt
ReadVolt(spi_ADC_rxbuf);
}else if(IV->_VoVi_Switch == 0x00){
// read vout volt
ReadVoutVolt(spi_ADC_rxbuf);
}
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 9){
/** read battery voltage **/
ReadVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
IV->MeasureVolt = DecodeADCVolt(ADC_measure);
if(IV->_VoVi_Switch == 0x01){
/** read battery voltage **/
ReadVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
IV->MeasureVolt = DecodeADCVolt(ADC_measure);
}else if(IV->_VoVi_Switch == 0x00){
/** read vout voltage **/
ReadVoutVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
IV->MeasureVolt = DecodeADCVoutVolt(ADC_measure);
}
VoltCurrentSwitch++;
}
else{
@@ -157,7 +183,7 @@ static void IV_Plot(IVMode *IV) {
NotifyCurrent[2] = (uint8_t) ((IV->_MeasureData & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t) (IV->_MeasureData & 0x000000FF);
if (IV->_VoVi_Switch == 0x01){ //user see Vin
if((IV->_VoVi_Switch == 0x01) || (IV->_VoVi_Switch == 0x00)){ //user see Vin || user see Vout
NotifyVolt[0] = (uint8_t) (IV->MeasureVolt >> 24);
NotifyVolt[1] = (uint8_t) ((IV->MeasureVolt & 0x00FF0000) >> 16);
NotifyVolt[2] = (uint8_t) ((IV->MeasureVolt & 0x0000FF00) >> 8);
@@ -176,7 +202,6 @@ static void IV_Plot(IVMode *IV) {
}
}
}
}
@@ -22,6 +22,7 @@
/* DAC reset parameter */
#define DAC_ZERO 25000
#define DAC_ONEV 30000
#define DAC_POS_MAX 0x0000
#define DAC_NEG_MAX 0xFFFF
@@ -77,6 +78,10 @@ struct HEADSTAGE_INSTRUCTION {
uint8_t VoVi_Switch;
// Square current curve
uint16_t Pulse_Period;
uint16_t Pulse_Length;
} INSTRUCTION = {0};
/*********************************************************************
@@ -69,6 +69,10 @@ static void WorkModeLED() {
WORKLED();
break;
}
case READ_VOUT_VALUE: {
WORKLED();
break;
}
default: {
LEDPowerON();
@@ -0,0 +1,22 @@
#ifndef ELITERVout
#define ELITERVout
static void RVout_Plot(RVoutMode *RVout) {
// ADC gain is don't care when measuring voltage
INSTRUCTION.ADCGainLevel = GAIN_200R;
ADCGainControl(INSTRUCTION.ADCGainLevel);
// read ADC VoutVolt
ReadVoutVolt(spi_ADC_rxbuf);
// decode ADC value and put it into notify buffer
RVout->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
NotifyVolt[0] = (uint8_t) (RVout->_MeasureData >> 24);
NotifyVolt[1] = (uint8_t) ((RVout->_MeasureData & 0x00FF0000) >> 16);
NotifyVolt[2] = (uint8_t) ((RVout->_MeasureData & 0x0000FF00) >> 8);
NotifyVolt[3] = (uint8_t) (RVout->_MeasureData & 0x000000FF);
}
#endif
@@ -0,0 +1,167 @@
#ifndef ELITESC
#define ELITESC
static uint16_t SCCurve(SCMode *SC) {
static uint16_t DACOutCode;
static bool direction_up; // direction_up = true, if Vfinal > Vorigin
static bool current_direction_up; // current_direction_up = true, Vstep => positive. vice versa
// reset origin volt at the begin
if (DACReset) {
DACUserCode = SC->_VOrigin;
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
DAC_outputV(DACOutCode); // output VOLT_ORIGIN
DACReset = false;
return DACOutCode;
}
if (CT.StepTimeCounter == SC->_StepTime) {
// if (CT.PulseLength_counter < SC->_pulsePeriod) {
// if (SC->_MeasureData < (1e8 - SC->_Step)){ // SC->_MeasureData == 1e8 => 0.1mA
// SC->_VStop += SC->_Step;
// }
// else if (SC->_MeasureData > (1e8 + SC->_Step)){
// SC->_VStop -= SC->_Step;
// }
//
// DACUserCode = SC->_VStop;
// }
// else if (CT.PulseLength_counter < SC->_pulseLength) {
// if (SC->_MeasureData < (0 - SC->_Step)){ // SC->_MeasureData == 0 => 0mA
// SC->_VOrigin += SC->_Step;
// }
// else if (SC->_MeasureData > (0 + SC->_Step)){
// SC->_VOrigin -= SC->_Step;
// }
//
// DACUserCode = SC->_VOrigin;
// }
//
//
// SC->_CycleNumber--;
// if (SC->_CycleNumber == 0){
// PeriodicEvent = false; // periodic event end
// DACReset = true;
// }
if (CT.PulseLength_counter < SC->_pulsePeriod) {
//if (SC->_MeasureData > 1e10){
//LED_color(DARKLED, 255, 0, 0); // red when _MeasureData is larger than 10mA
//}
DACUserCode = SC->_VOrigin;
}
else if (CT.PulseLength_counter < SC->_pulseLength) {
//if (SC->_MeasureData > 1e10){
//LED_color(DARKLED, 0, 0, 255); // blue when _MeasureData is larger than 10mA
//}
DACUserCode = SC->_VStop;
}
if (CT.PulseLength_counter == 1 ) SC->_CycleNumber--;
if (SC->_CycleNumber == 0){
PeriodicEvent = false; // periodic event end
DACReset = true;
}
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
DAC_outputV(DACOutCode);
}
return DACOutCode;
}
static void SC_Plot(SCMode *SC){
static uint8_t PreviousGain = GAIN_200R;
static uint8_t VoltCurrentSwitch = 0;
uint16_t ADC_measure = 0;
if(VoltCurrentSwitch < 5){
ReadCurrent(spi_ADC_rxbuf);
VoltCurrentSwitch ++;
}
else if(VoltCurrentSwitch == 5){
// read current
if(INSTRUCTION.AutoGainEnable){
SC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
if(PreviousGain != INSTRUCTION.ADCGainLevel){
PreviousGain = INSTRUCTION.ADCGainLevel;
SC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
SC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
}
if(PreviousGain != INSTRUCTION.ADCGainLevel){
PreviousGain = INSTRUCTION.ADCGainLevel;
SC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
SC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
}
}
else{
ReadCurrent(spi_ADC_rxbuf);
SC->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
VoltCurrentSwitch ++;
}
// else if(VoltCurrentSwitch < 9){
// // read volt
// ReadVolt(spi_ADC_rxbuf);
// VoltCurrentSwitch++;
// }
// else if(VoltCurrentSwitch == 9){
// /** read battery voltage **/
// ReadVolt(spi_ADC_rxbuf);
// ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// //SC->MeasureVolt = 20000;
// SC->MeasureVolt = DecodeADSColt(ADC_measure);
// VoltCurrentSwitch++;
// }
else if(VoltCurrentSwitch < 9){
if(SC->_VoVi_Switch == 0x01){
// read volt
ReadVolt(spi_ADC_rxbuf);
}else if(SC->_VoVi_Switch == 0x00){
// read vout volt
ReadVoutVolt(spi_ADC_rxbuf);
}
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 9){
if(SC->_VoVi_Switch == 0x01){
/** read battery voltage **/
ReadVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
//SC->MeasureVolt = 20000;
SC->MeasureVolt = DecodeADCVolt(ADC_measure);
}else if(SC->_VoVi_Switch == 0x00){
/** read vout voltage **/
ReadVoutVolt(spi_ADC_rxbuf);
ADC_measure = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
SC->MeasureVolt = DecodeADCVoutVolt(ADC_measure);
}
VoltCurrentSwitch++;
}
else{
VoltCurrentSwitch = 0;
}
NotifyCurrent[0] = (uint8_t) (SC->_MeasureData >> 24);
NotifyCurrent[1] = (uint8_t) ((SC->_MeasureData & 0x00FF0000) >> 16);
NotifyCurrent[2] = (uint8_t) ((SC->_MeasureData & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t) (SC->_MeasureData & 0x000000FF);
if ((SC->_VoVi_Switch == 0x01) || (SC->_VoVi_Switch == 0x00)){ //user see Vin || user see Vout
NotifyVolt[0] = (uint8_t) (SC->MeasureVolt >> 24);
NotifyVolt[1] = (uint8_t) ((SC->MeasureVolt & 0x00FF0000) >> 16);
NotifyVolt[2] = (uint8_t) ((SC->MeasureVolt & 0x0000FF00) >> 8);
NotifyVolt[3] = (uint8_t) (SC->MeasureVolt & 0x000000FF);
}
}
#endif
@@ -39,7 +39,7 @@
#define ELITE_WORK_DATA
#include "EliteInstruction.h"
#define IV_CURVE 0b00010000
#define IV_CURVE 0b11110001
#define CV_CURVE 0b00100000
#define VOLT_OUTPUT 0b00110000
#define ZT_CURVE 0b01000000
@@ -51,7 +51,8 @@
#define SQUARE_WAVE_VOLTAMMETRY 0b10110000
#define POTENTIAL_STATE 0b11000000
#define CONSTANT_CURRENT 0b11010000
#define SET_RESISTER_LEVEL 0b11100000
#define READ_VOUT_VALUE 0b11100000
#define SQUARE_CURR 0b00010000
static bool Free_Work_Mode = false;
typedef void (*InitWorkData) ();
@@ -189,6 +190,20 @@ VTMode * InitVTMode(){
return ret;
}
/* End of VT Mode Data */
/* ReadVOut Mode Data */
typedef struct _RVoutMode{
MEASURE;
}RVoutMode;
RVoutMode * InitTVMode(){
RVoutMode *ret = malloc(sizeof(RVoutMode));
ret->_MeasureData = 0;
// ret->SetMeasureData = &_SetMeasureData;
// ret->GetMeasureData = &_GetMeasureData;
return ret;
}
/* End of ReadVOut Mode Data */
/***** End of Measure Only Mode *****/
@@ -391,6 +406,67 @@ CVMode * InitCVMode(){
}
/*End of CV Mode*/
/* SC Mode Data */ // SC mode => Square Current Mode
typedef struct _SCMode{
MEASURE;
int32_t MeasureVolt;
VOUT_PARA;
LIMIT;
uint16_t _pulseLength;
uint16_t _pulsePeriod;
}SCMode;
SCMode *InitSCMode(){
SCMode *ret = malloc(sizeof(SCMode));
ret->_MeasureData = 0;
ret->MeasureVolt = (INSTRUCTION.VoltOrigin - DAC_ZERO)/5;
// ret->_VoltOut = DAC_ZERO;
// ret->_VOrigin = DAC_ZERO;
// ret->_VStop = DAC_ONEV;;
// ret->_Step = 500; // approximately 10mV
// ret->_CycleNumber = 10;
// // ret->_StepTime = INSTRUCTION.StepTime;
// // ret->_pulseLength = INSTRUCTION.Pulse_Length; // this is pulse length, should be STEPTIME_ONE_SEC/10 or STEPTIME_ONE_SEC
// // ret->_pulsePeriod = INSTRUCTION.Pulse_Period; // this is pulse period, should be STEPTIME_ONE_SEC/100 or STEPTIME_ONE_SEC/10
//
// ret->_pulseLength = STEPTIME_ONE_SEC / 10; // this is pulse length, should be STEPTIME_ONE_SEC/10 or STEPTIME_ONE_SEC
// ret->_pulsePeriod = STEPTIME_ONE_SEC / 100; // this is pulse period, should be STEPTIME_ONE_SEC/100 or STEPTIME_ONE_SEC/10
// ret->_StepTime = STEPTIME_ONE_SEC / 1000;
//
ret->_VOrigin = INSTRUCTION.VoltOrigin;
ret->_VStop = INSTRUCTION.VoltFinal;;
ret->_Step = INSTRUCTION.Step; // approximately 10mV
ret->_CycleNumber = 100;
ret->_StepTime = INSTRUCTION.StepTime;
ret->_pulsePeriod = INSTRUCTION.Pulse_Period; // this is pulse period, should be STEPTIME_ONE_SEC/100 or STEPTIME_ONE_SEC/10
ret->_pulseLength = INSTRUCTION.Pulse_Length; // this is pulse length, should be STEPTIME_ONE_SEC/10 or STEPTIME_ONE_SEC
// ret->SetVoltOut = &_SetVoltOut;
// ret->GetVoltOut = &_GetVoltOut;
// ret->SetVOrigin = &_SetVOrigin;
// ret->GetVOrigin = &_GetVOrigin;
// ret->SetVStop = &_SetVStop;
// ret->GetVStop = &_GetVStop;
// ret->SetStep = &_SetStep;
// ret->GetStep = &_GetStep;
// ret->SetStepTime = &_SetStepTime;
// ret->GetStepTime = &_GetStepTime;
// ret->SetCycleNumber = &_SetCycleNumber;
// ret->GetCycleNumber = &_GetCycleNumber;
ret->_LimitValue = 1e5;
ret->SetLimitValue = &_SetLimitValue;
ret->GetLimitValue = &_GetLimitValue;
return ret;
}
/* End of SC Mode Data */
/* Const Current Mode */
#define CC_ZERO_POINT 0
#define MAX_DAC_UC 50000
@@ -520,8 +596,11 @@ typedef union _WorkMode{
CVMode *CV;
RTMode *RT;
CCMode *CC;
SCMode *SC;
// CCCMode *CCC;
PSMode *PS;
RVoutMode *RVout;
}WorkMode;
WorkMode *CreateWorkMode(){
@@ -555,6 +634,12 @@ void InitWorkMode(WorkMode *WM){
// case CYCLE_CONSTANT_CURRENT:
// WM->CCC = InitCCCMode();
// break;
case READ_VOUT_VALUE:
WM->RVout = InitTVMode();
break;
case SQUARE_CURR:
WM->SC = InitSCMode();
break;
default:
WM->VT = InitVTMode();
break;
@@ -605,6 +690,18 @@ void FreeWorkMode(WorkMode *WM){
WM->CC = NULL;
}
break;
case READ_VOUT_VALUE:
if(WM->RVout != NULL){
free(WM->RVout);
WM->RVout = NULL;
}
break;
case SQUARE_CURR:
if(WM->SC != NULL){
free(WM->SC);
WM->SC = NULL;
}
break;
// case CYCLE_CONSTANT_CURRENT:
// if(WM->CCC != NULL){
// free(WM->CCC);
@@ -536,6 +536,7 @@ static void ADC_test_read(uint8_t *ADCdata); // for auto shifting
static void ADCGainControl(uint8_t ADCLevel);
static void ADCChannelSelect(uint8_t ADCChannel);
static int32_t DecodeADCVolt(uint16_t ADC_measure);
static int32_t DecodeADCVoutVolt(uint16_t ADC_measure);
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure);
static void Impedance_Calculate(uint16_t Voltage, int32_t Current);
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw);
@@ -579,7 +580,7 @@ static void set_update_instruction_callback(update_instruction_callback_type cal
#define VIS_SHIFT_200R 0b10000000
// real instruction
#define IV_CURVE 0b00010000
#define IV_CURVE 0b11110001
#define CV_CURVE 0b00100000
#define VOLT_OUTPUT 0b00110000
#define ZT_CURVE 0b01000000
@@ -591,8 +592,10 @@ static void set_update_instruction_callback(update_instruction_callback_type cal
#define SQUARE_WAVE_VOLTAMMETRY 0b10110000
#define POTENTIAL_STATE 0b11000000
#define CONSTANT_CURRENT 0b11010000
#define SET_RESISTER_LEVEL 0b11100000
#define READ_VOUT_VALUE 0b11100000
#define CYCLE_CONSTANT_CURRENT 0b11110000
#define SQUARE_CURR 0b00010000
// CIS instruction
@@ -631,6 +634,7 @@ struct _CT{
uint16_t StepTimeCounter;
uint16_t NotifyCounter;
uint32_t StandByCounter;
uint32_t PulseLength_counter;
}CT = {0};
//static bool NotifyReady = false;
@@ -646,6 +650,7 @@ static void DACCode2Real2Notify(uint16_t DACcode); // send notify voltage a
static void ZT_Plot(RTMode *RT);
static void VT_Plot(VTMode *VT);
static int32_t IT_PlotIT_Plot(WorkMode *WorkModeData);
static void RVout_Plot(RVoutMode *RVout);
// the following fxn do the same thing
// IVCurve_T is called if Vorigin > Vfinal, vice versa
@@ -659,6 +664,7 @@ static uint16_t OneWayVoltScan(IVMode *IV);
static void ramp_test();
static uint16_t DPVCurve(WorkMode *WorkModeData);
static uint16_t CVCurve(CVMode *CV);
static uint16_t SCCurve(SCMode *SC);
static uint16_t SWVCurve(WorkMode *WorkModeData);
static void reset();
@@ -690,11 +696,13 @@ static void TurnOn10V();
#include "EliteCCMode.h"
#include "EliteIVCurve.h"
#include "EliteCVCurve.h"
#include "EliteSCCurve.h"
#include "EliteITCurve.h"
#include "EliteVTCurve.h"
#include "EliteZTCurve.h"
#include "EliteCCCMode.h"
#include "impedance_meter.h"
#include "EliteReadVout.h"
// update instruction for Z meter
static void update_ZM_instruction(uint8 *ins) {
@@ -738,7 +746,7 @@ static void update_ZM_instruction(uint8 *ins) {
// }
// if(ins[10]) {
//INSTRUCTION.VoVi_Switch = ins[10];
INSTRUCTION.VoVi_Switch = 0x01;
INSTRUCTION.VoVi_Switch = 0x00;
// }
break;
}
@@ -843,11 +851,50 @@ static void update_ZM_instruction(uint8 *ins) {
}
// if(ins[11]) {
//INSTRUCTION.VoVi_Switch = ins[11];
INSTRUCTION.VoVi_Switch = 0x01;
INSTRUCTION.VoVi_Switch = 0x00;
// }
break;
}
case SQUARE_CURR: {
// CleanBuffer();
INSTRUCTION.eliteFxn = SQUARE_CURR;
DACReset = true;
INSTRUCTION.SampleRate = 100;
// if (ins[3] | ins[4]) {
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]); // don't care, set to DAC_ZERO as default
// INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
// }
// if (ins[5] | ins[6]) {
INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]); // don't care, set to DAC_ONEV as default
// INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
// }
// if (ins[7] | ins[8]) {
INSTRUCTION.Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
INSTRUCTION.Step = StepCode2DACcode(INSTRUCTION.Step);
// }
// if (ins[9]) {
INSTRUCTION.StepTime = ins[9];
INSTRUCTION.StepTime = OldStep2NewStepTime(INSTRUCTION.StepTime);
// }
INSTRUCTION.Pulse_Period = ins[9] * 2; // Pulse Period
INSTRUCTION.Pulse_Period = OldStep2NewStepTime(INSTRUCTION.Pulse_Period);
INSTRUCTION.Pulse_Length = ins[9] * 4; // Pulse Length
INSTRUCTION.Pulse_Length = OldStep2NewStepTime(INSTRUCTION.Pulse_Length);
// set for testing
// INSTRUCTION.VoltOrigin = DAC_ZERO;
// INSTRUCTION.VoltFinal = DAC_ONEV;
// INSTRUCTION.Step = 500;
// INSTRUCTION.StepTime = STEPTIME_ONE_SEC / 1000;
// INSTRUCTION.Pulse_Period = STEPTIME_ONE_SEC / 100;
// INSTRUCTION.Pulse_Length = STEPTIME_ONE_SEC / 10;
break;
}
case VOLT_OUTPUT: {
INSTRUCTION.eliteFxn = VOLT_OUTPUT;
@@ -935,8 +982,14 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case SET_RESISTER_LEVEL:{
INSTRUCTION.ResisterMeter = ins[3];
case READ_VOUT_VALUE:{
// INSTRUCTION.ResisterMeter = ins[3];
INSTRUCTION.eliteFxn = READ_VOUT_VALUE;
/*uint8_t ReadVoutBuf[2] = {0};
ADC_write(0xA4);
ADC_read(ReadVoutBuf);
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, 2, ReadVoutBuf);*/
break;
}
@@ -78,7 +78,9 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
(INSTRUCTION.eliteFxn == IT_CURVE) || \
(INSTRUCTION.eliteFxn == VT_CURVE) || \
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) \
(INSTRUCTION.eliteFxn == SQUARE_CURR) || \
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) || \
(INSTRUCTION.eliteFxn == READ_VOUT_VALUE) \
)
/*********************************************************************
@@ -117,6 +119,14 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
CT.NotifyCounter ++;
}
// Pulse Length counter (Square Current Curve)
if (CT.PulseLength_counter == INSTRUCTION.Pulse_Length){
CT.PulseLength_counter = 1;
}
else{
CT.PulseLength_counter ++;
}
/** Periodic Event **/
// Default working flow is DAC out -> ADC read -> send notify
// We will need a flag to control DAC, if we want to exchange to ADC -> DAC -> notify
@@ -170,6 +180,9 @@ static void EliteDACControl(WorkMode *WorkModeData) {
VoltScan(WorkModeData);
}
}
else if(INSTRUCTION.eliteFxn == SQUARE_CURR){
VoltScan(WorkModeData);
}
else if (INSTRUCTION.eliteFxn == ZT_CURVE){
if(INSTRUCTION.ResisterMeter == RESISTER_METER_SMALL){
// output 1V
@@ -214,6 +227,10 @@ static void EliteADCControl(WorkMode *WorkModeData) {
CV_Plot(WorkModeData->CV);
break;
}
case SQUARE_CURR:{
SC_Plot(WorkModeData->SC);
break;
}
case IT_CURVE:{
IT_Plot(WorkModeData);
// NotifyReady = true;
@@ -235,6 +252,16 @@ static void EliteADCControl(WorkMode *WorkModeData) {
// CCModeReverseCurrent(WorkModeData->CC);
break;
}
case READ_VOUT_VALUE:{
RVout_Plot(WorkModeData->RVout);
/*uint8_t ReadVoutBuf[2] = {0};
ADC_write(0xA4);
ADC_read(ReadVoutBuf);
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, 2, ReadVoutBuf);*/
break;
}
default:{
IT_Plot(WorkModeData);
// NotifyReady = true;
@@ -245,7 +272,7 @@ static void EliteADCControl(WorkMode *WorkModeData) {
}
static void EliteNotifyControl() {
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE) || (INSTRUCTION.eliteFxn == SQUARE_CURR)) {
// output the last notify, and reset Elite
if (!PeriodicEvent) {
SendNotify();
+7694
View File
File diff suppressed because it is too large Load Diff