Elite 1.4-re split every function into .h file
This commit is contained in:
+6
@@ -25,6 +25,7 @@ struct CURRENT_USER_CODE{
|
||||
|
||||
static int32_t CCModeReadCurrent(){
|
||||
int32_t Real_Current = 0;
|
||||
CCModeReset = 0; //
|
||||
|
||||
CCCurrent2IUC();
|
||||
// read ADC current
|
||||
@@ -42,6 +43,11 @@ static int32_t CCModeReadCurrent(){
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
static int32_t CCModeOutputDAC(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void SetCCModeGain(){
|
||||
switch(CurrentUserCode.lv){
|
||||
case CURRENT_LV_FOUR:{
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
|
||||
#ifndef ELITEIT
|
||||
#define ELITEIT
|
||||
|
||||
static int32_t IT_Plot() {
|
||||
// read ADC current
|
||||
int32_t Real_Current = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// check if ADC over/under flow
|
||||
// let the output saturate if over/under flow
|
||||
ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
#endif
|
||||
+24
-1
@@ -2,7 +2,30 @@
|
||||
#ifndef ELITEIV
|
||||
#define ELITEIV
|
||||
|
||||
static uint16_t IVCurve() {
|
||||
static uint16_t VoltScan() {
|
||||
uint16_t Voltage;
|
||||
if (INSTRUCTION.VoltOrigin == INSTRUCTION.VoltFinal) {
|
||||
// DAC_outputV(DACOUT, INSTRUCTION.VoltOrigin); //delete 'command' parameter
|
||||
DAC_outputV(INSTRUCTION.VoltOrigin);
|
||||
PeriodicEvent = false;
|
||||
return INSTRUCTION.VoltOrigin;
|
||||
} else if (INSTRUCTION.eliteFxn == SQUARE_WAVE_VOLTAMMETRY) {
|
||||
Voltage = SWVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) {
|
||||
Voltage = DPVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) {
|
||||
Voltage = CVCurve();
|
||||
}
|
||||
|
||||
// IV plot mode
|
||||
else {
|
||||
Voltage = OneWayVoltScan();
|
||||
}
|
||||
|
||||
return Voltage;
|
||||
}
|
||||
|
||||
static uint16_t OneWayVoltScan() {
|
||||
static uint16_t DACOutCode;
|
||||
|
||||
// reset origin volt at the begin
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
#ifndef ELITEVT
|
||||
#define ELITEVT
|
||||
|
||||
static void VT_Plot() {
|
||||
// ADC gain is don't care when measuring voltage
|
||||
uint8_t ADCGain = 1;
|
||||
|
||||
// read ADC volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
DecodeADCValue(ADCGain, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
#endif
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
|
||||
#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_Plot() {
|
||||
// read ADC current
|
||||
int32_t Real_Current = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// check if ADC over/under flow
|
||||
ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
Impedance_Calculate(INSTRUCTION.VoltConstant, Real_Current);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+8
-1
@@ -613,6 +613,13 @@ static int16_t avg_number = 0;
|
||||
static int32_t ADCRealCurrent = 0;
|
||||
static long long ADCRealCurrent_long = 0;
|
||||
|
||||
// Constant Current Mode function
|
||||
static CCModeReset = 1;
|
||||
static int32_t CCModeReadCurrent();
|
||||
static int32_t CCModeOutputDAC();
|
||||
static void SetCCModeGain();
|
||||
static void CCCurrent2IUC();
|
||||
|
||||
// for DPVCurve SWVCurve
|
||||
static uint16_t Amplitude;
|
||||
static uint8_t PulseWidth;
|
||||
@@ -640,7 +647,7 @@ static uint8_t OldStep2NewStep(uint8_t OldStep);
|
||||
static uint8_t OldStep2NewStepTime(uint8_t StepTime);
|
||||
static uint8_t IVdone = 0;
|
||||
|
||||
static uint16_t IVCurve();
|
||||
static uint16_t OneWayVoltScan();
|
||||
static void ramp_test();
|
||||
static uint16_t DPVCurve();
|
||||
static uint16_t CVCurve();
|
||||
|
||||
+15
-82
@@ -24,7 +24,7 @@ static void SimpleBLEPeripheral_performPeriodicTask();
|
||||
|
||||
static void SimpleBLEPeripheral_clockHandler(UArg arg) {
|
||||
// Store the event.
|
||||
// events |= SBP_PERIODIC_EVT;
|
||||
// events |= SBP_PERIODIC_EVT;
|
||||
|
||||
// Wake up the application.
|
||||
Semaphore_post(semaphore); // send samaphore to jump out of infinite waiting(simple_peripheral.c line570)
|
||||
@@ -52,28 +52,6 @@ static void ZM_init() {
|
||||
|
||||
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins) {}
|
||||
|
||||
static uint16_t VoltScan() {
|
||||
uint16_t Voltage;
|
||||
if (INSTRUCTION.VoltOrigin == INSTRUCTION.VoltFinal) {
|
||||
// DAC_outputV(DACOUT, INSTRUCTION.VoltOrigin); //delete 'command' parameter
|
||||
DAC_outputV(INSTRUCTION.VoltOrigin);
|
||||
PeriodicEvent = false;
|
||||
return INSTRUCTION.VoltOrigin;
|
||||
} else if (INSTRUCTION.eliteFxn == SQUARE_WAVE_VOLTAMMETRY) {
|
||||
Voltage = SWVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) {
|
||||
Voltage = DPVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) {
|
||||
Voltage = CVCurve();
|
||||
}
|
||||
|
||||
// IV plot mode
|
||||
else {
|
||||
Voltage = IVCurve();
|
||||
}
|
||||
|
||||
return Voltage;
|
||||
}
|
||||
|
||||
static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
int32_t RealV;
|
||||
@@ -85,61 +63,6 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
NotifyVolt[3] = (uint8_t)(RealV & 0x000000FF);
|
||||
}
|
||||
|
||||
// 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_Plot() {
|
||||
// read ADC current
|
||||
int32_t Real_Current = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// check if ADC over/under flow
|
||||
ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
Impedance_Calculate(INSTRUCTION.VoltConstant, Real_Current);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void VT_Plot() {
|
||||
// ADC gain is don't care when measuring voltage
|
||||
uint8_t ADCGain = 1;
|
||||
|
||||
// read ADC volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
DecodeADCValue(ADCGain, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
static int32_t IT_Plot() {
|
||||
// read ADC current
|
||||
int32_t Real_Current = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// check if ADC over/under flow
|
||||
// let the output saturate if over/under flow
|
||||
ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
#define IsPeriodicMode() ( \
|
||||
(INSTRUCTION.eliteFxn == IV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == IT_CURVE) || \
|
||||
@@ -148,6 +71,15 @@ static int32_t IT_Plot() {
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) \
|
||||
)
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_performPeriodicTask
|
||||
*
|
||||
* @brief Control periodic event such as DAC out, ADC read, and send notify.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void SimpleBLEPeripheral_performPeriodicTask() {
|
||||
if ( IsPeriodicMode() ){
|
||||
if (StepTimeCounter == INSTRUCTION.StepTime){
|
||||
@@ -164,6 +96,11 @@ static void SimpleBLEPeripheral_performPeriodicTask() {
|
||||
SampleRate_counter++;
|
||||
}
|
||||
|
||||
/** Periodic Event **/
|
||||
// Default working mode is DAC out -> ADC read -> send notify
|
||||
// We will need a flag to control DAC, if we want to exchange to ADC -> DAC -> notify
|
||||
// This flag can be named by FxnNameReset
|
||||
|
||||
// In IV, CV, and func-gen mode, DAC will output voltage
|
||||
// else DAC do nothing.
|
||||
EliteDACControl();
|
||||
@@ -194,8 +131,6 @@ static void EliteADCControl() {
|
||||
if (SampleRate_counter == INSTRUCTION.SampleRate) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:{
|
||||
// LED_color(DARKLED, 0, 0, 255);
|
||||
// LED_color(DARKLED, 0, 0, 125);
|
||||
IT_Plot();
|
||||
break;
|
||||
}
|
||||
@@ -228,11 +163,9 @@ static void EliteNotifyControl() {
|
||||
// output the last notify, and reset Elite
|
||||
if (!PeriodicEvent) {
|
||||
SendNotify();
|
||||
// LED_color(DARKLED, 0xFF, 0x00, 0x00);
|
||||
reset();
|
||||
} else if (StepTimeCounter == INSTRUCTION.StepTime - 1) {
|
||||
SendNotify();
|
||||
// LED_color(DARKLED, 0xFF, 0x00, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user