Compare commits

...

23 Commits

Author SHA1 Message Date
ROY 32aec7b958 [copy] copy 87bb2580 version from BPS_bioprocc2650 project 2022-06-23 10:51:11 +08:00
ROY ee1d052c3a [cali] add BOARD_13 calibration data. 2022-06-22 15:36:50 +08:00
ROY 7acafa81b8 [cali] add BOARD_12 calibration data. 2022-06-22 15:33:59 +08:00
ROY e97d556dd9 [cali] update BOARD_7 calibration data. 2022-06-10 18:19:46 +08:00
ROY c227d21546 [update] use red led when BT timeout 2022-06-01 10:57:35 +08:00
ROY f9e33d0ede [cali] add BOARD_11 calibration data. 2022-05-31 16:13:51 +08:00
ROY a9fd1028d1 [cali] add BOARD_8 calibration data. 2022-05-31 16:08:18 +08:00
ROY f6a20eaea5 [cali] update BOARD_2 calibration data. 2022-05-31 13:26:34 +08:00
ROY f904bbd522 [cali] update BOARD_7 calibration data. 2022-05-31 13:23:55 +08:00
ROY 6f3a1b57ae [cali] add BOARD_7 calibration data. 2022-05-26 17:31:39 +08:00
ROY b795b7eb6b [cali] update BOARD_8 & BOARD_9 & BOARD_10 calibration data. 2022-05-26 17:22:37 +08:00
ROY a1adf82f2b [update] cc & cp corrected speed 1/10/100 2022-05-23 11:00:46 +08:00
Roy 061064c27a [update] don't use GPT_MODE_PERIODIC_DOWN 2022-05-18 15:17:38 +08:00
Roy 2d1556686c [cali] update BOARD_1 calibration data. 2022-05-04 10:40:13 +08:00
Roy 0d7f334499 [cali] update BOARD_4 calibration data. 2022-05-04 10:38:25 +08:00
Roy b849231be3 [update] fix manual current stalls 2022-04-29 18:37:39 +08:00
Roy 060dde64a8 [cali] update BOARD_5 calibration data. 2022-04-29 16:48:21 +08:00
Roy 6be73528d4 [cali] update BOARD_1 calibration data. 2022-04-29 10:12:16 +08:00
Roy 7b4436920f [cali] update BOARD_2 calibration data. 2022-04-28 18:18:26 +08:00
Roy b34e947cc8 [update] fix power off led 2022-04-28 10:15:20 +08:00
Roy 8c4737e494 [cali] add BOARD_6 calibration data. 2022-04-27 16:57:55 +08:00
Roy 6f36e781b7 [cali] add BOARD_5 calibration data. 2022-04-27 16:55:25 +08:00
Roy 8403c16fa0 [update] fix highz problem 2022-04-27 13:18:24 +08:00
33 changed files with 4176 additions and 6764 deletions
@@ -177,7 +177,7 @@ static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool hig
}
}
PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch
// CPUdelay(10);
CPUdelay(10);
PIN_setOutputValue(&ZM_rst, latch_num, 0); // Turn off latch
remove_elite_pin();
ELITE15_SPI_HOLD();
@@ -0,0 +1,32 @@
#ifndef ELITECCC
#define ELITECCC
#include "EliteCCMode.h"
// XXX : should we reset DAC output after STOP?
static void CCModeReverseCurrent(CCCMode *CCC){
if(CCC->StandBy){
if(CT.StandByCounter == CCC->StandByTime){
CCC->StandBy = false;
CT.StandByCounter = 0;
}
else{
CT.StandByCounter ++;
}
}
else{
// reverse charge/discharge
if(CCC->BatteryV == CCC->VMax){
CCC->StandBy = true;
CCC->value = CCC->DischargeCurrent;
}
else if(CCC->BatteryV == CCC->VMin){
CCC->StandBy = true;
CCC->value = CCC->ChargeCurrent;
}
}
}
#endif
@@ -0,0 +1,83 @@
#ifndef ELITECCMODE
#define ELITECCMODE
#define Vset INSTRUCTION.Vset
#define DELTAVOLTMAX 100000
/* Transform setting CC into IUC
*
* User code in CC mode : 0 ~ 3000000
* Real current value : -15.00000 ~ 15.00000 mA
* => user code = 1500000 mapping to 0.00000 mA
*/
static void CC_Vscan(CCMode *CC){
static int32_t Iin = 0;
static int32_t deltaI = 0;
static int32_t deltaV = 0;
uint16_t divisionRate;
if(vscanReset){
Vset = 0;
if(CC->_charge == 0){
CC->_Iset *= -1;
}
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - CC->_Iset;
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
divisionRate = 1000;
}else{
divisionRate = 10;
}
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
deltaV = DELTAVOLTMAX;
}else if(deltaV < (-DELTAVOLTMAX)){
deltaV = (-DELTAVOLTMAX);
}
Vset = Vset + deltaV; //[5nV]
if(Vset <= CC->_Vmin){
Vset = CC->_Vmin;
}else if(Vset >= CC->_Vmax){
Vset = CC->_Vmax;
}
}
if(!vscanReset){
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - CC->_Iset;
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
divisionRate = 1000;
}else{
divisionRate = 10;
}
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
deltaV = DELTAVOLTMAX;
}else if(deltaV < (-DELTAVOLTMAX)){
deltaV = (-DELTAVOLTMAX);
}
Vset = Vset + deltaV; //[5nV]
if(Vset <= CC->_Vmin){
Vset = CC->_Vmin;
}else if(Vset >= CC->_Vmax){
Vset = CC->_Vmax;
}
}
// int32_t RealV;
// RealV = (int32_t)(deltaV);
// InputNotify(NOTIFY_IMPEDANCE, RealV);
}
#endif
@@ -0,0 +1,156 @@
#ifndef ELITECV3
#define ELITECV3
#define Vset INSTRUCTION.Vset
static uint16_t CV3Curve(CV3Mode *CV3){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
Vin = CV3->_measureVin * 200;//[5nV]
if(DACReset){
Vout = Vset + Vin;
DACReset = false;
}else{
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
InputNotify(NOTIFY_VOLT, RealV2);
int32_t RealV;
RealV = (int32_t)(Vout / 200);//[1uV]
InputNotify(NOTIFY_IMPEDANCE, RealV);
DAC_outputV(DACOutCode);
return DACOutCode;
}
static void CV3_Vscan(CV3Mode *CV3){
static int16_t VminCounter;
static int16_t VmaxCounter;
static uint16_t CycleCounter;
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV3->_cycleNumber + 1);
if(vscanReset){
VmaxCounter = 0;
VminCounter = 0;
CycleCounter = 0;
if(INSTRUCTION.directionInit == 1){
CV3->_direction_up = true;
CV3->_current_direction_up = true;
}else{
CV3->_direction_up = false;
CV3->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
CV3->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
CV3->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
if(CV3->_Vmin == CV3->_Vinit){
VminCounter = -1;
}
if(CV3->_Vmax == CV3->_Vinit){
VmaxCounter = -1;
}
Vset = CV3->_Vinit;
}
if(!vscanReset){
if((INSTRUCTION.Vinit < INSTRUCTION.Ve1 && INSTRUCTION.Vinit < INSTRUCTION.Ve2) ||
(INSTRUCTION.Vinit > INSTRUCTION.Ve1 && INSTRUCTION.Vinit > INSTRUCTION.Ve2)
){
if (CV3->_current_direction_up){
Vset = Vset + CV3->_Vstep;
}else{
Vset = Vset - CV3->_Vstep;
}
if(INSTRUCTION.Vinit < INSTRUCTION.Ve1 && INSTRUCTION.Vinit < INSTRUCTION.Ve2){
if(Vset == CV3->_Vmin){
VminCounter = -1;
INSTRUCTION.Vinit = INSTRUCTION.Vmin;
CV3->_Vinit = CV3->_Vmin;
}
}else if(INSTRUCTION.Vinit > INSTRUCTION.Ve1 && INSTRUCTION.Vinit > INSTRUCTION.Ve2){
if(Vset == CV3->_Vmax){
VmaxCounter = -1;
INSTRUCTION.Vinit = INSTRUCTION.Vmax;
CV3->_Vinit = CV3->_Vmax;
}
}
}else{
if (Vset >= CV3->_Vmax){
VmaxCounter++;
}else if (Vset <= CV3->_Vmin){
VminCounter++;
}
if (CV3->_current_direction_up){
Vset = Vset + CV3->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - CV3->_Vstep * GPT.GptimerMultiple;
}
if(VmaxCounter != 0 && VminCounter != 0){
if(VmaxCounter == VminCounter && CV3->_direction_up && CV3->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset >= CV3->_Vinit){
CV3->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
if(VmaxCounter == VminCounter && !CV3->_direction_up && !CV3->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset <= CV3->_Vinit){
CV3->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
}
if (Vset >= CV3->_Vmax){
CV3->_current_direction_up = false;
}else if (Vset <= CV3->_Vmin){
CV3->_current_direction_up = true;
}
/*stop condition*/
if(CV3->_cycleNumber == 0){
// PeriodicEvent = false;
ModeLED(POST_WORK);
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
}
}
}
// int32_t RealV;
// RealV = (int32_t)(Vset / 500);//[1uV]
// InputNotify(NOTIFY_VOLT, RealV);
}
#endif
@@ -0,0 +1,217 @@
#ifndef ELITECV
#define ELITECV
static uint16_t SWVCurve(WorkMode *WorkModeData) {
static uint8_t counter;
static uint16_t outputV;
static uint16_t Volt;
static bool direction_up;
// reset origin volt at the begin
if (DACReset) {
Volt = INSTRUCTION.Ve1;
outputV = INSTRUCTION.Ve1;
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
direction_up = true;
else
direction_up = false;
counter = 1;
DACReset = false;
}
if (counter == 2 * PulseWidth)
counter = 1;
else
counter++;
// output a certain volt
outputV = Volt;
DAC_outputV(outputV);
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
// check if we reach the final volt
if ((outputV >= INSTRUCTION.Ve2 && direction_up) || (outputV <= INSTRUCTION.Ve2 && !direction_up)) {
PeriodicEvent = false;
DACReset = true;
}
// prepare the next output volt
if (direction_up) {
if (counter == PulseWidth)
Volt = Volt + Amplitude;
else if (counter == 2 * PulseWidth)
Volt = Volt - (Amplitude - INSTRUCTION.step);
else
Volt = Volt;
} else {
if (counter == PulseWidth)
Volt = Volt - Amplitude;
else if (counter == 2 * PulseWidth)
Volt = Volt + (Amplitude - INSTRUCTION.step);
else
Volt = Volt;
}
return outputV;
}
static uint16_t DPVCurve(WorkMode *WorkModeData) {
static uint8_t counter;
static uint16_t Volt1;
static uint16_t Volt2;
static uint16_t outputV;
static bool direction_up;
// reset origin volt at the begin
if (DACReset) {
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
direction_up = true;
else
direction_up = false;
Volt1 = INSTRUCTION.Ve1;
if (direction_up)
Volt2 = INSTRUCTION.Ve1 + Amplitude;
else
Volt2 = INSTRUCTION.Ve1 - Amplitude;
counter = 1;
DACReset = false;
}
if (counter == PulsePeriod)
counter = 1;
else
counter++;
// output a certain volt
if (counter <= (PulsePeriod - PulseWidth)) {
outputV = Volt1;
DAC_outputV(Volt1);
} else {
outputV = Volt2;
DAC_outputV(Volt2);
}
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
// check if we reach the final volt
if (((outputV >= INSTRUCTION.Ve2) && direction_up) || ((outputV <= INSTRUCTION.Ve2) && !direction_up)) {
PeriodicEvent = false;
DACReset = true;
}
// check overflow/underflow and prepare for next output
if (direction_up) {
if (Volt1 + INSTRUCTION.step < Volt1)
Volt1 = 0xffff;
else
Volt1 = Volt1 + INSTRUCTION.step;
if (Volt2 + INSTRUCTION.step < Volt2)
Volt2 = 0xffff;
else
Volt2 = Volt2 + INSTRUCTION.step;
} else {
if (Volt1 - INSTRUCTION.step > Volt1)
Volt1 = 0x0000;
else
Volt1 = Volt1 - INSTRUCTION.step;
if (Volt2 - INSTRUCTION.step > Volt2)
Volt2 = 0x0000;
else
Volt2 = Volt2 - INSTRUCTION.step;
}
if (counter + 1 <= (PulsePeriod - PulseWidth)) {
return Volt1;
} else {
return Volt2;
}
}
static void CV_Vscan(CVMode *CV){
static int16_t VminCounter;
static int16_t VmaxCounter;
static uint16_t CycleCounter;
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV->_cycleNumber + 1);
if(vscanReset){
VmaxCounter = 0;
VminCounter = 0;
CycleCounter = 0;
if(INSTRUCTION.directionInit == 1){
CV->_direction_up = true;
CV->_current_direction_up = true;
}else if(INSTRUCTION.directionInit == 0){
CV->_direction_up = false;
CV->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
CV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
CV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
if(CV->_Vmin == CV->_Vinit){
VminCounter = -1;
}
if(CV->_Vmax == CV->_Vinit){
VmaxCounter = -1;
}
Vset = CV->_Vinit;
}
if(!vscanReset){
if (Vset >= CV->_Vmax){
VmaxCounter++;
}else if (Vset <= CV->_Vmin){
VminCounter++;
}
if (CV->_current_direction_up){
Vset = Vset + CV->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - CV->_Vstep * GPT.GptimerMultiple;
}
if(VmaxCounter != 0 && VminCounter != 0){
if(VmaxCounter == VminCounter && CV->_direction_up && CV->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset >= CV->_Vinit){
CV->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
if(VmaxCounter == VminCounter && !CV->_direction_up && !CV->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset <= CV->_Vinit){
CV->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
}
if (Vset >= CV->_Vmax){
CV->_current_direction_up = false;
}else if (Vset <= CV->_Vmin){
CV->_current_direction_up = true;
}
/*stop condition*/
if(CV->_cycleNumber == 0){
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}
}
#endif
@@ -0,0 +1,47 @@
#ifndef ELITECVSCAN
#define ELITECVSCAN
#define Vset INSTRUCTION.Vset
static uint16_t CVSCANCurve(CVSCANMode *CVSCAN){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
Vin = CVSCAN->_measureVin * 200;//[5nV]
if(DACReset){
Vout = Vset + Vin;
DACReset = false;
}else{
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
InputNotify(NOTIFY_VOLT, RealV2);
int32_t RealV;
RealV = (int32_t)(Vout / 200);//[1uV]
InputNotify(NOTIFY_IMPEDANCE, RealV);
DAC_outputV(DACOutCode);
return DACOutCode;
}
static void CVSCAN_Vscan(CVSCANMode *CVSCAN){
if(vscanReset){
Vset = CVSCAN->_Vinit;
}
if(!vscanReset){
Vset = CVSCAN->_Vinit;
}
}
#endif
@@ -4,6 +4,31 @@
static bool DACReset;
//#ifdef ELITE_VERSION_1_3
//#define DACOUT 0x30
//
//static void DAC_outputV(uint16_t voltLV) {
// // C = command, X = don't care, D = data
// // CCCC XXXX = command
// // DDDD DDDD = v1
// // DDDD XXXX = v2
//
// uint8_t v1, v2 = 0;
// v1 = (uint8_t) (voltLV >> 4) & 0xFF;
// v2 = (uint8_t) ((voltLV & 0x000F) << 4) & 0xF0;
//
// spi_DACtxbuf[0] = command;
// spi_DACtxbuf[1] = v1;
// spi_DACtxbuf[2] = v2;
// for (int i = 3; i < SPI_DAC_SIZE; i++) {
// spi_DACtxbuf[i] = 0;
// }
//
// DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
//}
//#endif
#ifdef ELITE_VERSION_1_4
#define DACCLS 0x02
#define DACOUT 0x31
@@ -34,21 +59,20 @@ static uint16_t DAC_outputV(uint16_t voltLV) {
static void VoutGainControl(uint8_t VOUTLevel){
if(VOUTLevel == 0){
// VOUT gain level = 0, using 240K resister
PIN15_setOutputValue(Turnon_VOUT_SMALL, 0);
PIN15_setOutputValue(Turon_VOUT_SMALL, 0);
}
else if(VOUTLevel == 1){
// VOUT gain level = 1, using 15K resister
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
else if(VOUTLevel == 2){
// VOUT gain level = 2, using 15K resister
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
else{
// default using 15K resister
PIN15_setOutputValue(Turnon_VOUT_SMALL, 1);
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
volt_rec_en = false;
}
#endif
@@ -70,23 +94,26 @@ static void AutoGainChangeVout(int32_t userCode){
// switch to 1 level volt(small) 15K
// switch to 2 level volt(large) 240K
if(instru.VoutGainLv == VOUT_GAIN_AUTO){
instru.VoutGainLv = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLv);
if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_AUTO){
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
record_flag = false;
}
if(instru.VoutGainLv == VOUT_GAIN_15K){
if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_15K){
if(RealVolt > DAC_VOUT_GAIN_LARGE_BOUNDARY || RealVolt < -1 * DAC_VOUT_GAIN_LARGE_BOUNDARY){
// switch to 2 level volt(large)
instru.VoutGainLv = VOUT_GAIN_240K;
VoutGainControl(instru.VoutGainLv);
INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
record_flag = false;
}
}
else if(instru.VoutGainLv == VOUT_GAIN_240K){
else if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_240K){
if(RealVolt < DAC_VOUT_GAIN_SMALL_BOUNDARY && RealVolt > -1 * DAC_VOUT_GAIN_SMALL_BOUNDARY ){
// switch to 1 level volt(small)
instru.VoutGainLv = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLv);
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
record_flag = false;
}
}
}
@@ -2,6 +2,14 @@
#ifndef ELITE_FLAG_CT_INIT
#define ELITE_FLAG_CT_INIT
// CT counter
struct _CT{
uint32_t SampleRate_counter;
uint16_t StepTimeCounter;
uint16_t NotifyCounter;
uint32_t StandByCounter;
}CT = {0};
// GPT counter
struct _GPT{
uint32_t GptimerCounter;
@@ -17,6 +25,13 @@ struct _GPT{
uint32_t StiCounter;
}GPT = {0};
static void InitCT(){
CT.SampleRate_counter = 1;
CT.StepTimeCounter = 1;
CT.NotifyCounter = 1;
CT.StandByCounter = 0;
}
static void InitGPT(){
GPT.GptimerCounter = 0;
GPT.GptimerCounter0 = 0;
@@ -17,14 +17,14 @@ static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_In
#define elite_gptimer_start() GPTimerCC26XX_start(gptimer_handle)
#define elite_gptimer_stop() GPTimerCC26XX_stop(gptimer_handle)
#define elite_gptimer_close() GPTimerCC26XX_close(gptimer_handle)
#define CLOCK_FREQ 4769 // clock freq = 0.1 ms(4800), Measured(4769)
#define CLOCK_FREQ 4800 // clock freq = 0.1 ms CLK frequency 4769
#define elite_gptimer_open() \
do { \
GPTimerCC26XX_Params params; \
GPTimerCC26XX_Params_init(&params); \
params.width = GPT_CONFIG_16BIT; \
params.mode = GPT_MODE_PERIODIC_DOWN; \
params.mode = GPT_MODE_PERIODIC_UP; \
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; \
gptimer_handle = GPTimerCC26XX_open(Board_GPTIMER0A, &params); \
Types_FreqHz freq; \
@@ -0,0 +1,48 @@
#ifndef ELITEIV
#define ELITEIV
#define Vset INSTRUCTION.Vset
static void IV_Vscan(IVMode *IV){
if(vscanReset){
if(INSTRUCTION.directionInit == 1){
IV->_direction_up = true;
IV->_current_direction_up = true;
}else if(INSTRUCTION.directionInit == 0){
IV->_direction_up = false;
IV->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
IV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
IV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
Vset = IV->_Vinit;
}
if(!vscanReset){
if(IV->_current_direction_up){
if(Vset >= IV->_Vmax){
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}else{
if(Vset <= IV->_Vmin){
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}
if (IV->_current_direction_up){
Vset = Vset + IV->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - IV->_Vstep * GPT.GptimerMultiple;
}
}
}
#endif
@@ -1,27 +1,50 @@
/*=============================================================================
= instr.h =
=============================================================================*/
#ifndef ELITE_INSTR_H
#define ELITE_INSTR_H
#ifdef __cpulsplus
extern "C" {
#endif
#ifndef ELITEINSTRUCTION
#define ELITEINSTRUCTION
/** Iin, Vin, Vout **/
#define IIN_ADC 0x00
#define VIN_ADC 0x01
#define VOUT_DAC 0x02
#define HIGH_Z 0x03
/** ADC Iin gain level **/
#define I_GAIN_3M 0x00 // largest gain
#define I_GAIN_100K 0x01
#define I_GAIN_3K 0x02
#define I_GAIN_100R 0x03 // the least gain
#define I_GAIN_AUTO 0x04
/** ADC Vin gain level **/
#define VIN_GAIN_1M 0x00
#define VIN_GAIN_30K 0x01
#define VIN_GAIN_1K 0x02
#define VIN_GAIN_AUTO 0x03
/** Vout gain level **/
#define VOUT_GAIN_240K 0x00
#define VOUT_GAIN_15K 0x01
#define VOUT_GAIN_AUTO 0x02
/* DAC reset parameter */
#define DAC_ZERO 25000
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
/*==============================
==== headstage instruction ====
=============================*/
struct HEADSTAGE_INSTRUCTION {
uint8_t chip_id;
uint8_t eliteFxn;
// time relation
/** DAC parameter **/
uint8_t VsetRateIndex;
uint32_t VsetRate;
uint32_t sampleRate;
uint32_t notifyRate;
uint32_t period;
int32_t Vset;
uint16_t VoltConstant;
uint8_t directionInit;
@@ -32,40 +55,26 @@ struct HEADSTAGE_INSTRUCTION {
int32_t Vmax;
int32_t Vmin;
uint32_t steptime;
/** ADC parameter **/
uint8_t sampleRateIndex;
uint32_t sampleRate;
uint8_t VoViSwitch;
uint8_t AutoGainEnable;
uint8_t VinAutoGainEnable;
uint8_t VoutAutoGainEnable;
uint8_t ADCGainLevel;
// voltage output gain
uint16_t VoutGainLevel;
uint8_t VinADCGainLevel;
uint8_t IinADCAutoGainEn;
uint8_t VinADCAutoGainEn;
uint8_t VoutAutoGainEn;
uint8_t IinADCGainLv;
uint8_t VinADCGainLv;
uint16_t VoutGainLv;
uint8_t gain_switch_on;
uint8_t AdcChannel;
bool hign_z_en;
/** Notify parameter **/
uint32_t notifyRate;
/** mode parameter **/
uint16_t cycleNumber;
uint8_t charge;
int32_t constantCurrent;
// uni pulse mode
int32_t v0;
uint32_t t_pulse[4];
int32_t v_initial[4];
int32_t v_slope[4];
int32_t v_step[4];
uint32_t t_pulse_min[4];
uint32_t t_pulse_max[4];
int32_t v_stop;
int32_t v_up;
int32_t v_low;
bool v_invert_option;
bool v_stop_direction;
int32_t v_1;
int32_t v_2;
// pulse mode
int32_t Currentmax;
int32_t sti_v1;
int32_t sti_v2;
int32_t sti_v3;
@@ -83,51 +92,11 @@ struct HEADSTAGE_INSTRUCTION {
uint16_t sti_cy;
uint16_t sti_loop;
int32_t Vout;
uint16_t StepTime;
// not use
int32_t Currentmax;
uint8_t VoViSwitch;
uint8_t AdcChannel;
} instru = {0};
/** Iin, Vin, Vout **/
#define RIS_ADC_IIN 0x00
#define RIS_ADC_VIN 0x01
#define RIS_DAC_VOUT 0x02
#define RIS_HIGH_Z 0x03
#define RIS_ADC_VOUT 0x04
#define RIS_ADC_BAT 0x05
// ADC Iin gain level !!! move to ADC.h in future
#define I_GAIN_3M 0x00 // lv0,largest gain
#define I_GAIN_100K 0x01 // lv1
#define I_GAIN_3K 0x02 // lv2
#define I_GAIN_100R 0x03 // lv3,the least gain
#define I_GAIN_AUTO 0x04
// ADC Vin gain level !!! move to ADC.h in future
#define VIN_GAIN_1M 0x00
#define VIN_GAIN_30K 0x01
#define VIN_GAIN_1K 0x02
#define VIN_GAIN_AUTO 0x03
// DAC Vout gain level !!! move to DAC.h in future
#define VOUT_GAIN_240K 0x00
#define VOUT_GAIN_15K 0x01
#define VOUT_GAIN_AUTO 0x02
/* DAC reset parameter */
#define DAC_ZERO 25000 // DAC_ZERO is about 0V
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
} INSTRUCTION = {0};
/*********************************************************************
* @fn InitEliteInstruction
@@ -138,103 +107,53 @@ struct HEADSTAGE_INSTRUCTION {
*
* @return None.
*/
static void InitEliteInstruction(void)
{
instru.chip_id = 0;
instru.eliteFxn = 0; //default is a null event
instru.VsetRateIndex = 0; // vscan rate
instru.VsetRate = 2;
instru.sampleRate = 20; // ADC's sample rate
instru.notifyRate = CLOCK_ONE_SECOND; // send data's rate
instru.period = CLOCK_ONE_SECOND;
instru.Vset = 0; // vscan's volt[5nv]
instru.VoltConstant = DAC_ZERO; // DAC's volt[UC]
instru.directionInit = 1; // 0:reverse, 1:forward
instru.step = 0;
instru.Ve1 = DAC_ZERO; // user set volt[UC]
instru.Ve2 = DAC_ZERO; // user set volt[UC]
instru.Vinit = 0; // user set init volt[5nv]
instru.Vmax = 0; // user set max volt[5nv]
instru.Vmin = 0; // user set min voit[5nv]
instru.IinADCAutoGainEn = 1;
instru.VinADCAutoGainEn = 1;
instru.VoutAutoGainEn = 1;
instru.IinADCGainLv = I_GAIN_AUTO;
instru.VinADCGainLv = VIN_GAIN_AUTO;
instru.VoutGainLv = VOUT_GAIN_AUTO;
instru.gain_switch_on = 0b11110000; // cur auto gain switch, |lv0|lv1|lv2|lv3|none|none|none|none|
instru.AdcChannel = 0; // RIS_ADC_IIN: 0x00, RIS_ADC_VIN: 0x01, RIS_DAC_VOUT: 0x02, RIS_HIGH_Z: 0x03
instru.hign_z_en = 1;
instru.cycleNumber = 1;
instru.charge = 1; // 0:discharge, 1:charge
instru.constantCurrent = 0;
// uni pulse mode
instru.v0 = DAC_ZERO; // t < 0, volt is 0v
instru.v_stop = 0;
instru.t_pulse[0] = 0;
instru.t_pulse[1] = 0;
instru.t_pulse[2] = 0;
instru.t_pulse[3] = 0;
instru.v_initial[0] = 0;
instru.v_initial[1] = 0;
instru.v_initial[2] = 0;
instru.v_initial[3] = 0;
instru.v_slope[0] = 0;
instru.v_slope[1] = 0;
instru.v_slope[2] = 0;
instru.v_slope[3] = 0;
instru.v_step[0] = 0;
instru.v_step[1] = 0;
instru.v_step[2] = 0;
instru.v_step[3] = 0;
instru.t_pulse_min[0] = 0;
instru.t_pulse_min[1] = 0;
instru.t_pulse_min[2] = 0;
instru.t_pulse_min[3] = 0;
instru.t_pulse_max[0] = 0;
instru.t_pulse_max[1] = 0;
instru.t_pulse_max[2] = 0;
instru.t_pulse_max[3] = 0;
instru.v_invert_option = false;
instru.v_stop_direction = true;
instru.v_1 = 0;
instru.v_2 = 0;
static void InitEliteInstruction(){
INSTRUCTION.chip_id = 0;
INSTRUCTION.eliteFxn = 0; //default is a null event
INSTRUCTION.VsetRateIndex = 0;
INSTRUCTION.VsetRate = 2;
INSTRUCTION.Vset = 0;
INSTRUCTION.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
INSTRUCTION.directionInit = 1; //0:reverse 1:forward
INSTRUCTION.step = 0;
INSTRUCTION.Ve1 = DAC_ZERO;
INSTRUCTION.Ve2 = DAC_ZERO;
INSTRUCTION.Vinit = 0;
INSTRUCTION.Vmax = 0;
INSTRUCTION.Vmin = 0;
INSTRUCTION.sampleRateIndex = 1;
INSTRUCTION.sampleRate = 100;
INSTRUCTION.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
INSTRUCTION.AutoGainEnable = 1;
INSTRUCTION.VinAutoGainEnable = 1;
INSTRUCTION.VoutAutoGainEnable = 1;
INSTRUCTION.ADCGainLevel = I_GAIN_AUTO;
INSTRUCTION.VoutGainLevel = VOUT_GAIN_AUTO;
INSTRUCTION.VinADCGainLevel = VIN_GAIN_AUTO;
INSTRUCTION.notifyRate = STEPTIME_ONE_SEC;
INSTRUCTION.cycleNumber = 1;
INSTRUCTION.charge = 1; //0:discharge 1:charge
INSTRUCTION.constantCurrent = 0;
INSTRUCTION.Currentmax = 0;
INSTRUCTION.StepTime = STEPTIME_ONE_SEC;
INSTRUCTION.AdcChannel = 0;
//pulse mode
instru.sti_t1 = 0;
instru.sti_t2 = 0;
instru.sti_t3 = 0;
instru.sti_t4 = 0;
instru.sti_t5 = 0;
instru.sti_t6 = 0;
instru.sti_t7 = 0;
instru.sti_v1 = DAC_ZERO;
instru.sti_v2 = DAC_ZERO;
instru.sti_v3 = DAC_ZERO;
instru.sti_v4 = DAC_ZERO;
instru.sti_v5 = DAC_ZERO;
instru.sti_v6 = DAC_ZERO;
instru.sti_v7 = DAC_ZERO;
instru.sti_loop = 1;
instru.sti_cy = 0;
instru.Vout = 0;
// not use
instru.Currentmax = 0;
instru.VoViSwitch = 0x01;
return;
}
#ifdef __cpulsplus
INSTRUCTION.sti_t1 = 0;
INSTRUCTION.sti_t2 = 0;
INSTRUCTION.sti_t3 = 0;
INSTRUCTION.sti_t4 = 0;
INSTRUCTION.sti_t5 = 0;
INSTRUCTION.sti_t6 = 0;
INSTRUCTION.sti_t7 = 0;
INSTRUCTION.sti_v1 = DAC_ZERO;
INSTRUCTION.sti_v2 = DAC_ZERO;
INSTRUCTION.sti_v3 = DAC_ZERO;
INSTRUCTION.sti_v4 = DAC_ZERO;
INSTRUCTION.sti_v5 = DAC_ZERO;
INSTRUCTION.sti_v6 = DAC_ZERO;
INSTRUCTION.sti_v7 = DAC_ZERO;
INSTRUCTION.sti_loop = 1;
INSTRUCTION.sti_cy = 0;
}
#endif
#endif
@@ -9,7 +9,8 @@ static bool TurnOnElite(uint8_t key) {
// press 1 sec, power on LED, read bat power
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
headstage_battery_volt();
uint16_t bat = NotifyVoltBat;
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
PIN15_setOutputValue(enable_5v, 0);
return false;
@@ -49,14 +50,14 @@ static void EliteKeyPress(uint8_t key) {
}
ShutDownCounter ++;
} else {
if (OriginEliteFxn == instru.eliteFxn) { // old function == currunt instruction
if (OriginEliteFxn == INSTRUCTION.eliteFxn) { // old function == currunt instruction
if (ShutDownCounter != 0) {
// dark LED
checkFlafLED();
ShutDownCounter = 0;
}
} else { // old function != currunt instruction
OriginEliteFxn = instru.eliteFxn;
OriginEliteFxn = INSTRUCTION.eliteFxn;
if (ShutDownCounter != 0) {
ShutDownCounter = 0;
}
@@ -5,12 +5,6 @@
#define DARKLED 0xE1
#define LIGHTLED 0xE8
static bool btWaitLedFlag = 0;
static bool noEventLedFlag = 0;
static bool preWorkLedFlag = 0;
static bool workingLedFlag = 0;
static bool postWorkLedFlag = 0;
static void WorkModeLED();
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
@@ -25,20 +19,21 @@ static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue)
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
}
static void Elite_led_color(uint16_t color){
switch (color) {
case COLOR_RED: {
LED_color(DARKLED, 0xFF, 0x00, 0x00);
LED_color(DARKLED, 0x50, 0x00, 0x00);
break;
}
case COLOR_ORANGE: {
LED_color(DARKLED, 0xFF, 0x58, 0x09);
LED_color(DARKLED, 0x50, 0x58, 0x09);
break;
}
case COLOR_YELLOW: {
LED_color(LIGHTLED, 0xFF, 0x80, 0x00);
LED_color(LIGHTLED, 0x50, 0x80, 0x00);
break;
}
case COLOR_GREEN: {
@@ -58,42 +53,21 @@ static void Elite_led_color(uint16_t color){
break;
}
case COLOR_MAGENTA: {
LED_color(DARKLED, 0xFF, 0x00, 0x80);
LED_color(DARKLED, 0x50, 0x00, 0x80);
break;
}
case COLOR_PURPLE: {
LED_color(DARKLED, 0xFF, 0x00, 0xFF);
LED_color(DARKLED, 0x50, 0x00, 0xFF);
break;
}
case COLOR_WHITE: {
LED_color(DARKLED, 0xCA, 0xFF, 0xFF);
LED_color(DARKLED, 0x50, 0xFF, 0xFF);
break;
}
case COLOR_BLACK: {
LED_color(0x00, 0x00, 0x00, 0x00);
break;
}
//dark LED
case COLOR_YELLOW_DARK: {
LED_color(DARKLED, 0xFF, 0x80, 0x00);
break;
}
case COLOR_GREEN_DARK: {
LED_color(DARKLED, 0x00, 0x33, 0x00);
break;
}
case COLOR_BLUE_DARK: {
LED_color(DARKLED, 0x00, 0x00, 0x33);
break;
}
case COLOR_CYAN_DARK: {
LED_color(DARKLED, 0x00, 0x10, 0x10);
break;
}
case COLOR_PURPLE_DARK: {
LED_color(DARKLED, 0x55, 0x00, 0x55);
break;
}
default: {
break;
}
@@ -140,8 +114,7 @@ static void ModeLED(uint16_t modeStatus) {
}
}
static void checkFlafLED()
{
static void checkFlafLED() {
if(btWaitLedFlag == 1){
ModeLED(BT_WAIT);
}
@@ -159,42 +132,50 @@ static void checkFlafLED()
}
}
static void WorkModeLED()
{
switch (instru.eliteFxn) {
case CURVE_IV:
case CURVE_VO:
case CURVE_RT:
case CURVE_VT:
case CURVE_IT:
case CURVE_CV:
case CURVE_CA:
case CURVE_CC:
case CURVE_OCP:
case CURVE_LSV:
case CURVE_IV_CY:
case CURVE_PULSE:
case CURVE_UNI_PULSE:
case CURVE_DPV:
case CURVE_DPV_SMPRATE:
case CURVE_DPV_ADVANCE:
case CURVE_DPV_ADVANCE_SMPRATE:
WORKLED();
break;
case CURVE_CALI_ADC:
if (instru.AdcChannel == RIS_ADC_IIN) {
Elite_led_color(COLOR_RED);
} else if (instru.AdcChannel == RIS_ADC_VIN) {
Elite_led_color(COLOR_ORANGE);
} else if (instru.AdcChannel == RIS_DAC_VOUT) {
Elite_led_color(COLOR_BLUE);
}
break;
default:
break;
static void WorkModeLED() {
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE:
case CV_CURVE:
case DIFFERENTIAL_PULSE_VOLTAMMETRY:
case SQUARE_WAVE_VOLTAMMETRY:
case VOLT_OUTPUT:
case ZT_CURVE:
case VT_CURVE:
case IT_CURVE:
case ADC_TEST:
case CYCLIC_VOLTAMMETRY:
case LINEAR_SWEEP_VOLTAMMETRY:
case CONSTANT_VSCAN:{
WORKLED();
break;
}
case PULSE_MODE:{
// Elite_led_color(COLOR_YELLOW);
WORKLED();
break;
}
case CONSTANT_CURRENT:{
WORKLED();
break;
}
case CALI_ADC_MODE:{
if(INSTRUCTION.AdcChannel == IIN_ADC){
Elite_led_color(COLOR_RED);
}else if(INSTRUCTION.AdcChannel == VIN_ADC){
Elite_led_color(COLOR_ORANGE);
}else if(INSTRUCTION.AdcChannel == VOUT_DAC){
Elite_led_color(COLOR_BLUE);
}
break;
}
// case VIS_RST: {
// LEDPowerON();
// break;
// }
default: {
WORKLED();
break;
}
}
}
@@ -0,0 +1,98 @@
#ifndef ELITELSV
#define ELITELSV
#define Vset INSTRUCTION.Vset
static uint16_t LSVCurve(LSVMode *LSV){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
Vin = LSV->_measureVin * 200;//[5nV]
if(DACReset){
Vout = Vset + Vin;
DACReset = false;
}else{
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
InputNotify(NOTIFY_VOLT, RealV2);
int32_t RealV;
RealV = (int32_t)(Vout / 200);//[1uV]
InputNotify(NOTIFY_IMPEDANCE, RealV);
DAC_outputV(DACOutCode);
//
return DACOutCode;
}
static void LSV_Vscan(LSVMode *LSV){
NotifyCycleNumber = (INSTRUCTION.cycleNumber - LSV->_cycleNumber + 1);
if(vscanReset){
if(INSTRUCTION.directionInit == 1){
LSV->_direction_up = true;
LSV->_current_direction_up = true;
}else{
LSV->_direction_up = false;
LSV->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
LSV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
LSV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
Vset = LSV->_Vinit;
}
if(!vscanReset){
if (LSV->_current_direction_up){
Vset = Vset + LSV->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - LSV->_Vstep * GPT.GptimerMultiple;
}
/*stop condition*/
if (Vset >= LSV->_Vmax){
ModeLED(POST_WORK);
// PeriodicEvent = false;
Vset = LSV->_Vmin;
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
}else if (Vset <= LSV->_Vmin){
ModeLED(POST_WORK);
// PeriodicEvent = false;
Vset = LSV->_Vmax;
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
}
}
}
#endif
@@ -8,25 +8,59 @@
#define ELITENOTIFY
#include "headstage.h"
#include <string.h>
/*notify's input type*/
#define NOTIFY_CURRENT 0
#define NOTIFY_VOLT 1
#define NOTIFY_IMPEDANCE 2
#define NOTIFY_VOLT_BAT 3
#define NOTIFY_TEMPERATURE 4
#define NOTIFY_CURRENT 0
#define NOTIFY_VOLT 1
#define NOTIFY_IMPEDANCE 2
#define NOTIFY_VOLT_BAT 3
#define FINISH_MODE_INS 0b10100000
#define NOT_BUF_OFFSET_INIT 8
/**
* the index where to start insert data into buffer.
* start from 6.
*/
static size_t not_buf_offset = NOT_BUF_OFFSET_INIT;
static uint32_t not_time_stamp;
static uint8_t NotifyCurrent[4] = {0};
static uint8_t NotifyVolt[4] = {0};
static uint8_t NotifyImpedance[4] = {0};
static uint16_t NotifyVoltBat = 0;
static uint16_t NotifyTemperature = 0;
static uint8_t NotifyVoltBat[4] = {0};
static uint16_t NotifyCycleNumber = 0;
static bool finishMode = false;
// ****************** New Notify Format ******************************** //
/*
* Notify format
*
*
| | 1 | 2 | 3 |
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
-----------------------------------------------------------------
| header |
| current |
| voltage or impedance |
| mode & gain |
| time stamp |
| cycle number |
mode & gain
this byte include Elite working mode and ADC gain level
we use "(mode & 0xF0) | (gain & 0x0F)" to encode these two information
cycle number
for cyclic voltammetry use, we save it as channel number.
0xFF
* header = device ID
* I = current (0.001nA), V = voltage (mV),
* Z = impedance (k ohm), T = time (ms)
*
*
*/
// ********* End New Format Notify ***************************************** //
/*
* Notify format
@@ -53,37 +87,32 @@ static bool finishMode = false;
*
*/
static void SendNotify() {
static uint8_t notify_times = 0;
uint32_t bat = NotifyVoltBat;
initDATBuf();
not_buf[0] = INSTRUCTION.chip_id;
for (int i = 0; i < 4; i++) {
not_buf[i + 1] = NotifyCurrent[i];
not_buf[i + 5] = NotifyVolt[i];
not_buf[i + 9] = NotifyImpedance[i];
}
// 1 Timestamp = 32 usec; 31 Timestamp ~= 1 msec
not_time_stamp = (Timestamp_get32()) / 31; // msec
not_buf[0] = instru.chip_id;
not_buf[13] = not_time_stamp & 0xff;
not_buf[14] = (not_time_stamp >> 8) & 0xff;
not_buf[15] = (not_time_stamp >> 16) & 0xff;
not_buf[16] = (not_time_stamp >> 24) & 0xff;
memcpy(not_buf+1, (uint8_t *)&not_time_stamp, sizeof(not_time_stamp));
memcpy(not_buf+5, NotifyCurrent, sizeof(NotifyCurrent));
memcpy(not_buf+9, NotifyVolt, sizeof(NotifyVolt));
memcpy(not_buf+13, NotifyImpedance, sizeof(NotifyImpedance));
memcpy(not_buf+17, (uint8_t *)&NotifyCycleNumber, sizeof(NotifyCycleNumber));
not_buf[17] = (NotifyCycleNumber >> 8) & 0xff;
not_buf[18] = NotifyCycleNumber & 0xff;
if (finishMode) {
not_buf[19] = (FINISH_MODE_INS) & 0b11110000;
} else {
not_buf[19] = 0 & 0b11110000;
}
memcpy(not_buf+20, (uint8_t *)&bat, sizeof(bat));
memcpy(not_buf+24, &notify_times, sizeof(notify_times));
for (int i = 25; i < BLE_DAT_BUFF_SIZE; i++){
for (int i = 19; i < BLE_DAT_BUFF_SIZE; i++){
not_buf[i] = 0;
}
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
notify_times++;
}
static void initDATBuf(){
@@ -107,7 +136,6 @@ static void initCISBuf(){
static void initRawDataBuf(){
not_time_stamp = 0;
NotifyCycleNumber = 0;
finishMode = false;
for (int i = 0; i < 4; i++){
NotifyCurrent[i] = 0;
@@ -120,7 +148,7 @@ static void FlushNotify(){
initRawDataBuf();
initDATBuf();
not_buf[0] = instru.chip_id;
not_buf[0] = INSTRUCTION.chip_id;
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
}
@@ -129,22 +157,31 @@ static void InputNotify(int NotifyType, int32_t Data){
switch (NotifyType) {
case NOTIFY_CURRENT:
memcpy(NotifyCurrent, (uint8_t *)&Data, sizeof(Data));
NotifyCurrent[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyCurrent[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyCurrent[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t)(Data & 0x000000FF);
break;
case NOTIFY_IMPEDANCE:
memcpy(NotifyImpedance, (uint8_t *)&Data, sizeof(Data));
NotifyImpedance[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyImpedance[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyImpedance[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyImpedance[3] = (uint8_t)(Data & 0x000000FF);
break;
case NOTIFY_VOLT :
memcpy(NotifyVolt, (uint8_t *)&Data, sizeof(Data));
NotifyVolt[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyVolt[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyVolt[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyVolt[3] = (uint8_t)(Data & 0x000000FF);
break;
case NOTIFY_VOLT_BAT :
NotifyVoltBat = (uint16_t)Data;
break;
case NOTIFY_TEMPERATURE :
NotifyTemperature = (uint16_t)Data;
NotifyVoltBat[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyVoltBat[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyVoltBat[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyVoltBat[3] = (uint8_t)(Data & 0x000000FF);
break;
}
}
@@ -0,0 +1,112 @@
#ifndef ELITEPULSE
#define ELITEPULSE
#define Vset INSTRUCTION.Vset
static void PULSE_Vscan(PULSEMode *PULSE)
{
static uint16_t lastVolt;
if (stiFirstTime) {
stiFirstTime = false;
lastVolt = 25000;
PULSE->_sti_t_flag = 1;
PULSE->_sti_v = PULSE->_sti_v1;
PULSE->_sti_t = PULSE->_sti_t1;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
} else if(!stiFirstTime) {
if (GPT.StiCounter >= PULSE->_sti_t) {
GPT.StiCounter -= PULSE->_sti_t; //to get right time
if (PULSE->_sti_lp > 0) {
if (PULSE->_sti_cy > 0) {
if (PULSE->_sti_t_flag == 1) {
PULSE->_sti_t_flag = 2;
PULSE->_sti_v = PULSE->_sti_v2;
PULSE->_sti_t = PULSE->_sti_t2;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 2) {
PULSE->_sti_t_flag = 3;
PULSE->_sti_v = PULSE->_sti_v3;
PULSE->_sti_t = PULSE->_sti_t3;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 3) {
PULSE->_sti_cy -- ;
if (PULSE->_sti_cy == 0) {
PULSE->_sti_t_flag = 4;
PULSE->_sti_v = PULSE->_sti_v4;
PULSE->_sti_t = PULSE->_sti_t4;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
} else {
PULSE->_sti_t_flag = 2;
PULSE->_sti_v = PULSE->_sti_v2;
PULSE->_sti_t = PULSE->_sti_t2;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
}
}
} else if (PULSE->_sti_cy <= 0){
if (PULSE->_sti_t_flag == 4) {
PULSE->_sti_lp -- ;
if (PULSE->_sti_lp > 0) {
PULSE->_sti_cy = INSTRUCTION.sti_cy;
PULSE->_sti_t_flag = 2;
PULSE->_sti_v = PULSE->_sti_v2;
PULSE->_sti_t = PULSE->_sti_t2;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
} else {
PULSE->_sti_t_flag = 5;
PULSE->_sti_v = PULSE->_sti_v5;
PULSE->_sti_t = PULSE->_sti_t5;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
}
}
}
} else if (PULSE->_sti_lp <= 0) {
if (PULSE->_sti_t_flag == 5) {
PULSE->_sti_t_flag = 6;
PULSE->_sti_v = PULSE->_sti_v6;
PULSE->_sti_t = PULSE->_sti_t6;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 6) {
PULSE->_sti_t_flag = 7;
PULSE->_sti_v = PULSE->_sti_v7;
PULSE->_sti_t = PULSE->_sti_t7;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 7) {
PULSE->_sti_v = 25000;
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}
}
}
if (lastVolt != PULSE->_sti_v) {
lastVolt = PULSE->_sti_v;
//if (PULSE->_sti_v == 25000) {
// PIN15_setOutputValue(HIGH_Z_MODE, 0); // 1 => close high_z mode
//} else {
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
//}
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, PULSE->_sti_v));
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, PULSE->_sti_v));
}
}
#endif
@@ -3,22 +3,25 @@
#define ELITERESET
static void reset() {
megaStiEnable = false;
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
megaStiEnable = false;
ModeLED(NO_EVENT);
InitEliteFlag();
InitFlag();
InitCT();
InitGPT();
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 0 => open high_z mode
VinADCGainControl(VIN_GAIN_AUTO);
IinADCGainControl(I_GAIN_AUTO);
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
initINSBuf();
initDATBuf();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
VinADCGainCtrl(VIN_GAIN_AUTO);
IinADCGainCtrl(I_GAIN_AUTO);
instru.VoutGainLv = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLv);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
for (int i = 0; i < SPI_LED_SIZE; i++) {
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
@@ -34,24 +37,26 @@ static void reset() {
spi_ADC_rxbuf[i] = 0;
}
ModeLED(NO_EVENT);
CPUdelay(1600);
}
static void Eliteinterrupt() {
megaStiEnable = false;
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
megaStiEnable = false;
ModeLED(NO_EVENT);
InitFlag();
InitEliteFlag();
InitCT();
InitGPT();
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 0 => open high_z mode
// INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
// VoutGainControl(INSTRUCTION.VoutGainLevel);
// DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
initINSBuf();
initDATBuf();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
instru.VoutGainLv = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLv);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
for (int i = 0; i < SPI_LED_SIZE; i++) {
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
@@ -67,7 +72,6 @@ static void Eliteinterrupt() {
spi_ADC_rxbuf[i] = 0;
}
ModeLED(NO_EVENT);
CPUdelay(8000);
}
#endif
@@ -42,14 +42,14 @@ static void ELITE15_SPI_CLOSE();
static void Elite_SPI_init(){
SPI_init();
SPI_Params_init(&spiParams0);
spiParams0.bitRate = 10000000; // 10M
spiParams0.bitRate = 2000; // 12k
spiParams0.mode = SPI_MASTER;
spiParams0.dataSize = 16;
spiParams0.frameFormat = SPI_POL0_PHA1;
spiHandle0 = SPI_open(Board_SPI0, &spiParams0); // LED SPI
SPI_Params_init(&spiParams1);
spiParams1.bitRate = 10000000; // 10M
spiParams1.bitRate = 1000000; // 1M
spiParams1.mode = SPI_MASTER;
spiParams1.dataSize = 8;
spiParams1.frameFormat = SPI_POL0_PHA1;
@@ -98,11 +98,10 @@ static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
static void ELITE15_SPI_HOLD() {
Elite_SPI_init();
#ifdef ELITE_PIN_1_5_RE
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]); // ADC_CS
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]); // DAC_CS
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]); // update HIGH_Z_MODE
#endif
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, LOAD1, 0);
@@ -0,0 +1,21 @@
#ifndef ELITEZT
#define ELITEZT
// output a certain voltage e.g. 2v
// and measure the input voltage
// => calculate the resister
// change the output voltage step
// => get a R-T curve (with resolution = 1 sample/volt step )
static void ZT_Vscan(RTMode *RT){
if(vscanReset){
Vset = ((int32_t)(INSTRUCTION.VoltConstant) - 25000) * 4 * 10000; //[5nV]
OneWayVoltScan();
}
if(!vscanReset){
}
}
#endif
@@ -6,9 +6,6 @@
#include <Board.h>
#include <ti/drivers/PIN.h>
//#define ELITE_PIN_1_5
#define ELITE_PIN_1_5_RE
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI D1
@@ -20,6 +17,7 @@
#define Board_SPI1_CLK D2
#define Board_SPI1_CS PIN_UNASSIGNED
//#define clk_test_pin IOID_0
#define D0 IOID_3
#define D1 IOID_4
#define D2 IOID_5
@@ -39,24 +37,15 @@
#define ADC_DAC_SPI_CLK LOAD0, D2
#define LED_MOSI LOAD0, D1
#define LED_CLK LOAD0, D0
#define MEM_CS LOAD0, D5
#ifdef ELITE_PIN_1_5
#define MEM_HOLD LOAD0, D4
#define HIGH_Z_MODE LOAD2, D5
#endif
#ifdef ELITE_PIN_1_5_RE
#define MEM_HOLD LOAD1, D0
#define HIGH_Z_MODE LOAD0, D4
#endif
#define MEM_CS LOAD0, D5
#define Turnon_I_MID LOAD2, D0
#define Turnon_I_SMALL LOAD2, D4
#define Turnon_I_LARGE LOAD2, D1
#define Turnon_V_SMALL LOAD2, D2
#define Turnon_V_MID LOAD2, D3
#define Turnon_VOUT_SMALL LOAD2, D7
#define shutdown_6994 LOAD2, D6
#define Turon_VOUT_SMALL LOAD2, D7
//#define Turnon10K Turnon_I_MID
//#define Turnon200R Turnon_I_LARGE
@@ -67,9 +56,12 @@
#define Board_I2C0_SDA0 PIN_UNASSIGNED
#endif
#define shutdown_6994 LOAD2, D6
#define switch_on IOID_14
//#define HIGH_Z_MODE LOAD2, D5
#define enable_10v LOAD1, D5
#define enable_5v LOAD1, D6
#define MEM_HOLD LOAD1, D0
PIN_Handle pin_handle;
static PIN_State ZM_rst;
@@ -84,6 +76,8 @@ const PIN_Config BLE_IO[] = {
D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// clk_test_pin | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
@@ -2,7 +2,7 @@
***********************************************************
Read battery's method
***********************************************************
1.read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
1.ReadADCBat(spi_ADC_rxbuf)
let "spi_ADC_rxbuf" be 8000
8000 * 187.5uV * 2 = 3000000uV = 3V ;
2.AONBatMonBatteryVoltageGet()
@@ -34,48 +34,40 @@ static uint8_t headstage_battery_percent() {
static void headstage_battery_volt(){
uint32_t bat_volt = 0;
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
ReadADCBat(spi_ADC_rxbuf);
bat_volt = (uint32_t) (spi_ADC_rxbuf[0] << 8) | (uint32_t) (spi_ADC_rxbuf[1]);
bat_volt = bat_volt * 12 / 125; //x * 187.5 * 1e-6 * 2 / 125 * 320 * 100 ;
// bat_volt = (bat_volt - 1) * 187.5 * 2;
InputNotify(NOTIFY_VOLT_BAT, bat_volt);
}
static void headstage_temperature(void) {
int32_t curTemp = 0;
curTemp = AONBatMonTemperatureGetDegC();
InputNotify(NOTIFY_TEMPERATURE,curTemp);
}
static bool EliteADCBattery(){
static void EliteADCBattery(){
static uint8_t ADCSwitch = 0;
bool read_adc_flag = false;
if(ADCSwitch == 0){ /**read V**/
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read V**/
read_adc_raw_data(RIS_ADC_BAT, spi_ADC_rxbuf, spi_ADC_txbuf);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read V(buffer)**/
headstage_battery_volt();
headstage_temperature();
ADCSwitch++;
read_adc_flag = true;
}else if(ADCSwitch == 3){
batteryCheck_flag = false;
tempCheck_flag = false;
if(INSTRUCTION.eliteFxn == ADC_TEST){
ADCSwitch = 0;
}else{
if(ADCSwitch == 0){ /**read V**/
ReadADCBat(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read V**/
ReadADCBat(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read V(buffer)**/
headstage_battery_volt();
batteryCheck_flag = false;
ADCSwitch = 0;
}
}
return read_adc_flag;
}
static void measureBat(){
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
if(GPT.BatteryCheckCounter >= 50000){//5min=3000000, 5s=50000
GPT.BatteryCheckCounter = 0;
batteryCheck_flag = true;
@@ -90,7 +82,8 @@ static void measureBat(){
}
}
uint16_t bat = NotifyVoltBat;
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
PIN15_setOutputValue(enable_5v, 0);
}
@@ -20,49 +20,31 @@
#define VIS_CC_ZERO 0x40
// RIS (real instruction)
enum all_mode_e {
CURVE_IV = 0x01, // I-V Curve //0x10,
CURVE_IV_CY = 0x02, // Cycle I-V //0x20,
CURVE_VO = 0x03, // Function Generator //0x30,
CURVE_RT = 0x04, // R-T Graph //0x40,
CURVE_VT = 0x05, // V-T Graph //0x50,
CURVE_IT = 0x06, // I-T Graph //0x60,
CURVE_CC = 0x07, // Constant Current (CC) //0xD0,
CURVE_OCP = 0x08, // Open Circuit Potential (OCP)
CURVE_CV = 0x09, // Cyclic Voltammetry (CV) //0xC0,
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV) //0x02,
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA) //0x03,
CURVE_PULSE = 0x0C, //0x94,
CURVE_UNI_PULSE = 0x0D, // universal pulse
CURVE_DPV = 0x0E,
CURVE_DPV_SMPRATE = 0x0F,
CURVE_DPV_ADVANCE = 0x10,
CURVE_DPV_ADVANCE_SMPRATE = 0x11,
CURVE_CALI_ADC = 0xF1, // Cali ADC - test //0x92,
SET_SAMPLE_RATE = 0xE0, //0x70,
SET_ADC_DAC_GAIN = 0xE1, //0x80,
SET_PARA = 0xE2
};
enum set_para_e {
DAC_VOLT = 0x01,
};
enum dev_para_e {
VERSION_DEV_TEST = 0x01,
BAT_DEV_TEST = 0x02,
TEMP_DEV_TEST = 0x03,
LED_DEV_TEST = 0x04,
};
#define IV_CURVE 0x10
#define CV_CURVE 0x20
#define VOLT_OUTPUT 0x30
#define ZT_CURVE 0x40
#define VT_CURVE 0x50
#define IT_CURVE 0x60
#define SET_SAMPLE_RATE 0x70
#define SET_ADC_DAC_GAIN 0x80
#define DIFFERENTIAL_PULSE_VOLTAMMETRY 0xA0
#define SQUARE_WAVE_VOLTAMMETRY 0xB0
#define CYCLIC_VOLTAMMETRY 0xC0
#define CONSTANT_CURRENT 0xD0
#define CYCLE_CONSTANT_CURRENT 0xF0
#define HIGH_CYCLE_CYCLIC_VOLTAMMETRY 0x01
#define LINEAR_SWEEP_VOLTAMMETRY 0x02
#define CONSTANT_VSCAN 0x03
#define ADC_TEST 0x91
#define CALI_DAC_MODE 0x93
#define CALI_ADC_MODE 0x92
#define PULSE_MODE 0x94
// CIS (control instruction)
#define CIS_VERSION 0x40
#define CIS_VOLT 0x10
#define CIS_TEMPERATURE 0x80
#define CIS_LED_TEST 0x70
// mode parameter
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
@@ -71,6 +53,24 @@ enum dev_para_e {
#define VDIRECTION(v1,v2) ((v1 > v2) ? 0 : 1)
#define AFTER_READ_I 0
#define AFTER_READ_V 1
#define ReadADCVolt(x) ((x==0)? ReadADCVout(spi_ADC_rxbuf) : ReadADCVin(spi_ADC_rxbuf))
#define PARA_1 0x01
#define PARA_2 0x02
#define PARA_3 0x03
#define PARA_4 0x04
#define PARA_5 0x05
#define PARA_6 0x06
#define PARA_7 0x07
#define PARA_8 0x08
#define PARA_9 0x09
#define PARA_10 0x0A
#define PARA_11 0x0B
#define PARA_12 0x0C
#define PARA_13 0x0D
#define PARA_14 0x0E
#define PARA_15 0x0F
#define PARA_16 0x10
#define PARA_17 0x11
//Elite LED
#define COLOR_BLACK 0x00
@@ -84,12 +84,6 @@ enum dev_para_e {
#define COLOR_PURPLE 0x08
#define COLOR_WHITE 0x09
#define COLOR_YELLOWGREEN 0x0A
#define COLOR_YELLOW_DARK 0xF3
#define COLOR_GREEN_DARK 0xF4
#define COLOR_BLUE_DARK 0xF5
#define COLOR_CYAN_DARK 0xF6
#define COLOR_PURPLE_DARK 0xF8
#define LEDPowerON() Elite_led_color(COLOR_GREEN)
#define WORKLED() Elite_led_color(COLOR_CYAN)
#define KEYLED() Elite_led_color(COLOR_YELLOW)
@@ -103,14 +97,4 @@ enum dev_para_e {
#define POST_WORK 0x05
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
//plot_type
#define IT_PLOT 1
#define VT_PLOT 2
#define VOUT_PLOT 3
#define IIN_VIN_PLOT 4
#define IIN_VIN_VOUT_PLOT 5
#define CLOCK_ONE_SECOND 10000
#endif
@@ -2,10 +2,10 @@
#ifndef VERSION_DATE
#define VERSION_DATE
#define VERSION_DATE_YEAR 22
#define VERSION_DATE_MONTH 4
#define VERSION_DATE_DAY 13
#define VERSION_DATE_HOUR 14
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 12
#define VERSION_DATE_DAY 10
#define VERSION_DATE_HOUR 17
#define VERSION_DATE_MINUTE 16
// this is NOT the version hash !!
@@ -30,12 +30,6 @@
#define SPI_BUFFER_SIZE 16
/**
* the pointer to point which channel is used currently.
* -1 for not beginning.
*/
static int8 channel_pointer = -1;
static uint8_t spi_txbuf[SPI_BUFFER_SIZE] = {0};
static uint8_t spi_rxbuf[SPI_BUFFER_SIZE] = {0};
@@ -135,16 +129,16 @@ static void update_ins_sti_channel(uint8_t *buf, uint8 sti_chp, uint8 sti_chn) {
static void update_ins_buffer() {
uint8 header = 0b10100000;
uint8 amp_gain = (instru.amp_gain & 0b11) << 3;
uint8 amp_lbf = instru.amp_low_band_freq & 0b111;
uint8 amp_gain = (INSTRUCTION.amp_gain & 0b11) << 3;
uint8 amp_lbf = INSTRUCTION.amp_low_band_freq & 0b111;
uint8 channel = 0; // should be call update_ins_channel to modify this value
uint8 chopper = (instru.chopper) ? 0b00001000 : 0;
uint8 fast_settle = (instru.fast_settle) ? 0b00000100 : 0;
uint8 sti_enable = (instru.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
uint8 sti_volt_l = (instru.sti_volt & 0b11111) >> 4;
uint8 sti_volt_h = (instru.sti_volt & 0b01111) << 4;
uint8 sti_chp = instru.sti_channel_pmos & 0b1111;
uint8 sti_chn = (instru.sti_channel_nmos & 0b1111) << 4;
uint8 chopper = (INSTRUCTION.chopper) ? 0b00001000 : 0;
uint8 fast_settle = (INSTRUCTION.fast_settle) ? 0b00000100 : 0;
uint8 sti_enable = (INSTRUCTION.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
uint8 sti_volt_l = (INSTRUCTION.sti_volt & 0b11111) >> 4;
uint8 sti_volt_h = (INSTRUCTION.sti_volt & 0b01111) << 4;
uint8 sti_chp = INSTRUCTION.sti_channel_pmos & 0b1111;
uint8 sti_chn = (INSTRUCTION.sti_channel_nmos & 0b1111) << 4;
uint8 clk_signal = 0; // should be call update_ins_clock to modify this value
spi_txbuf[0] = header | amp_gain | amp_lbf;
@@ -199,7 +193,7 @@ static bool update_ins_rec_buffer() {
* @param: buf: pointer of the SPI buffer.
*/
static void update_ins_sti_buffer() {
switch (instru.work_mode) {
switch (INSTRUCTION.work_mode) {
case STI_MODE_POS:
case STI_MODE_NEG:
// copy [4:7]
@@ -221,7 +215,7 @@ static void update_ins_sti_buffer() {
update_ins_sti_enable(spi_txbuf, TRUE);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, 0xF, instru.sti_channel_pmos);
update_ins_sti_channel(spi_txbuf + 4, 0xF, INSTRUCTION.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, FALSE);
break;
@@ -244,13 +238,13 @@ static void update_ins_sti_buffer() {
spi_txbuf[15] = spi_txbuf[3];
// change content
update_ins_sti_enable(spi_txbuf + 0, TRUE);
update_ins_sti_channel(spi_txbuf + 0, instru.sti_channel_pmos, instru.sti_channel_nmos);
update_ins_sti_channel(spi_txbuf + 0, INSTRUCTION.sti_channel_pmos, INSTRUCTION.sti_channel_nmos);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, instru.sti_channel_nmos, instru.sti_channel_pmos);
update_ins_sti_channel(spi_txbuf + 4, INSTRUCTION.sti_channel_nmos, INSTRUCTION.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, TRUE);
update_ins_sti_channel(spi_txbuf + 8, 0xF, instru.sti_channel_nmos);
update_ins_sti_channel(spi_txbuf + 8, 0xF, INSTRUCTION.sti_channel_nmos);
// ins buf [C:F]
update_ins_sti_enable(spi_txbuf + 12, FALSE);
break;
@@ -287,12 +281,12 @@ static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t
}
static uint8_t *spi_transact_rec_instruction() {
if (IS_REC_MODE(instru.work_mode)) {
if (IS_REC_MODE(INSTRUCTION.work_mode)) {
PIN_setOutputValue(pin_handle, IOID_13, 1); // DBS_P2S turn on
headstage_spi_transaction(SPI_BUFFER_SIZE, spi_txbuf, spi_rxbuf);
PIN_setOutputValue(pin_handle, IOID_13, 0); // DBS_P2S turn off
} else if (IS_ARM_MODE(instru.work_mode) && !adc_clock_signal) {
} else if (IS_ARM_MODE(INSTRUCTION.work_mode) && !adc_clock_signal) {
create_ramp(spi_rxbuf);
}
@@ -1,879 +0,0 @@
#ifndef SCAN_VOLT_H
#define SCAN_VOLT_H
#ifdef __cplusplus
extern "C" {
#endif
#define Vset instru.Vset
static void iv_vscan(void)
{
struct wm_iv_ctx_t *iv = (struct wm_iv_ctx_t *)wm_get();
if (vscanReset) {
if (instru.directionInit == 1) {
iv->_direction_up = true;
iv->_current_direction_up = true;
} else if (instru.directionInit == 0) {
iv->_direction_up = false;
iv->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if (instru.step <= 10) {
iv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
iv->_Vstep = instru.step / 5 * instru.VsetRate;
}
Vset = iv->_Vinit;
}
if (!vscanReset) {
if (iv->_current_direction_up) {
if (Vset >= iv->_Vmax) {
PeriodicEvent = false;
}
} else {
if (Vset <= iv->_Vmin) {
PeriodicEvent = false;
}
}
if (iv->_current_direction_up) {
Vset = Vset + iv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - iv->_Vstep * GPT.GptimerMultiple;
}
}
return;
}
static void iv_cy_vscan(void)
{
struct wm_iv_cy_ctx_t *iv_cy = (struct wm_iv_cy_ctx_t *)wm_get();
static bool VminCounter;
static bool VmaxCounter;
NotifyCycleNumber = (instru.cycleNumber - iv_cy->_cycleNumber + 1);
if(vscanReset){
VmaxCounter = false;
VminCounter = false;
if(instru.directionInit == 1){
iv_cy->_direction_up = true;
iv_cy->_current_direction_up = true;
}else if(instru.directionInit == 0){
iv_cy->_direction_up = false;
iv_cy->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(instru.step <= 10){
iv_cy->_Vstep = instru.step * instru.VsetRate / 5;
}else{
iv_cy->_Vstep = instru.step / 5 * instru.VsetRate;
}
if(iv_cy->_Vmin == iv_cy->_Vinit){
VminCounter = true;
}
if(iv_cy->_Vmax == iv_cy->_Vinit){
VmaxCounter = true;
}
Vset = iv_cy->_Vinit;
}
if(!vscanReset){
if (Vset >= iv_cy->_Vmax){
VmaxCounter = true;
}else if (Vset <= iv_cy->_Vmin){
VminCounter = true;
}
if (iv_cy->_current_direction_up){
Vset = Vset + iv_cy->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - iv_cy->_Vstep * GPT.GptimerMultiple;
}
if(VmaxCounter && VminCounter){
if(iv_cy->_direction_up && iv_cy->_current_direction_up){
if(Vset >= iv_cy->_Vinit){
iv_cy->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
if(!iv_cy->_direction_up && !iv_cy->_current_direction_up){
if(Vset <= iv_cy->_Vinit){
iv_cy->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
}
if (Vset >= iv_cy->_Vmax){
iv_cy->_current_direction_up = false;
}else if (Vset <= iv_cy->_Vmin){
iv_cy->_current_direction_up = true;
}
/*stop condition*/
if(iv_cy->_cycleNumber == 0){
PeriodicEvent = false;
}
}
return;
}
static void it_vscan(void)
{
struct wm_it_ctx_t *it = (struct wm_it_ctx_t *)wm_get();
if (vscanReset) {
Vset = it->_Vinit;
}
if(!vscanReset) {
Vset = it->_Vinit;
}
return;
}
static void rt_vscan(void)
{
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
if (vscanReset) {
Vset = rt->_Vinit;
}
if(!vscanReset) {
Vset = rt->_Vinit;
}
return;
}
static void vo_vscan(void)
{
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
if (vscanReset) {
Vset = vo->_Vinit;
}
if(!vscanReset) {
Vset = vo->_Vinit;
}
return;
}
#define DELTAVOLTMAX 2000000 //2000000 = 10mV
static void cc_vscan(void)
{
/* Transform setting CC into IUC
*
* User code in CC mode : 0 ~ 3000000
* Real current value : -15.00000 ~ 15.00000 mA
* => user code = 1500000 mapping to 0.00000 mA
*/
struct wm_cc_ctx_t *cc = (struct wm_cc_ctx_t *)wm_get();
struct wm_meas_t *m = &cc->measure;
uint16_t divisionRate;
int32_t deltaI;
int32_t deltaV;
int32_t Iin;
int32_t Vin;
if (vscanReset) {
Vset = 0;
if (cc->_charge == 0) {
cc->_Iset = instru.constantCurrent * 200 * (-1);
//[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA];
}
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
Vin = m->_measureVin * 200; //[5nV]
Vset = Vin + cc->_Iset; //[5nV]
if (Vset >= 1100000000) { // 5.5V
Vset = 1100000000;
} else if (Vset <= -1000000000) { //-5V
Vset = -1000000000;
}
}
if (!vscanReset) {
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - cc->_Iset;
if (deltaI > 2000000 || deltaI < -2000000) { //100uA
divisionRate = 1;
} else {
divisionRate = 20;
}
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
if (deltaV > DELTAVOLTMAX) { //2000000 = 10mV
deltaV = DELTAVOLTMAX;
} else if (deltaV < (-DELTAVOLTMAX)) {
deltaV = (-DELTAVOLTMAX);
}
Vset = Vset + deltaV; //[5nV]
if (Vset >= 1100000000) { // 5.5V
Vset = 1100000000;
} else if (Vset <= -1000000000) { //-5V
Vset = -1000000000;
}
if (Vset <= cc->_Vmin) {
Vset = cc->_Vmin;
} else if (Vset >= cc->_Vmax) {
Vset = cc->_Vmax;
}
}
return;
}
static void cv_vscan(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static bool VminCounter;
static bool VmaxCounter;
NotifyCycleNumber = (instru.cycleNumber - cv->_cycleNumber + 1);
if (vscanReset) {
VmaxCounter = false;
VminCounter = false;
if (instru.directionInit == 1) {
cv->_direction_up = true;
cv->_current_direction_up = true;
} else {
cv->_direction_up = false;
cv->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if (instru.step <= 10) {
cv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
cv->_Vstep = instru.step / 5 * instru.VsetRate;
}
if (cv->_Vmin == cv->_Vinit) {
VminCounter = true;
}
if (cv->_Vmax == cv->_Vinit) {
VmaxCounter = true;
}
Vset = cv->_Vinit;
}
if (!vscanReset) {
if ((instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) ||
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
) {
if (cv->_current_direction_up) {
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
}
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
if (Vset == cv->_Vmin) {
VminCounter = true;
instru.Vinit = instru.Vmin;
cv->_Vinit = cv->_Vmin;
}
} else if (instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2) {
if (Vset == cv->_Vmax) {
VmaxCounter = true;
instru.Vinit = instru.Vmax;
cv->_Vinit = cv->_Vmax;
}
}
} else {
if (Vset >= cv->_Vmax) {
VmaxCounter = true;
} else if (Vset <= cv->_Vmin) {
VminCounter = true;
}
if (cv->_current_direction_up) {
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
}
if (VmaxCounter && VminCounter) {
if (cv->_direction_up && cv->_current_direction_up) {
if (Vset >= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
if (!cv->_direction_up && !cv->_current_direction_up) {
if (Vset <= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
}
if (Vset >= cv->_Vmax) {
cv->_current_direction_up = false;
} else if (Vset <= cv->_Vmin) {
cv->_current_direction_up = true;
}
/*stop condition*/
if (cv->_cycleNumber == 0) {
PeriodicEvent = false;
}
}
}
return;
}
static void lsv_vscan(void)
{
struct wm_lsv_ctx_t *lsv = (struct wm_lsv_ctx_t *)wm_get();
NotifyCycleNumber = (instru.cycleNumber - lsv->_cycleNumber + 1);
if (vscanReset) {
if (instru.directionInit == 1) {
lsv->_direction_up = true;
lsv->_current_direction_up = true;
} else {
lsv->_direction_up = false;
lsv->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if (instru.step <= 10) {
lsv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
lsv->_Vstep = instru.step / 5 * instru.VsetRate;
}
Vset = lsv->_Vinit;
}
if (!vscanReset) {
if (lsv->_current_direction_up) {
Vset = Vset + lsv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - lsv->_Vstep * GPT.GptimerMultiple;
}
/*stop condition*/
if (Vset >= lsv->_Vmax) {
PeriodicEvent = false;
} else if (Vset <= lsv->_Vmin) {
PeriodicEvent = false;
}
}
return;
}
static void ca_vscan(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
if(vscanReset){
Vset = ca->_Vinit;
}
if(!vscanReset){
Vset = ca->_Vinit;
}
return;
}
static void uni_pulse_vscan(uint32_t time)
{
uint32_t t = time;
struct wm_uni_pulse_ctx_t *p = (struct wm_uni_pulse_ctx_t *)wm_get();
uint32_t m;
uint32_t t_min;
uint32_t t_max;
if(vscanReset){
Vset = p->_v0;
return;
}
if(!vscanReset){
if (t == 0) {
m = 0;
} else {
m = t % p->_t_period;
}
if (m < p->_t_pa[0]) {
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t + p->_v_step[0] * (int32_t)(t / p->_t_period);
Vset = p->_Vset;
t_min = p->_t_pulse_min[0];
t_max = p->_t_pulse_max[0];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
return;
}
if (m < p->_t_pa[1]) {
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t + p->_v_step[1] * (int32_t)(t / p->_t_period);
Vset = p->_Vset;
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
return;
}
if (m < p->_t_pa[2]) {
p->_Vset = p->_v_initial[2] + p->_v_slope[2] * t + p->_v_step[2] * (int32_t)(t / p->_t_period);
Vset = p->_Vset;
t_min = p->_t_pa[1] + p->_t_pulse_min[2];
t_max = p->_t_pa[1] + p->_t_pulse_max[2];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
return;
}
if (m < p->_t_pa[3]) {
p->_Vset = p->_v_initial[3] + p->_v_slope[3] * t + p->_v_step[3] * (int32_t)(t / p->_t_period);
Vset = p->_Vset;
t_min = p->_t_pa[2] + p->_t_pulse_min[3];
t_max = p->_t_pa[2] + p->_t_pulse_max[3];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
return;
}
return;
}
return;
}
static void dpv_vscan(uint32_t time)
{
uint32_t t = time;
struct wm_dpv_ctx_t *p = (struct wm_dpv_ctx_t *)wm_get();
uint32_t m;
uint32_t t_min;
uint32_t t_max;
if(vscanReset){
Vset = p->_v0;
return;
}
if(!vscanReset){
if (t == 0) {
m = 0;
} else {
m = t % p->_t_period;
}
if (m < p->_t_pa[0]) {
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 + p->_v_step[0] * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
Vset = p->_Vset;
t_min = p->_t_pulse_min[0];
t_max = p->_t_pulse_max[0];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
if ((p->_v_curr_direc && Vset >= p->_v_stop) ||
(!p->_v_curr_direc && Vset <= p->_v_stop)) {
PeriodicEvent = false;
}
return;
}
if (m < p->_t_pa[1]) {
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t / 1000 + p->_v_step[1] * (int32_t)dpv_step_cnt;
Vset = p->_Vset;
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
return;
}
return;
}
return;
}
static void dpv_advance_vscan(uint32_t time)
{
uint32_t t = time;
struct wm_dpv_advance_ctx_t *p = (struct wm_dpv_advance_ctx_t *)wm_get();
uint32_t m;
uint32_t t_min;
uint32_t t_max;
static bool VminCounter;
static bool VmaxCounter;
if(vscanReset){
if (p->_v_direc_init) {
if (p->_v0 <= p->_v_up && p->_v0 <= p->_v_low && p->_v_2 > p->_v_1) {
VminCounter = true;
}
} else {
if (p->_v0 >= p->_v_up && p->_v0 >= p->_v_low && p->_v_1 > p->_v_2) {
VmaxCounter = true;
}
}
p->_Vset = p->_v0;
Vset = p->_Vset;
return;
}
if(!vscanReset){
if (t == 0) {
m = 0;
} else {
m = t % p->_t_period;
}
if (m < p->_t_pa[0]) {
t_min = p->_t_pulse_min[0];
t_max = p->_t_pulse_max[0];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 + p->_v_step[0] * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
Vset = p->_Vset;
if (VminCounter == true && VmaxCounter == true) {
p->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
if (p->_cycleNumber <= 0) {
if (p->_v_stop_direction == true && p->_Vset >= p->_v_stop - p->_v_amp + p->_v_step[0]) {
PeriodicEvent = false;
} else if (p->_v_stop_direction == false && p->_Vset <= p->_v_stop - p->_v_amp + p->_v_step[0]) {
PeriodicEvent = false;
}
}
if (p->_v_curr_direc && p->_Vset >= p->_v_up - p->_v_amp + p->_v_step[0]) {
if (p->_v_invert_option) {
p->_v_amp = p->_v_amp * (-1);
}
p->_v_initial[0] = p->_Vset;
p->_v_initial[1] = p->_v_initial[0] + p->_v_amp;
dpv_step_cnt = 0;
p->_v_step[0] = (-1) * p->_v_step[0];
p->_v_step[1] = (-1) * p->_v_step[1];
p->_v_curr_direc = false;
VmaxCounter = true;
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
Vset = p->_Vset;
} else if (!p->_v_curr_direc && p->_Vset <= p->_v_low - p->_v_amp + p->_v_step[0]) {
if (p->_v_invert_option) {
p->_v_amp = p->_v_amp * (-1);
}
p->_v_initial[0] = p->_Vset;
p->_v_initial[1] = p->_v_initial[0] + p->_v_amp;
dpv_step_cnt = 0;
p->_v_step[0] = (-1) * p->_v_step[0];
p->_v_step[1] = (-1) * p->_v_step[1];
p->_v_curr_direc = true;
VminCounter = true;
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
Vset = p->_Vset;
}
return;
}
if (m < p->_t_pa[1]) {
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t / 1000 + p->_v_step[1] * (int32_t)dpv_step_cnt;
Vset = p->_Vset;
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
if (m > t_min && m < t_max) {
calc_avg_en = true;
} else {
calc_avg_en = false;
}
return;
}
return;
}
return;
}
static void pulse_vscan(void)
{
struct wm_pulse_ctx_t *pulse = (struct wm_pulse_ctx_t *)wm_get();
static uint16_t lastVolt;
if (stiFirstTime) {
stiFirstTime = false;
lastVolt = 25000;
pulse->_sti_t_flag = 1;
pulse->_sti_v = pulse->_sti_v1;
pulse->_sti_t = pulse->_sti_t1;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if(!stiFirstTime) {
if (GPT.StiCounter >= pulse->_sti_t) {
GPT.StiCounter -= pulse->_sti_t; //to get right time
if (pulse->_sti_lp > 0) {
if (pulse->_sti_cy > 0) {
if (pulse->_sti_t_flag == 1) {
pulse->_sti_t_flag = 2;
pulse->_sti_v = pulse->_sti_v2;
pulse->_sti_t = pulse->_sti_t2;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (pulse->_sti_t_flag == 2) {
pulse->_sti_t_flag = 3;
pulse->_sti_v = pulse->_sti_v3;
pulse->_sti_t = pulse->_sti_t3;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (pulse->_sti_t_flag == 3) {
pulse->_sti_cy -- ;
if (pulse->_sti_cy == 0) {
pulse->_sti_t_flag = 4;
pulse->_sti_v = pulse->_sti_v4;
pulse->_sti_t = pulse->_sti_t4;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else {
pulse->_sti_t_flag = 2;
pulse->_sti_v = pulse->_sti_v2;
pulse->_sti_t = pulse->_sti_t2;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
}
}
} else if (pulse->_sti_cy <= 0){
if (pulse->_sti_t_flag == 4) {
pulse->_sti_lp -- ;
if (pulse->_sti_lp > 0) {
pulse->_sti_cy = instru.sti_cy;
pulse->_sti_t_flag = 2;
pulse->_sti_v = pulse->_sti_v2;
pulse->_sti_t = pulse->_sti_t2;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else {
pulse->_sti_t_flag = 5;
pulse->_sti_v = pulse->_sti_v5;
pulse->_sti_t = pulse->_sti_t5;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
}
}
}
} else if (pulse->_sti_lp <= 0) {
if (pulse->_sti_t_flag == 5) {
pulse->_sti_t_flag = 6;
pulse->_sti_v = pulse->_sti_v6;
pulse->_sti_t = pulse->_sti_t6;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (pulse->_sti_t_flag == 6) {
pulse->_sti_t_flag = 7;
pulse->_sti_v = pulse->_sti_v7;
pulse->_sti_t = pulse->_sti_t7;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (pulse->_sti_t_flag == 7) {
pulse->_sti_v = 25000;
PeriodicEvent = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
}
if (lastVolt != pulse->_sti_v) {
lastVolt = pulse->_sti_v;
//if (pulse->_sti_v == 25000) {
// PIN15_setOutputValue(HIGH_Z_MODE, 0); // 1 => close high_z mode
//} else {
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
//}
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
}
return;
}
static void chg_vo_para(uint16_t parameter, int32_t value)
{
uint16_t pa = parameter;
int32_t val = value;
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
if (pa == DAC_VOLT) {
vo->_Vinit = val;
}
return;
}
static void chg_it_para(uint16_t parameter, int32_t value)
{
uint16_t pa = parameter;
int32_t val = value;
struct wm_it_ctx_t *it = (struct wm_it_ctx_t *)wm_get();
if (pa == DAC_VOLT) {
it->_Vinit = val;
}
return;
}
static void chg_rt_para(uint16_t parameter, int32_t value)
{
uint16_t pa = parameter;
int32_t val = value;
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
if (pa == DAC_VOLT) {
rt->_Vinit = val;
}
return;
}
static void set_para(uint8_t eliteFxn, uint16_t parameter, int32_t value)
{
uint8_t mode = eliteFxn;
uint16_t pa = parameter;
int32_t val = value;
if (mode == CURVE_VO) {
chg_vo_para(pa, val);
return;
}
if (mode == CURVE_IT) {
chg_it_para(pa, val);
return;
}
if (mode == CURVE_RT) {
chg_rt_para(pa, val);
return;
}
return;
}
#endif
@@ -543,22 +543,31 @@ static void SimpleBLEPeripheral_init(void) {
// static void detectKey_clockHandler(UArg arg);
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
uint8_t key= 0;
bool EliteOn = 0;
uint16_t counter6994 = 0;
batteryADC_flag = false;
// Initialize application
SimpleBLEPeripheral_init();
ZM_init();
WorkMode *WorkModeData = CreateWorkMode();
// init DAC, set output ~= 0 V
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
uint8_t key = 0;
uint16_t counter6994 = 0;
bool EliteOn = 0;
elite_gptimer_start();
// Application main loops
GPT.GptimerCounter0 = GPT.GptimerCounter;
batteryADC_flag = false;
headstage_battery_volt();
headstage_init_device_info();
for (;;) {
// PIN_setOutputValue(pin_handle, clk_test_pin, clk_onoff); // test system clock frequency
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
@@ -605,33 +614,24 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
}
}
}
if(events & SBP_PERIODIC_EVT){
events &= ~SBP_PERIODIC_EVT;
if (!PeriodicEvent) { // if there is no periodic event
key = PIN_getInputValue(switch_on);
if (EliteOn) {
if (counter6994 < CLOCK_ONE_SECOND*5) { // counter6994 enable a IC after 35 counts
if (counter6994 < CLOCK_ONE_SECOND/2) { // counter6994 enable a IC after 35 counts
counter6994++;
} else if (counter6994 == CLOCK_ONE_SECOND*5) {
PIN15_setOutputValue(shutdown_6994, 0); // OFF = 1 => turn off 6994
} else if (counter6994 == CLOCK_ONE_SECOND/2) {
PIN15_setOutputValue(shutdown_6994, 1); // OFF = 1 => turn off 6994
counter6994++;
} else if (counter6994 > CLOCK_ONE_SECOND*5) {
counter6994 = 0;
}
EliteKeyPress(key);
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
if(key != 0){ //detect Elite battery power when no periodic event
measureBat();
}
if(Free_Work_Mode){
wm_deinit();
FreeWorkMode(WorkModeData);
InitEliteInstruction();
Free_Work_Mode = false;
}
@@ -641,12 +641,12 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
}
else { // if there is periodic event
if(InitPeriodicEvent){
wm_init();
InitWorkMode(WorkModeData);
InitPeriodicEvent = false;
}
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask();
SimpleBLEPeripheral_performPeriodicTask(WorkModeData);
key = PIN_getInputValue(switch_on);
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
}
@@ -925,16 +925,16 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
numActive = linkDB_NumActive();
uint16_t cxnHandle;
// requestedPDUSize = LL payload = L2CAP_header + ATT header + BLE_NOT_BUFF_SIZE = 7 + BLE_NOT_BUFF_SIZE //roy
uint16_t requestedPDUSize = 251; //251 roy
uint16_t requestTxTime = 2120; // (LL payload + 14) * 8 //2120 roy
GAPRole_GetParameter(GAPROLE_CONNHANDLE, &cxnHandle);
if (SUCCESS == HCI_LE_SetDataLenCmd(cxnHandle, requestedPDUSize, requestTxTime)) {
// LED_color(DARKLED, 0xFF, 0x00, 0xFF);
}
// uint16_t cxnHandle;
//
// // requestedPDUSize = LL payload = L2CAP_header + ATT header + BLE_NOT_BUFF_SIZE = 7 + BLE_NOT_BUFF_SIZE //roy
// uint16_t requestedPDUSize = 251; //251 roy
// uint16_t requestTxTime = 2120; // (LL payload + 14) * 8 //2120 roy
// GAPRole_GetParameter(GAPROLE_CONNHANDLE, &cxnHandle);
//
// if (SUCCESS == HCI_LE_SetDataLenCmd(cxnHandle, requestedPDUSize, requestTxTime)) {
//// LED_color(DARKLED, 0xFF, 0x00, 0xFF);
// }
// Use numActive to determine the connection handle of the last
// connection
@@ -975,7 +975,6 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
case GAPROLE_WAITING_AFTER_TIMEOUT:
SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
ModeLED(BT_WAIT);
#ifdef PLUS_BROADCASTER
// Reset flag for next connection.
@@ -84,7 +84,7 @@ extern "C"
// Length of Characteristic 5 in bytes
#define SIMPLEPROFILE_CHAR5_LEN 5
/*user insert*/
#define SIMPLEPROFILE_CHAR4_LEN 40
#define SIMPLEPROFILE_CHAR4_LEN 20
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR2_LEN 20
/*********************************************************************