Compare commits
120 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a9fd1c79c8 | |||
| 551b412329 | |||
| 7d79d4e6df | |||
| 83e2a6537c | |||
| 509419610b | |||
| 4d5c4182fd | |||
| 91fadb0d97 | |||
| 0ff4833fb0 | |||
| 2f2967c09a | |||
| ba5b306fd5 | |||
| 2190115d6f | |||
| a7d083c6bc | |||
| 7f51e113d6 | |||
| 651e42d218 | |||
| 8bbd4dbb41 | |||
| a032346630 | |||
| 6b78e8ebbe | |||
| 824ec33776 | |||
| 969a726332 | |||
| 1215f8a30c | |||
| 89e7706ac2 | |||
| 352e6f5e3b | |||
| 87c82df18c | |||
| 8f4eb259cf | |||
| ad12b9e857 | |||
| 3c91123424 | |||
| 0c602842a3 | |||
| a36b9e3ec2 | |||
| c7a92aa317 | |||
| 9ea145192e | |||
| 82abbcc528 | |||
| b99b75a31d | |||
| f5fa44b95a | |||
| ff64788ba4 | |||
| 1c49b2e204 | |||
| 171e3b2df6 | |||
| 16636e1c1d | |||
| 817eb45cb8 | |||
| 2ea3c76a49 | |||
| 4fc2c9c348 | |||
| a321ea5f3e | |||
| 13ace26dd0 | |||
| ceb73191dc | |||
| d5b5ebdadb | |||
| 9ac63d8313 | |||
| 0966c99b20 | |||
| 6f51cc35e2 | |||
| e85974b12b | |||
| f342ff0763 | |||
| cbe9bd8211 | |||
| 0293647d0c | |||
| 87d187c3a5 | |||
| 09fbfd9dda | |||
| 74ca631309 | |||
| 03e86e175d | |||
| 1c54525256 | |||
| d49874a666 | |||
| 6d6ba43d81 | |||
| 4914498732 | |||
| 85220734de | |||
| 7531a6638b | |||
| 4088a4d38b | |||
| 1b3d057d33 | |||
| 17e1846afa | |||
| 0407690197 | |||
| 55e8b37f13 | |||
| fb4c0a59e8 | |||
| ea3d146c86 | |||
| cddafdffff | |||
| 05e953d6e2 | |||
| 9b7e960bec | |||
| c3aa2f7178 | |||
| 5b4970d814 | |||
| 46c43afa26 | |||
| 6bcfc74d1a | |||
| 4d920209f7 | |||
| 52f8708905 | |||
| b7024363ee | |||
| 1a6d30606c | |||
| e72698dea3 | |||
| 3100dded42 | |||
| 53584f2b5b | |||
| b2d924228a | |||
| f3de02477d | |||
| 77a2bc2d8f | |||
| c56a07ead8 | |||
| 2e3ca56ece | |||
| b8588393b7 | |||
| ea33b37080 | |||
| ea7815dc64 | |||
| 2340b0e88c | |||
| d05d42415a | |||
| e34db21efd | |||
| f6a1a9fa4e | |||
| a567483ffa | |||
| 9dc0a0109a | |||
| afd9ac1223 | |||
| 30ff3a6d69 | |||
| 50781513dc | |||
| fab091d3ec | |||
| b734f2d44c | |||
| 576c6e5177 | |||
| 70a8640327 | |||
| 72d95dac61 | |||
| 84367ae2d3 | |||
| c06a9a996e | |||
| 699c6d1365 | |||
| cbad40dc5a | |||
| 53afd6dd2f | |||
| 5f12e4b10d | |||
| 28f6c39288 | |||
| ec7bd09b70 | |||
| dc6ac4cf19 | |||
| 15cde79313 | |||
| ac6767f082 | |||
| 4f7c2205b0 | |||
| f576158d38 | |||
| 47fc620923 | |||
| 897270dab4 | |||
| 3becd44444 |
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -106,7 +106,7 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_BP_Pin_J2_15 DIO8 /* MOSI */
|
||||
#define Board_BP_Pin_J2_14 DIO7 /* MISO */
|
||||
#define Board_BP_Pin_J2_13 DIO9 /* DAC_CS */
|
||||
#define Board_BP_Pin_J2_12 DIO12 /* ADC_CS */
|
||||
#define Board_BP_Pin_J2_12 DIO12 /* AD_CS */
|
||||
#define Board_BP_Pin_J2_11 IOID_UNUSED /* NC */
|
||||
|
||||
/* Mapping of BoosterPack Connector Pins to BoosterPack Standard Functions (reflecting the BoosterPack Standard)
|
||||
|
||||
+377
-145
@@ -6,7 +6,6 @@
|
||||
#include "EliteSPI.h"
|
||||
#include "EliteNotify.h"
|
||||
|
||||
|
||||
// Elite ADC macro
|
||||
// ADC command, Elite will use these cmd to control ADC
|
||||
#define CMD_CURRENT_MEASURE 0xC5
|
||||
@@ -47,7 +46,6 @@ static void ADC_write(uint8_t ADCin) {
|
||||
spi_ADC_txbuf[0] = ADCin;
|
||||
spi_ADC_txbuf[1] = 0b11101011;
|
||||
|
||||
|
||||
ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
@@ -57,37 +55,30 @@ static void ADC_read(uint8_t *ADCdata){
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
ADC_SPI(SPI_ADC_SIZE, spi_ADC_txbuf, ADCdata);
|
||||
ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
static void ADCGainControl(uint8_t ADCLevel){
|
||||
if(ADCLevel == 0){
|
||||
// ADC gain level = 0, using 200K resister
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 0);
|
||||
}
|
||||
else if(ADCLevel == 1){
|
||||
// ADC gain level = 1, using 10K resister
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 1);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 0);
|
||||
}
|
||||
else if(ADCLevel == 2){
|
||||
// ADC gain level = 2, using 200R resister
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 1);
|
||||
}
|
||||
else if(ADCLevel == 3){
|
||||
// ADC gain level = 0, auto gain (using 200R resister)
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 1);
|
||||
}
|
||||
else{
|
||||
// default using 200R resister
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 1);
|
||||
}
|
||||
}
|
||||
/* Elite1.5 Calibration Usage */
|
||||
static void CAL_ADC_read(uint8_t *ADCdata){
|
||||
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
CAL_ADC_SPI(SPI_ADC_SIZE, spi_ADC_txbuf, ADCdata);
|
||||
}
|
||||
|
||||
static void CAL_ADC_write(uint8_t ADCin) {
|
||||
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
spi_ADC_txbuf[0] = ADCin;
|
||||
spi_ADC_txbuf[1] = 0b11101011;
|
||||
|
||||
CAL_ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
static void ADCChannelSelect(uint8_t ADCChannel){
|
||||
// set ADC parameter
|
||||
@@ -126,8 +117,20 @@ static void ADCChannelSelect(uint8_t ADCChannel){
|
||||
}
|
||||
}
|
||||
|
||||
static void ReadVolt(uint8_t *buf){
|
||||
static void ReadADCIin(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadADCVin(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
ADC_read(buf);
|
||||
|
||||
@@ -135,7 +138,7 @@ static void ReadVolt(uint8_t *buf){
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadVoutVolt(uint8_t *buf){
|
||||
static void ReadADCVout(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
ADCChannelSelect(ADC_CH_DAC);
|
||||
ADC_read(buf);
|
||||
@@ -144,17 +147,7 @@ static void ReadVoutVolt(uint8_t *buf){
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadCurrent(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadBatVolt(uint8_t *buf){
|
||||
static void ReadADCBat(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
ADCChannelSelect(ADC_CH_BAT);
|
||||
ADC_read(buf);
|
||||
@@ -163,124 +156,363 @@ static void ReadBatVolt(uint8_t *buf){
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
/* for Elite1.5-re */
|
||||
// Iin theoretical boundary <2.67, 1.89~80, 63~2600, >1900 (uA)
|
||||
#define I_GAIN_SMALL_BOUNDARY 4000 // 4 uA = 4,000,000 pA
|
||||
#define I_GAIN_MID1_BOUNDARY1 2000 // 2 uA = 2,000,000 pA
|
||||
#define I_GAIN_MID1_BOUNDARY2 90000 // 90 uA = 90,000,000 pA
|
||||
#define I_GAIN_MID2_BOUNDARY1 70000 // 70 uA = 70,000,000 pA
|
||||
#define I_GAIN_MID2_BOUNDARY2 1800000 // 1800 uA = 1,800,000 nA
|
||||
#define I_GAIN_LARGE_BOUNDARY 950000 // 950 uA = 950,000 nA
|
||||
|
||||
// theoretical boundary <20, 10~500, >100 (uA)
|
||||
//#define GAIN_SMALL_BOUNDARY 40000 // 40 uA = 40,000,000 pA
|
||||
//#define GAIN_MID_BOUNDARY1 20000 // 20 uA = 20,000,000 pA
|
||||
//#define GAIN_MID_BOUNDARY2 400000 // 400 uA = 400,000,000 pA
|
||||
//#define GAIN_LARGE_BOUNDARY 200000 // 200 uA = 200,000 nA
|
||||
// Vin theoretical boundary <7, 5~200, >100 (mV)
|
||||
#define VIN_GAIN_SMALL_BOUNDARY 7000 // 7 mV = 7,000,000 nV
|
||||
#define VIN_GAIN_MID1_BOUNDARY1 5000 // 5 mV = 5,000,000 nV
|
||||
#define VIN_GAIN_MID1_BOUNDARY2 300000 // 300 mV = 300,000,000 nV
|
||||
#define VIN_GAIN_LARGE_BOUNDARY 250000 // 250 mV = 250,000,000 nV
|
||||
|
||||
//#define GAIN_SMALL_BOUNDARY 8000 // 8 uA = 8,000,000 pA
|
||||
//#define GAIN_MID_BOUNDARY1 3000 // 3 uA = 3,000,000 pA
|
||||
//#define GAIN_MID_BOUNDARY2 90000 // 90 uA = 90,000,000 pA
|
||||
//#define GAIN_LARGE_BOUNDARY 70000 // 70 uA = 70,000 nA
|
||||
static int32_t AutoGainReadIin(uint8_t *buf){
|
||||
int32_t RealCurrent = 0;
|
||||
|
||||
/* for Elite1.4-re which 6.3kohm replaced by 10kohm */
|
||||
// theoretical boundary <40, 30~1350, >1000 (uA)
|
||||
#define GAIN_SMALL_BOUNDARY 40000 // 40 uA = 40,000,000 pA
|
||||
#define GAIN_MID_BOUNDARY1 30000 // 30 uA = 30,000,000 pA
|
||||
#define GAIN_MID_BOUNDARY2 1350000 // 1350 uA = 1350,000,000 pA
|
||||
#define GAIN_LARGE_BOUNDARY 1000000 // 1000 uA = 1000,000 nA
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
RealCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
static int32_t AutoGainReadCurrent(uint8_t *buf){
|
||||
return RealCurrent;
|
||||
}
|
||||
|
||||
int32_t Real_Current = 0;
|
||||
static int32_t AutoGainReadVin(uint8_t *buf){
|
||||
int32_t RealVolt = 0;
|
||||
|
||||
if(INSTRUCTION.ADCGainLevel == GAIN_AUTO){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
}
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
RealVolt = DecodeADCValue(INSTRUCTION.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
return Real_Current;
|
||||
return RealVolt;
|
||||
}
|
||||
|
||||
//static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
// // switch to 1 level current(small) 3M
|
||||
// // switch to 2 level current 100K
|
||||
// // switch to 3 level current 3K
|
||||
// // switch to 4 level current(large) 100R
|
||||
// if(INSTRUCTION.ADCGainLevel == I_GAIN_100R){
|
||||
// if(RealCurrent < I_GAIN_LARGE_BOUNDARY && RealCurrent > -1*I_GAIN_LARGE_BOUNDARY){
|
||||
// // switch to 1 level current(small)
|
||||
// if (RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
// I_GAIN_3M_counter++;
|
||||
// if(I_GAIN_3M_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_3M;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_3M_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 2 level current
|
||||
// else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
|
||||
// I_GAIN_100K_counter++;
|
||||
// if(I_GAIN_100K_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100K;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_100K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 3 level current
|
||||
// else{
|
||||
// I_GAIN_3K_counter++;
|
||||
// if(I_GAIN_3K_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_3K;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_3K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// if(I_GAIN_3K_counter > 0){
|
||||
// I_GAIN_3K_counter--;
|
||||
// }
|
||||
// if(I_GAIN_100K_counter > 0){
|
||||
// I_GAIN_100K_counter--;
|
||||
// }
|
||||
// if(I_GAIN_3M_counter > 0){
|
||||
// I_GAIN_3M_counter--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(INSTRUCTION.ADCGainLevel == I_GAIN_3K){
|
||||
// // switch to 4 level current(large)
|
||||
// if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
// I_GAIN_100R_counter++;
|
||||
// if(I_GAIN_100R_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_100R_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
|
||||
// // switch to 1 level current(small)
|
||||
// if(RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
// I_GAIN_3M_counter++;
|
||||
// if(I_GAIN_3M_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_3M;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_3M_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 2 level current
|
||||
// else{
|
||||
// I_GAIN_100K_counter++;
|
||||
// if(I_GAIN_100K_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100K;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_100K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// if(I_GAIN_100R_counter > 0){
|
||||
// I_GAIN_100R_counter--;
|
||||
// }
|
||||
// if(I_GAIN_100K_counter > 0){
|
||||
// I_GAIN_100K_counter--;
|
||||
// }
|
||||
// if(I_GAIN_3M_counter > 0){
|
||||
// I_GAIN_3M_counter--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(INSTRUCTION.ADCGainLevel == I_GAIN_100K){
|
||||
// // switch to 1 level current(small)
|
||||
// if(RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
// I_GAIN_3M_counter++;
|
||||
// if(I_GAIN_3M_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_3M;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_3M_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// else if (RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
|
||||
// // switch to 4 level current(large)
|
||||
// if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
// I_GAIN_100R_counter++;
|
||||
// if(I_GAIN_100R_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_100R_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 3 level current
|
||||
// else{
|
||||
// I_GAIN_3K_counter++;
|
||||
// if(I_GAIN_3K_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_3K;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_3K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// if(I_GAIN_100R_counter > 0){
|
||||
// I_GAIN_100R_counter--;
|
||||
// }
|
||||
// if(I_GAIN_3K_counter > 0){
|
||||
// I_GAIN_3K_counter--;
|
||||
// }
|
||||
// if(I_GAIN_3M_counter > 0){
|
||||
// I_GAIN_3M_counter--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(INSTRUCTION.ADCGainLevel == I_GAIN_3M){
|
||||
// if(RealCurrent > I_GAIN_SMALL_BOUNDARY || RealCurrent < -1*I_GAIN_SMALL_BOUNDARY){
|
||||
// // switch to 4 level current(large)
|
||||
// if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
// I_GAIN_100R_counter++;
|
||||
// if(I_GAIN_100R_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_100R_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 3 level current
|
||||
// else if(RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
|
||||
// I_GAIN_3K_counter++;
|
||||
// if(I_GAIN_3K_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_3K;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_3K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 2 level current
|
||||
// else{
|
||||
// I_GAIN_100K_counter++;
|
||||
// if(I_GAIN_100K_counter > 2){
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100K;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// I_GAIN_100K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }else{
|
||||
// if(I_GAIN_100R_counter > 0){
|
||||
// I_GAIN_100R_counter--;
|
||||
// }
|
||||
// if(I_GAIN_3K_counter > 0){
|
||||
// I_GAIN_3K_counter--;
|
||||
// }
|
||||
// if(I_GAIN_100K_counter > 0){
|
||||
// I_GAIN_100K_counter--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
static void AutoGainChange(int32_t Real_Current){
|
||||
if(INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
// switch to mid range current
|
||||
if(Real_Current < GAIN_LARGE_BOUNDARY && Real_Current > -1*GAIN_LARGE_BOUNDARY){
|
||||
// switch to small range current
|
||||
if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
|
||||
GAIN_200K_counter++;
|
||||
if(GAIN_200K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
GAIN_200K_counter = 0;
|
||||
}
|
||||
}else{
|
||||
GAIN_10K_counter++;
|
||||
if(GAIN_10K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
GAIN_10K_counter = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(GAIN_200K_counter > 0){
|
||||
GAIN_200K_counter--;
|
||||
}
|
||||
if(GAIN_10K_counter > 0){
|
||||
GAIN_10K_counter--;
|
||||
}
|
||||
}
|
||||
//static void AutoGainChangeVin(int32_t RealVin){
|
||||
// // switch to 1 level volt(small) 1M
|
||||
// // switch to 2 level volt 30K
|
||||
// // switch to 3 level volt(large) 1K
|
||||
// if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_1M){
|
||||
// if(RealVin > VIN_GAIN_SMALL_BOUNDARY || RealVin < -1*VIN_GAIN_SMALL_BOUNDARY){
|
||||
// // switch to 3 level volt(large)
|
||||
// if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
|
||||
// VIN_GAIN_1K_counter++;
|
||||
// if(VIN_GAIN_1K_counter > 2){
|
||||
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
// VIN_GAIN_1K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 2 level volt
|
||||
// else{
|
||||
// VIN_GAIN_30K_counter++;
|
||||
// if(VIN_GAIN_30K_counter > 2){
|
||||
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
// VIN_GAIN_30K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// if(VIN_GAIN_1K_counter > 0){
|
||||
// VIN_GAIN_1K_counter--;
|
||||
// }
|
||||
// if(VIN_GAIN_30K_counter > 0){
|
||||
// VIN_GAIN_30K_counter--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_30K){
|
||||
// // switch to 1 level volt(small)
|
||||
// if(RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
|
||||
// VIN_GAIN_1M_counter++;
|
||||
// if(VIN_GAIN_1M_counter > 2){
|
||||
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_1M;
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
// VIN_GAIN_1M_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// else if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
|
||||
// // switch to 3 level volt
|
||||
// VIN_GAIN_1K_counter++;
|
||||
// if(VIN_GAIN_1K_counter > 2){
|
||||
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
// VIN_GAIN_1K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }else{
|
||||
// if(VIN_GAIN_1K_counter > 0){
|
||||
// VIN_GAIN_1K_counter--;
|
||||
// }
|
||||
// if(VIN_GAIN_1M_counter > 0){
|
||||
// VIN_GAIN_1M_counter--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_1K){
|
||||
// if(RealVin < VIN_GAIN_LARGE_BOUNDARY && RealVin > -1*VIN_GAIN_LARGE_BOUNDARY){
|
||||
// // switch to 1 level volt(small)
|
||||
// if (RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
|
||||
// VIN_GAIN_1M_counter++;
|
||||
// if(VIN_GAIN_1M_counter > 2){
|
||||
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_1M;
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
// VIN_GAIN_1M_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// // switch to 2 level volt
|
||||
// else{
|
||||
// VIN_GAIN_30K_counter++;
|
||||
// if(VIN_GAIN_30K_counter > 2){
|
||||
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
// VIN_GAIN_30K_counter = 0;
|
||||
// record_flag = false;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// if(VIN_GAIN_1M_counter > 0){
|
||||
// VIN_GAIN_1M_counter--;
|
||||
// }
|
||||
// if(VIN_GAIN_30K_counter > 0){
|
||||
// VIN_GAIN_30K_counter--;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
static uint16_t ADC_CURRENT_AVG_calibration (uint8_t ADC_channel) {
|
||||
uint32_t ADCValueTemp = 0;
|
||||
uint32_t ADCValueSUM = 0;
|
||||
uint32_t ADCValueAVG = 0;
|
||||
uint16_t ADCValueAVG_RAW = 0;
|
||||
#define avgcount 10000
|
||||
|
||||
// Red light for start acquiring data
|
||||
Elite_led_color(COLOR_RED);
|
||||
// CPUdelay(10);
|
||||
for(int i=0; i<avgcount; i++){
|
||||
CAL_ADC_write(ADC_channel);
|
||||
CAL_ADC_read(spi_ADC_rxbuf);
|
||||
CPUdelay(10);
|
||||
CAL_ADC_write(ADC_channel);
|
||||
CAL_ADC_read(spi_ADC_rxbuf);
|
||||
CPUdelay(500);
|
||||
|
||||
ADCValueTemp = 0x0000FFFF & (((uint32_t) (spi_ADC_rxbuf[0]) << 8) | ((uint32_t) (spi_ADC_rxbuf[1])));
|
||||
ADCValueSUM = ADCValueSUM + ADCValueTemp;
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == GAIN_10K){
|
||||
// switch to large range current
|
||||
if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
|
||||
GAIN_200R_counter++;
|
||||
if(GAIN_200R_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
GAIN_200R_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// switch to small range current
|
||||
else if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
|
||||
GAIN_200K_counter++;
|
||||
if(GAIN_200K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
GAIN_200K_counter = 0;
|
||||
}
|
||||
ADCValueAVG = ADCValueSUM / avgcount;
|
||||
ADCValueAVG_RAW = (uint16_t) (ADCValueAVG & 0x0000FFFF);
|
||||
|
||||
}else{
|
||||
if(GAIN_200R_counter > 0){
|
||||
GAIN_200R_counter--;
|
||||
}
|
||||
if(GAIN_200K_counter > 0){
|
||||
GAIN_200K_counter--;
|
||||
}
|
||||
}
|
||||
// Blue light for data acquire done
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
|
||||
if (ADCValueAVG_RAW > 0x7FFF) {
|
||||
ADCValueAVG_RAW = 0x0000;
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == GAIN_200K){
|
||||
// switch to mid range current
|
||||
if(Real_Current > GAIN_SMALL_BOUNDARY || Real_Current < -1*GAIN_SMALL_BOUNDARY){
|
||||
// switch to large range current
|
||||
if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
|
||||
GAIN_200R_counter++;
|
||||
if(GAIN_200R_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
GAIN_200R_counter = 0;
|
||||
}
|
||||
|
||||
}else{
|
||||
GAIN_10K_counter++;
|
||||
if(GAIN_10K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
GAIN_10K_counter = 0;
|
||||
}
|
||||
// clean data
|
||||
ADCValueAVG = 0;
|
||||
ADCValueSUM = 0;
|
||||
ADCValueTemp = 0;
|
||||
|
||||
}
|
||||
}else{
|
||||
if(GAIN_200R_counter > 0){
|
||||
GAIN_200R_counter--;
|
||||
}
|
||||
if(GAIN_10K_counter > 0){
|
||||
GAIN_10K_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Blue light for data acquire done
|
||||
// Elite_led_color(COLOR_BLUE);
|
||||
|
||||
|
||||
|
||||
return ADCValueAVG_RAW;
|
||||
}
|
||||
|
||||
#define ReadADCVolt(x) ((x==0)? ReadVoutVolt(spi_ADC_rxbuf) : ReadVolt(spi_ADC_rxbuf))
|
||||
|
||||
#endif
|
||||
|
||||
-168
@@ -11,174 +11,6 @@
|
||||
* Real current value : -15.00000 ~ 15.00000 mA
|
||||
* => user code = 1500000 mapping to 0.00000 mA
|
||||
*/
|
||||
static void CC_Plot(WorkMode *WorkModeData){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static uint8_t BatSwitch = 0;
|
||||
static int32_t VoltData = 0;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
if(ADCSwitch == 0){
|
||||
if(BatSwitch == 0){ /**read Iin(buffer),read bat**/
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(CURRENT_MODE->_measureCurrent);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 1){
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}
|
||||
else if(ADCSwitch == 1 || ADCSwitch == 3){
|
||||
if(BatSwitch == 0){ /**read Bat**/
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 1){
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}
|
||||
else if(ADCSwitch == 2){
|
||||
if(BatSwitch == 0){ /**read V(buffer),read bat**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
if(CURRENT_MODE->_VoViSwitch == 0x01){
|
||||
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVin;
|
||||
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
|
||||
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVout;
|
||||
}
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 1){
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
BatSwitch = 0;
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer),read V**/
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(CURRENT_MODE->_measureCurrent);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer),read Iin**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
if(CURRENT_MODE->_VoViSwitch == 0x01 || CURRENT_MODE->_VoViSwitch == 0x02){
|
||||
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVin;
|
||||
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
|
||||
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVout;
|
||||
}
|
||||
|
||||
if(INSTRUCTION.VoViSwitch == 0x02){
|
||||
int32_t Vscan = (Vset / 200 - CURRENT_MODE->_measureVin);
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
}else{
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 3){ /**read Iin**/
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void CC_Vscan(CCMode *CC){
|
||||
static int32_t Iin = 0;
|
||||
static int32_t deltaI = 0;
|
||||
|
||||
+68
-42
@@ -19,7 +19,7 @@ static uint16_t CV3Curve(CV3Mode *CV3){
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
|
||||
int32_t RealV2;
|
||||
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
|
||||
@@ -72,56 +72,82 @@ static void CV3_Vscan(CV3Mode *CV3){
|
||||
}
|
||||
|
||||
if(!vscanReset){
|
||||
if (Vset >= CV3->_Vmax){
|
||||
VmaxCounter++;
|
||||
}else if (Vset <= CV3->_Vmin){
|
||||
VminCounter++;
|
||||
}
|
||||
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 (CV3->_current_direction_up){
|
||||
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{
|
||||
Vset = Vset - CV3->_Vstep;
|
||||
}
|
||||
if (Vset >= CV3->_Vmax){
|
||||
VmaxCounter++;
|
||||
}else if (Vset <= CV3->_Vmin){
|
||||
VminCounter++;
|
||||
}
|
||||
|
||||
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 (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(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
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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]
|
||||
|
||||
+4
-3
@@ -177,9 +177,9 @@ static void CV_Vscan(CVMode *CV){
|
||||
}
|
||||
|
||||
if (CV->_current_direction_up){
|
||||
Vset = Vset + CV->_Vstep;
|
||||
Vset = Vset + CV->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - CV->_Vstep;
|
||||
Vset = Vset - CV->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
if(VmaxCounter != 0 && VminCounter != 0){
|
||||
@@ -209,7 +209,8 @@ static void CV_Vscan(CVMode *CV){
|
||||
|
||||
/*stop condition*/
|
||||
if(CV->_cycleNumber == 0){
|
||||
reset();
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ static uint16_t CVSCANCurve(CVSCANMode *CVSCAN){
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
|
||||
int32_t RealV2;
|
||||
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
|
||||
|
||||
+65
-25
@@ -5,34 +5,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_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
|
||||
|
||||
static uint16_t DAC_outputV(uint16_t voltLV) {
|
||||
// C = command, X = don't care, D = data
|
||||
// CCCC CCCC = command
|
||||
@@ -52,9 +49,22 @@ static uint16_t DAC_outputV(uint16_t voltLV) {
|
||||
spi_DACtxbuf[2] = v2;
|
||||
|
||||
DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
|
||||
|
||||
return voltLV;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ELITE_VERSION_EIS
|
||||
static uint32_t DAC_outputV(uint32_t voltLV) {
|
||||
|
||||
// uint8_t v1, v2 = 0;
|
||||
// v1 = (uint8_t) ((voltLV & 0xFF00) >> 8);
|
||||
// v2 = (uint8_t) (voltLV & 0x00FF);
|
||||
|
||||
EIS_LPDAC_SPI(voltLV);
|
||||
|
||||
return voltLV;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t User2Real(uint16_t UserCode){
|
||||
@@ -62,4 +72,34 @@ static int32_t User2Real(uint16_t UserCode){
|
||||
return (int32_t)((UserCode - 25000) / 5);
|
||||
}
|
||||
|
||||
|
||||
// DAC Vout theoretical boundary <300, 100~ (mV)
|
||||
#define DAC_VOUT_GAIN_SMALL_BOUNDARY 100000 // 100 mV = 25500(usercode)
|
||||
#define DAC_VOUT_GAIN_LARGE_BOUNDARY 300000 // 300 mV = 26500(usercode)
|
||||
|
||||
static void AutoGainChangeVout(int32_t RealVolt){
|
||||
RealVolt = (RealVolt - 25000) * 200; // (RealVolt - 25000) / 5 * 1000
|
||||
// switch to 1 level volt(small) 15K
|
||||
// switch to 2 level volt(large) 240K
|
||||
|
||||
if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_AUTO){
|
||||
INSTRUCTION.VoutGainLevel = 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)
|
||||
INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
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)
|
||||
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+103
-2187
File diff suppressed because it is too large
Load Diff
+2
@@ -21,6 +21,8 @@ struct _GPT{
|
||||
uint32_t LeadTimeCounter;
|
||||
uint32_t BatteryADCCounter;
|
||||
uint32_t BatteryCheckCounter;
|
||||
uint32_t GptimerMultiple;
|
||||
uint32_t TestCounter;
|
||||
}GPT = {0};
|
||||
|
||||
static void InitCT(){
|
||||
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
|
||||
#ifndef ELITEIT
|
||||
#define ELITEIT
|
||||
|
||||
static void IT_Plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
EliteADCBattery();
|
||||
if(!batteryCheck_flag){
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
ADCSwitch = 2;
|
||||
}
|
||||
}else{
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(CURRENT_MODE->_measureCurrent);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read Iin**/
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read Iin**/
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
#endif
|
||||
+7
-168
@@ -4,170 +4,6 @@
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static void DACenable(WorkMode *WorkModeData, int32_t VoltData ,uint8_t afterRead){
|
||||
if(afterRead == AFTER_READ_I){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case CONSTANT_CURRENT:{
|
||||
CC_Vscan(WorkModeData->CC);
|
||||
OneWayVoltScan();
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:
|
||||
case CV_CURVE:
|
||||
case ZT_CURVE:
|
||||
case IT_CURVE:
|
||||
case VT_CURVE:
|
||||
case CYCLIC_VOLTAMMETRY:
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:
|
||||
case CONSTANT_VSCAN:{
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else if(afterRead == AFTER_READ_V){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:
|
||||
case CV_CURVE:{
|
||||
OneWayVoltScan();
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
CalcuResistance(WorkModeData->RT, VoltData);
|
||||
break;
|
||||
}
|
||||
case IT_CURVE:
|
||||
case VT_CURVE:
|
||||
case CONSTANT_CURRENT:{
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
CV3Curve(WorkModeData->CV3);
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
LSVCurve(WorkModeData->LSV);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
CVSCANCurve(WorkModeData->CVSCAN);
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CalcuResistance(RTMode *RT, int32_t VoltData){
|
||||
/* Elite 100 = 100R
|
||||
Elite 1000 = 1KR
|
||||
Elite 10000 = 10KR
|
||||
Elite 100000 = 100KR
|
||||
Elite 1000000 = 1MR
|
||||
*/
|
||||
static int32_t resister_32 = 0;
|
||||
int32_t Vtemp;
|
||||
Vtemp = (VoltData * 1000) - (RT->_measureCurrent * 10); //V = Vin - Iin * 10
|
||||
resister_32 = Vtemp / RT->_measureCurrent; //R = V / Iin;
|
||||
InputNotify(NOTIFY_IMPEDANCE, resister_32);
|
||||
}
|
||||
|
||||
static uint16_t OneWayVoltScan() {
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t Vout;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
if(DACReset){
|
||||
Vout = Vset;
|
||||
DACReset = false;
|
||||
}else{
|
||||
DeltaVout = Vset - (Vout);
|
||||
Vout = Vout + DeltaVout;
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000; //5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE)||(INSTRUCTION.eliteFxn == CV_CURVE)||(INSTRUCTION.eliteFxn == CONSTANT_CURRENT)){
|
||||
int32_t RealV;
|
||||
RealV = (int32_t)(Vout / 200);//[1uV]
|
||||
InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
}
|
||||
|
||||
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
static void IV_Plot(IVMode *IV) {
|
||||
/**********************************************
|
||||
CURRENT_MODE->_VoViSwitch : 1 read Vin volt
|
||||
->_VoViSwitch : 0 read Vout volt
|
||||
|
||||
***********************************************/
|
||||
static uint8_t VoltCurrentSwitch = 0;
|
||||
|
||||
if(VoltCurrentSwitch == 0){ /**read Iin(buffer),read Vin**/
|
||||
// read current
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
IV->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(IV->_measureCurrent);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
IV->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
OneWayVoltScan();
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, IV->_measureCurrent);
|
||||
|
||||
// read Volt
|
||||
if(IV->_VoViSwitch == 0x01){
|
||||
ReadVolt(spi_ADC_rxbuf);
|
||||
}else if(IV->_VoViSwitch == 0x00){
|
||||
ReadVoutVolt(spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
VoltCurrentSwitch++;
|
||||
}
|
||||
else if(VoltCurrentSwitch == 1){ /**read Vin**/
|
||||
// read Volt
|
||||
if(IV->_VoViSwitch == 0x01){
|
||||
ReadVolt(spi_ADC_rxbuf);
|
||||
}else if(IV->_VoViSwitch == 0x00){
|
||||
ReadVoutVolt(spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
VoltCurrentSwitch++;
|
||||
}
|
||||
else if(VoltCurrentSwitch == 2){ /**read Vin(buffer),read Iin**/
|
||||
// read Volt
|
||||
if(IV->_VoViSwitch == 0x01){
|
||||
ReadVolt(spi_ADC_rxbuf);
|
||||
IV->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
}else if(IV->_VoViSwitch == 0x00){
|
||||
ReadVoutVolt(spi_ADC_rxbuf);
|
||||
IV->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
InputNotify(NOTIFY_VOLT, IV->_measureVin);
|
||||
|
||||
// read current
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
|
||||
VoltCurrentSwitch++;
|
||||
}
|
||||
else if(VoltCurrentSwitch == 3){ /**read Iin**/
|
||||
// read current
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
|
||||
VoltCurrentSwitch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void IV_Vscan(IVMode *IV){
|
||||
if(vscanReset){
|
||||
if(INSTRUCTION.directionInit == 1){
|
||||
@@ -191,19 +27,22 @@ static void IV_Vscan(IVMode *IV){
|
||||
if(!vscanReset){
|
||||
if(IV->_current_direction_up){
|
||||
if(Vset >= IV->_Vmax){
|
||||
reset();
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}else{
|
||||
if(Vset <= IV->_Vmin){
|
||||
reset();
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
|
||||
if (IV->_current_direction_up){
|
||||
Vset = Vset + IV->_Vstep;
|
||||
Vset = Vset + IV->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - IV->_Vstep;
|
||||
Vset = Vset - IV->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+36
-36
@@ -2,16 +2,32 @@
|
||||
#ifndef ELITEINSTRUCTION
|
||||
#define ELITEINSTRUCTION
|
||||
|
||||
/** ADC gain level **/
|
||||
#define GAIN_200K 0x00 // largest gain
|
||||
#define GAIN_10K 0x01
|
||||
#define GAIN_200R 0x02 // the least gain
|
||||
#define GAIN_AUTO 0x03
|
||||
/** 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
|
||||
#define DAC_POS_MAX 0x0000
|
||||
#define DAC_NEG_MAX 0xFFFF
|
||||
|
||||
// Step time macro
|
||||
#define STEPTIME_HALF_SEC 5000
|
||||
@@ -44,7 +60,12 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
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;
|
||||
|
||||
/** Notify parameter **/
|
||||
uint32_t notifyRate;
|
||||
@@ -57,6 +78,8 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
|
||||
uint16_t StepTime;
|
||||
|
||||
uint8_t AdcChannel;
|
||||
|
||||
} INSTRUCTION = {0};
|
||||
|
||||
/*********************************************************************
|
||||
@@ -86,40 +109,17 @@ static void InitEliteInstruction(){
|
||||
INSTRUCTION.sampleRate = 100;
|
||||
INSTRUCTION.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
|
||||
INSTRUCTION.AutoGainEnable = 1;
|
||||
INSTRUCTION.ADCGainLevel = GAIN_AUTO;
|
||||
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;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn GetInstructionParameter
|
||||
*
|
||||
* @brief Get Constant Current mode parameter.
|
||||
*
|
||||
* @param ins - instruction including current value and unit
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void GetInstructionParameter(uint8 *ins){
|
||||
// CurrentLV=0 => unit is nA
|
||||
// CurrentLV=1 => unit is uA
|
||||
// CurrentLV=2 => unit is mA
|
||||
// INSTRUCTION.CurrentLV = (*ins);
|
||||
|
||||
// ConstantCurrentRange=0 => current value is 0~499
|
||||
// ConstantCurrentRange=1 => current value is 500~999
|
||||
// INSTRUCTION.ConstantCurrentRange = (*ins) & 0x0F;
|
||||
|
||||
// ConstantCurrent divide ConstantCurrentRange into 50000 count (thus each count is 0.01)
|
||||
// e.g. 485.7 uA can be represent by
|
||||
// CurrentLV = 1 (unit is uA)
|
||||
// ConstantCurrentRange = 0 (current range is 0~499)
|
||||
// ConstantCurrent = 48570
|
||||
INSTRUCTION.constantCurrent = (uint32_t) (*(ins+1))<<24 | (uint32_t) (*(ins+2))<<16 | (uint32_t) (*(ins+3))<<8 | (uint32_t) (*(ins+4));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+10
-23
@@ -8,25 +8,19 @@ static bool TurnOnElite(uint8_t key) {
|
||||
if (key == 0) {
|
||||
// press 1 sec, power on LED, read bat power
|
||||
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
|
||||
headstage_battery_volt();
|
||||
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
|
||||
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 0);
|
||||
return false;
|
||||
}else{
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 1); // enable 5V
|
||||
TurnOn10V();
|
||||
LEDPowerON();
|
||||
return true;
|
||||
}
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 1);// enable 5V
|
||||
Elite_SPI_init();
|
||||
ModeLED(BT_WAIT);
|
||||
AD5940_init();
|
||||
// DAC_outputV(0x3FFFF);
|
||||
return true;
|
||||
} else {
|
||||
TurnOnCounter++;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
TurnOnCounter = 0;
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 0);
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +34,7 @@ static void EliteKeyPress(uint8_t key) {
|
||||
// press key => bight LED
|
||||
|
||||
if (ShutDownCounter == CLOCK_ONE_SECOND) {
|
||||
KeyWorkModeLED();
|
||||
KEYLED();
|
||||
}
|
||||
|
||||
// press 3~4 sec, shutdown 2650
|
||||
@@ -53,7 +47,7 @@ static void EliteKeyPress(uint8_t key) {
|
||||
if (OriginEliteFxn == INSTRUCTION.eliteFxn) { // old function == currunt instruction
|
||||
if (ShutDownCounter != 0) {
|
||||
// dark LED
|
||||
WorkModeLED();
|
||||
checkFlafLED();
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
} else { // old function != currunt instruction
|
||||
@@ -61,16 +55,9 @@ static void EliteKeyPress(uint8_t key) {
|
||||
if (ShutDownCounter != 0) {
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
// dark mode LED
|
||||
WorkModeLED();
|
||||
checkFlafLED();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TurnOn10V() {
|
||||
If10Von = true;
|
||||
PIN_setOutputValue(pin_handle, enable_10v, 1);
|
||||
CPUdelay(8000);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+135
-105
@@ -2,12 +2,10 @@
|
||||
#ifndef ELITELED
|
||||
#define ELITELED
|
||||
|
||||
#define DARKLED 0xE1
|
||||
#define LIGHTLED 0xE8
|
||||
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
|
||||
#define LEDPowerON() LED_color(DARKLED, 0x00, 0xFA, 0x00)
|
||||
#define WORKLED() LED_color(0xE2, 0x00, 0x40, 0x40)
|
||||
#define KEYLED() LED_color(LIGHTLED, 0xF0, 0xA0, 0x00)
|
||||
#define DARKLED 0xE1
|
||||
#define LIGHTLED 0xE8
|
||||
|
||||
static void WorkModeLED();
|
||||
|
||||
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
spi_LEDtxbuf[0] = 0x0000;
|
||||
@@ -21,65 +19,92 @@ 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 WorkModeLED() {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE: {
|
||||
WORKLED();
|
||||
static void Elite_led_color(uint16_t color){
|
||||
switch (color) {
|
||||
case COLOR_RED: {
|
||||
LED_color(DARKLED, 0x50, 0x00, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_ORANGE: {
|
||||
LED_color(DARKLED, 0x50, 0x58, 0x09);
|
||||
break;
|
||||
}
|
||||
case COLOR_YELLOW: {
|
||||
LED_color(LIGHTLED, 0x50, 0x80, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_GREEN: {
|
||||
LED_color(DARKLED, 0x00, 0xFA, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_YELLOWGREEN: {
|
||||
LED_color(DARKLED, 0x64, 0xA6, 0x00);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLUE: {
|
||||
LED_color(DARKLED, 0x00, 0x00, 0xAA);
|
||||
break;
|
||||
}
|
||||
case COLOR_CYAN: {
|
||||
LED_color(DARKLED, 0x00, 0x40, 0x40);
|
||||
break;
|
||||
}
|
||||
case COLOR_MAGENTA: {
|
||||
LED_color(DARKLED, 0x50, 0x00, 0x80);
|
||||
break;
|
||||
}
|
||||
case COLOR_PURPLE: {
|
||||
LED_color(DARKLED, 0x50, 0x00, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_WHITE: {
|
||||
LED_color(DARKLED, 0x50, 0xFF, 0xFF);
|
||||
break;
|
||||
}
|
||||
case COLOR_BLACK: {
|
||||
LED_color(0x00, 0x00, 0x00, 0x00);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ModeLED(uint16_t modeStatus) {
|
||||
btWaitLedFlag = 0;
|
||||
noEventLedFlag = 0;
|
||||
preWorkLedFlag = 0;
|
||||
workingLedFlag = 0;
|
||||
postWorkLedFlag = 0;
|
||||
|
||||
switch (modeStatus) {
|
||||
case BT_WAIT: {
|
||||
btWaitLedFlag = 1;
|
||||
BT_WAIT_LED();
|
||||
break;
|
||||
}
|
||||
case CV_CURVE: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case DIFFERENTIAL_PULSE_VOLTAMMETRY: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case SQUARE_WAVE_VOLTAMMETRY: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case VOLT_OUTPUT: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case VT_CURVE: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case IT_CURVE: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
// WORKLED();
|
||||
LED_color(0xE2, 0x00, 0x00, 0xAA);
|
||||
break;
|
||||
}
|
||||
case VIS_RST: {
|
||||
case NO_EVENT: {
|
||||
noEventLedFlag = 1;
|
||||
LEDPowerON();
|
||||
break;
|
||||
}
|
||||
case ADC_TEST: {
|
||||
WORKLED();
|
||||
case PRE_WORK: {
|
||||
preWorkLedFlag = 1;
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY: {
|
||||
WORKLED();
|
||||
case WORKING: {
|
||||
workingLedFlag = 1;
|
||||
WorkModeLED();
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN: {
|
||||
WORKLED();
|
||||
case POST_WORK: {
|
||||
postWorkLedFlag = 1;
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -89,58 +114,63 @@ static void WorkModeLED() {
|
||||
}
|
||||
}
|
||||
|
||||
static void KeyWorkModeLED() {
|
||||
KEYLED();
|
||||
/*
|
||||
switch(INSTRUCTION.eliteFxn){
|
||||
case IV_CURVE:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case DIFFERENTIAL_PULSE_VOLTAMMETRY:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case SQUARE_WAVE_VOLTAMMETRY:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case VOLT_OUTPUT:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case IT_CURVE:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_RST:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case ADC_TEST:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
|
||||
default:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
static void checkFlafLED() {
|
||||
if(btWaitLedFlag == 1){
|
||||
ModeLED(BT_WAIT);
|
||||
}
|
||||
else if(noEventLedFlag == 1){
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
else if(preWorkLedFlag == 1){
|
||||
ModeLED(PRE_WORK);
|
||||
}
|
||||
else if(workingLedFlag == 1){
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
else if(postWorkLedFlag == 1){
|
||||
ModeLED(POST_WORK);
|
||||
}
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// case VIS_RST: {
|
||||
// LEDPowerON();
|
||||
// break;
|
||||
// }
|
||||
default: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+5
-3
@@ -19,7 +19,7 @@ static uint16_t LSVCurve(LSVMode *LSV){
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
|
||||
int32_t RealV2;
|
||||
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
|
||||
@@ -60,13 +60,14 @@ static void LSV_Vscan(LSVMode *LSV){
|
||||
if(!vscanReset){
|
||||
|
||||
if (LSV->_current_direction_up){
|
||||
Vset = Vset + LSV->_Vstep;
|
||||
Vset = Vset + LSV->_Vstep * GPT.GptimerMultiple;
|
||||
}else{
|
||||
Vset = Vset - LSV->_Vstep;
|
||||
Vset = Vset - LSV->_Vstep * GPT.GptimerMultiple;
|
||||
}
|
||||
|
||||
/*stop condition*/
|
||||
if (Vset >= LSV->_Vmax){
|
||||
ModeLED(POST_WORK);
|
||||
// PeriodicEvent = false;
|
||||
Vset = LSV->_Vmin;
|
||||
InitEliteFlag();
|
||||
@@ -79,6 +80,7 @@ static void LSV_Vscan(LSVMode *LSV){
|
||||
INSTRUCTION.notifyRate = 500;
|
||||
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
|
||||
}else if (Vset <= LSV->_Vmin){
|
||||
ModeLED(POST_WORK);
|
||||
// PeriodicEvent = false;
|
||||
Vset = LSV->_Vmax;
|
||||
InitEliteFlag();
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
#ifndef ELITE_LATCH_INIT
|
||||
#define ELITE_LATCH_INIT
|
||||
|
||||
static void InitLH() {
|
||||
for (int i=0; i<LATCH_BUFF_SIZE; i++) {
|
||||
LH.LATCH0[i] = 0;
|
||||
LH.LATCH1[i] = 0;
|
||||
LH.LATCH2[i] = 0;
|
||||
}
|
||||
LH.LoadState = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+6
-6
@@ -107,23 +107,23 @@ static void SendNotify() {
|
||||
|
||||
not_buf[17] = (NotifyCycleNumber >> 8) & 0xff;
|
||||
not_buf[18] = NotifyCycleNumber & 0xff;
|
||||
not_buf[19] = 0;
|
||||
not_buf[20] = 0;
|
||||
not_buf[21] = 0;
|
||||
not_buf[22] = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void initDATBuf(){
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++){
|
||||
not_buf[i] = 0;
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void initINSBuf(){
|
||||
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++){
|
||||
ins_buf[i] = 0;
|
||||
ins_buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-11
@@ -3,14 +3,16 @@
|
||||
#define ELITERESET
|
||||
|
||||
static void reset() {
|
||||
ModeLED(NO_EVENT);
|
||||
InitEliteFlag();
|
||||
InitFlag();
|
||||
InitCT();
|
||||
InitGPT();
|
||||
InitLH();
|
||||
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
LEDPowerON();
|
||||
// VinADCGainControl(VIN_GAIN_AUTO);
|
||||
// IinADCGainControl(I_GAIN_AUTO);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant));
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
@@ -29,20 +31,23 @@ static void reset() {
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1); // AD_CS HIGH
|
||||
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
|
||||
CPUdelay(1600);
|
||||
}
|
||||
|
||||
static void Eliteinterrupt() {
|
||||
InitEliteFlag();
|
||||
InitFlag();
|
||||
ModeLED(NO_EVENT);
|
||||
|
||||
InitEliteFlag();
|
||||
InitCT();
|
||||
InitGPT();
|
||||
InitLH();
|
||||
|
||||
ADCGainControl(GAIN_AUTO);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
LEDPowerON();
|
||||
// VinADCGainControl(VIN_GAIN_AUTO);
|
||||
// IinADCGainControl(I_GAIN_AUTO);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant));
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
|
||||
@@ -61,8 +66,7 @@ static void Eliteinterrupt() {
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1); // AD_CS HIGH
|
||||
CPUdelay(8000);
|
||||
}
|
||||
#endif
|
||||
|
||||
+224
-14
@@ -16,7 +16,7 @@
|
||||
|
||||
/* application use SPI parameters and buffers */
|
||||
#define SPI_LED_SIZE 28
|
||||
#define SPI_DAC_SIZE 3
|
||||
#define SPI_DAC_SIZE 5
|
||||
#define SPI_ADC_SIZE 4
|
||||
|
||||
static uint16_t spi_LEDtxbuf[SPI_LED_SIZE] = {0};
|
||||
@@ -36,11 +36,10 @@ static SPI_Params spiParams1;
|
||||
static SPI_Transaction LED_transaction;
|
||||
static SPI_Transaction ADC_DAC_transaction;
|
||||
|
||||
|
||||
static void Elite_SPI_init(){
|
||||
SPI_init();
|
||||
SPI_Params_init(&spiParams0);
|
||||
spiParams0.bitRate = 2000; // 12k
|
||||
spiParams0.bitRate = 2000; // 2k
|
||||
spiParams0.mode = SPI_MASTER;
|
||||
spiParams0.dataSize = 16;
|
||||
spiParams0.frameFormat = SPI_POL0_PHA1;
|
||||
@@ -50,7 +49,8 @@ static void Elite_SPI_init(){
|
||||
spiParams1.bitRate = 1000000; // 1M
|
||||
spiParams1.mode = SPI_MASTER;
|
||||
spiParams1.dataSize = 8;
|
||||
spiParams1.frameFormat = SPI_POL0_PHA1;
|
||||
spiParams1.frameFormat = SPI_POL0_PHA0;
|
||||
|
||||
spiHandle1 = SPI_open(Board_SPI1, &spiParams1); // ADC DAC SPI
|
||||
}
|
||||
|
||||
@@ -63,26 +63,236 @@ static void LED_SPI(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) {
|
||||
}
|
||||
|
||||
static void ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 0); // CS_ADC
|
||||
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 0); // ADC_CS LOW
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1); // CS_ADC
|
||||
}
|
||||
|
||||
static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 0); // DAC_CS LOW
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
}
|
||||
|
||||
/* Elite1.5 Calibration SPI */
|
||||
static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
|
||||
ADC_DAC_transaction.count = length;
|
||||
ADC_DAC_transaction.txBuf = spi_txbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1); // CS_ADC
|
||||
}
|
||||
|
||||
static void CAL_LED_SPI(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) {
|
||||
LED_transaction.count = length;
|
||||
LED_transaction.txBuf = spi_txbuf;
|
||||
LED_transaction.rxBuf = spi_rxbuf;
|
||||
|
||||
SPI_transfer(spiHandle0, &LED_transaction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef ELITE_VERSION_EIS
|
||||
//define SPI command
|
||||
#define SPICMD_SETADDR 0x20
|
||||
#define SPICMD_WRITEREG 0x2D
|
||||
#define SPICMD_READREG 0x6D
|
||||
|
||||
//define REG
|
||||
#define LPDACCON0 0x2128
|
||||
#define LPDACSW0 0x2124
|
||||
#define LPDACDAT0 0x2120
|
||||
#define LPREFBUFCON 0x2050
|
||||
#define SWMUX 0x235C
|
||||
#define LPTIASW0 0x20E4
|
||||
#define SWCON 0x200C
|
||||
#define HSDACCON 0x2010
|
||||
#define HSDACDAT 0x2048
|
||||
#define LPTIACON0 0x20EC
|
||||
#define HSTIACON 0x20FC
|
||||
#define AFECON 0x2000
|
||||
#define DSWFULLCON 0x2150
|
||||
#define NSWFULLCON 0x2154
|
||||
#define PSWFULLCON 0x2158
|
||||
#define TSWFULLCON 0x215C
|
||||
#define WGFCW 0x2030
|
||||
#define WGPHASE 0x2034
|
||||
#define WGOFFSET 0x2038
|
||||
#define WGAMPLITUDE 0x203C
|
||||
#define WGCON 0x2014
|
||||
#define DE0RESCON 0x20F8
|
||||
#define ADCCON 0x21A8
|
||||
#define DFTCON 0x20D0
|
||||
#define ADCFILTERCON 0x2044
|
||||
|
||||
static void select_REG(uint16_t addr){
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 0);
|
||||
// CPUdelay(16000);
|
||||
|
||||
spi_DACtxbuf[0] = SPICMD_SETADDR;
|
||||
spi_DACtxbuf[1] = (uint8_t)((addr & 0xFF00) >> 8);
|
||||
spi_DACtxbuf[2] = (uint8_t)(addr & 0x00FF);
|
||||
|
||||
ADC_DAC_transaction.count = 3;
|
||||
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
// CPUdelay(16000);
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1);
|
||||
}
|
||||
|
||||
static void w16_REG(uint16_t data){
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 0);
|
||||
spi_DACtxbuf[0] = SPICMD_WRITEREG;
|
||||
spi_DACtxbuf[1] = (uint8_t)((data & 0xFF00) >> 8);
|
||||
spi_DACtxbuf[2] = (uint8_t)(data & 0x00FF);
|
||||
|
||||
ADC_DAC_transaction.count = 3;
|
||||
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1);
|
||||
}
|
||||
|
||||
static void r16_REG(){
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 0);
|
||||
spi_DACtxbuf[0] = SPICMD_READREG;
|
||||
spi_DACtxbuf[1] = 0x00;
|
||||
spi_DACtxbuf[2] = 0x00;
|
||||
spi_DACtxbuf[3] = 0x00;
|
||||
|
||||
ADC_DAC_transaction.count = 4;
|
||||
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1);
|
||||
}
|
||||
|
||||
static void w32_REG(uint32_t data){
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 0);
|
||||
spi_DACtxbuf[0] = SPICMD_WRITEREG;
|
||||
spi_DACtxbuf[1] = (uint8_t)((data & 0xFF000000) >> 24);
|
||||
spi_DACtxbuf[2] = (uint8_t)((data & 0x00FF0000) >> 16);
|
||||
spi_DACtxbuf[3] = (uint8_t)((data & 0x0000FF00) >> 8);
|
||||
spi_DACtxbuf[4] = (uint8_t)(data & 0x000000FF);
|
||||
|
||||
ADC_DAC_transaction.count = 5;
|
||||
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1);
|
||||
}
|
||||
|
||||
static void r32_REG(){
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 0);
|
||||
spi_DACtxbuf[0] = SPICMD_READREG;
|
||||
spi_DACtxbuf[1] = 0x00;
|
||||
spi_DACtxbuf[2] = 0x00;
|
||||
spi_DACtxbuf[3] = 0x00;
|
||||
spi_DACtxbuf[4] = 0x00;
|
||||
spi_DACtxbuf[5] = 0x00;
|
||||
|
||||
ADC_DAC_transaction.count = 6;
|
||||
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
|
||||
ADC_DAC_transaction.rxBuf = spi_rxbuf;
|
||||
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
|
||||
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1);
|
||||
}
|
||||
|
||||
static void AD5940_init(){
|
||||
PIN_setOutputValue(pin_handle, AD_reset, 0);
|
||||
PIN_setOutputValue(pin_handle, AD_reset, 1);
|
||||
select_REG(0x0908);//initiation
|
||||
w16_REG(0x02C9);
|
||||
select_REG(0x0C08);
|
||||
w16_REG(0x206C);
|
||||
select_REG(0x21F0);
|
||||
w16_REG(0x0010);
|
||||
select_REG(0x0410);
|
||||
w16_REG(0x02C9);
|
||||
select_REG(0x0A28);
|
||||
w16_REG(0x0009);
|
||||
select_REG(0x238C);
|
||||
w16_REG(0x0104);
|
||||
select_REG(0x0A04);
|
||||
w16_REG(0x4859);
|
||||
select_REG(0x0A04);
|
||||
w16_REG(0xF27B);
|
||||
select_REG(0x0A00);
|
||||
w16_REG(0x8009);
|
||||
select_REG(0x0A04);
|
||||
w16_REG(0x4859);
|
||||
select_REG(0x22F0);
|
||||
w16_REG(0x0000);
|
||||
|
||||
select_REG(SWCON); //200C
|
||||
w32_REG(0x402B5);
|
||||
|
||||
select_REG(HSDACCON); //2010 //ac gain
|
||||
w32_REG(0x001E);
|
||||
|
||||
select_REG(WGFCW); //2030
|
||||
w32_REG(0x340000);
|
||||
select_REG(WGCON); //2014
|
||||
w32_REG(0x4); //AC on/off; 0x0:DC 0x4:AC 0x5:trapezoid
|
||||
|
||||
select_REG(LPDACCON0); //2128 //DC on
|
||||
w32_REG(0b0000001);
|
||||
select_REG(LPDACSW0); //2124 //operation
|
||||
w32_REG(0b101011);
|
||||
select_REG(LPDACDAT0); //2120 //output Vout
|
||||
w32_REG(0x00000);
|
||||
|
||||
// select_REG(HSTIACON); //20FC //SE0's gain
|
||||
// w32_REG(0x0);
|
||||
select_REG(DE0RESCON); //20F8 //DE0's gain
|
||||
w32_REG(0x68);
|
||||
|
||||
select_REG(ADCCON); //21A8
|
||||
w32_REG(0x101);
|
||||
select_REG(DFTCON); //20D0
|
||||
w32_REG(0x00C1);
|
||||
select_REG(ADCFILTERCON); //2044
|
||||
w32_REG(0x00D0);
|
||||
|
||||
select_REG(AFECON); //2000
|
||||
w32_REG(0x30CFC0);
|
||||
// w32_REG(0b1100011100111111000000);
|
||||
}
|
||||
|
||||
static void EIS_LPDAC_SPI(){
|
||||
// uint32_t con = 0b00001;//12 bit DAC
|
||||
// uint32_t sw = 0b01010;//test mode
|
||||
// uint32_t volt = 0;//2.4v
|
||||
// uint32_t buf = 0;//LP reference
|
||||
// uint32_t cm = 0;//common mode disabled
|
||||
// select_REG(LPDACCON0);
|
||||
// w32_REG(con);
|
||||
// select_REG(LPDACSW0);
|
||||
// w32_REG(sw);
|
||||
// select_REG(LPDACDAT0);
|
||||
// w32_REG(volt);
|
||||
// select_REG(LPREFBUFCON);
|
||||
// w32_REG(buf);
|
||||
// select_REG(SWMUX);
|
||||
// w32_REG(cm);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ELITE_SPI
|
||||
|
||||
-85
@@ -1,85 +0,0 @@
|
||||
|
||||
#ifndef ELITEVT
|
||||
#define ELITEVT
|
||||
|
||||
static void VT_Plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ADC gain is don't care when measuring voltage
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t VoltData;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
EliteADCBattery();
|
||||
if(!batteryCheck_flag){
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 2;
|
||||
}
|
||||
}else{
|
||||
if(ADCSwitch == 0){ /**read V(buffer)**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
if(CURRENT_MODE->_VoViSwitch == 0x01){
|
||||
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVin;
|
||||
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
|
||||
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVout;
|
||||
}
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
#endif
|
||||
+3
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef ELITE_WORK_DATA
|
||||
#define ELITE_WORK_DATA
|
||||
|
||||
#define CLOCK_ONE_SECOND 10000
|
||||
#define CLOCK_ONE_SECOND 00001
|
||||
|
||||
#include "EliteInstruction.h"
|
||||
|
||||
@@ -434,6 +434,7 @@ WorkMode *CreateWorkMode(){
|
||||
void InitWorkMode(WorkMode *WM){
|
||||
switch(INSTRUCTION.eliteFxn){
|
||||
case VOLT_OUTPUT:
|
||||
case CALI_DAC_MODE:
|
||||
WM->VO = InitVoltOutMode();
|
||||
break;
|
||||
case IT_CURVE:
|
||||
@@ -475,6 +476,7 @@ void InitWorkMode(WorkMode *WM){
|
||||
void FreeWorkMode(WorkMode *WM){
|
||||
switch(INSTRUCTION.eliteFxn){
|
||||
case VOLT_OUTPUT:
|
||||
case CALI_DAC_MODE:
|
||||
if(WM->VO != NULL){
|
||||
free(WM->VO);
|
||||
WM->VO = NULL;
|
||||
|
||||
-162
@@ -8,168 +8,6 @@
|
||||
// change the output voltage step
|
||||
// => get a R-T curve (with resolution = 1 sample/volt step )
|
||||
|
||||
static void ZT_Plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static uint8_t BatSwitch = 0;
|
||||
static int32_t VoltData = 0;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
if(ADCSwitch == 0){
|
||||
if(BatSwitch == 0){ /**read Iin(buffer),read bat**/
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(CURRENT_MODE->_measureCurrent);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 1){
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}
|
||||
else if(ADCSwitch == 1 || ADCSwitch == 3){
|
||||
if(BatSwitch == 0){ /**read Bat**/
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 1){
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}
|
||||
else if(ADCSwitch == 2){
|
||||
if(BatSwitch == 0){ /**read V(buffer),read bat**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
if(CURRENT_MODE->_VoViSwitch == 0x01){
|
||||
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVin;
|
||||
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
|
||||
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVout;
|
||||
}
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 1){
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
BatSwitch = 0;
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer),read V**/
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(CURRENT_MODE->_measureCurrent);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer),read Iin**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
if(CURRENT_MODE->_VoViSwitch == 0x01){
|
||||
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVin;
|
||||
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
|
||||
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = CURRENT_MODE->_measureVout;
|
||||
}
|
||||
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 3){ /**read Iin**/
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void ZT_Vscan(RTMode *RT){
|
||||
if(vscanReset){
|
||||
Vset = ((int32_t)(INSTRUCTION.VoltConstant) - 25000) * 4 * 10000; //[5nV]
|
||||
|
||||
+21
-31
@@ -8,50 +8,42 @@
|
||||
|
||||
/* SPI Board */
|
||||
#define Board_SPI0_MISO PIN_UNASSIGNED
|
||||
#define Board_SPI0_MOSI IOID_1
|
||||
#define Board_SPI0_CLK IOID_0
|
||||
#define Board_SPI0_MOSI IOID_4
|
||||
#define Board_SPI0_CLK IOID_3
|
||||
#define Board_SPI0_CS PIN_UNASSIGNED
|
||||
|
||||
#define Board_SPI1_MISO IOID_3
|
||||
#define Board_SPI1_MOSI IOID_2
|
||||
#define Board_SPI1_CLK IOID_4
|
||||
#define Board_SPI1_MISO IOID_1
|
||||
#define Board_SPI1_MOSI IOID_6
|
||||
#define Board_SPI1_CLK IOID_5
|
||||
#define Board_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
#define ADC_CS IOID_8
|
||||
#define DAC_CS IOID_9
|
||||
#define AD_CS IOID_10
|
||||
|
||||
#define Turnon200R IOID_5
|
||||
#define Turnon10K IOID_6
|
||||
//#define SD_MISO IOID_11
|
||||
//#define SD_CS IOID_8
|
||||
//#define SD_CLK IOID_7
|
||||
//#define SD_MOSI IOID_13
|
||||
|
||||
/* I2C */
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
#define Board_I2C0_SCL0 IOID_7
|
||||
#define Board_I2C0_SDA0 IOID_1
|
||||
#endif
|
||||
|
||||
#define shutdown_6994 IOID_10
|
||||
#define switch_on IOID_11
|
||||
#define enable_10v IOID_12
|
||||
#define enable_5v IOID_13
|
||||
#define switch_on IOID_14
|
||||
#define enable_5v IOID_9
|
||||
#define AD_reset IOID_13
|
||||
|
||||
PIN_Handle pin_handle;
|
||||
static PIN_State ZM_rst;
|
||||
|
||||
const PIN_Config BLE_IO[] = {
|
||||
//
|
||||
ADC_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // ADC_CS
|
||||
DAC_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // DAC_CS
|
||||
|
||||
enable_10v | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // 10V_enable
|
||||
enable_5v | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // 5V_enable
|
||||
shutdown_6994 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // turn off power
|
||||
Turnon200R | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
Turnon10K | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
enable_5v | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,// 5V_enable
|
||||
AD_reset | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
switch_on | PIN_INPUT_EN | PIN_PULLDOWN,
|
||||
|
||||
AD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
static void remove_elite_pin() {
|
||||
PIN_close(pin_handle);
|
||||
pin_handle = PIN_open(&ZM_rst, BLE_IO);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @def BOOSTXL_CC2650MA_SPIName
|
||||
* @brief Enum of SPI names on the CC2650 Booster Pack
|
||||
@@ -167,8 +159,6 @@ const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650_MA_I2CCOUNT] = {
|
||||
.intNum = INT_I2C_IRQ,
|
||||
.intPriority = ~0,
|
||||
.swiPriority = 0,
|
||||
.sdaPin = Board_I2C0_SDA0,
|
||||
.sclPin = Board_I2C0_SCL0,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+47
-16
@@ -2,12 +2,12 @@
|
||||
***********************************************************
|
||||
Read battery's method
|
||||
***********************************************************
|
||||
1.ReadBatVolt(spi_ADC_rxbuf)
|
||||
1.ReadADCBat(spi_ADC_rxbuf)
|
||||
let "spi_ADC_rxbuf" be 8000
|
||||
8000 * 187.5uV * 2 = 3V ;
|
||||
8000 * 187.5uV * 2 = 3000000uV = 3V ;
|
||||
2.AONBatMonBatteryVoltageGet()
|
||||
let "AONBatMonBatteryVoltageGet()" be 768
|
||||
768 * 125 / 320 / 100 = 3V ;
|
||||
768 * 125 / 320 / 100 = 768 / 256 = 3V ;
|
||||
|
||||
if you want to use first method, and get value 768
|
||||
conversion: 8000 * 187.5 * 1e-6 * 2 / 125 * 320 * 100 = 768
|
||||
@@ -34,7 +34,7 @@ static uint8_t headstage_battery_percent() {
|
||||
static void headstage_battery_volt(){
|
||||
uint32_t bat_volt = 0;
|
||||
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
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 ;
|
||||
InputNotify(NOTIFY_VOLT_BAT, bat_volt);
|
||||
@@ -42,19 +42,50 @@ static void headstage_battery_volt(){
|
||||
|
||||
static void EliteADCBattery(){
|
||||
static uint8_t ADCSwitch = 0;
|
||||
|
||||
if(ADCSwitch == 0){ /**read V**/
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadBatVolt(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer)**/
|
||||
headstage_battery_volt();
|
||||
batteryCheck_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(GPT.BatteryADCCounter >= 15 && batteryCheck_flag){
|
||||
GPT.BatteryADCCounter = 0; //To get the data right, ADC must be delay 1.5ms
|
||||
batteryADC_flag = true;
|
||||
if(batteryADC_flag){
|
||||
EliteADCBattery();
|
||||
batteryADC_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
|
||||
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
#ifndef ELITE_DEF
|
||||
#define ELITE_DEF
|
||||
|
||||
// define BT instruction
|
||||
#define INS_TYPE_RIS 0x30
|
||||
#define INS_TYPE_VIS 0xC0
|
||||
#define INS_TYPE_CIS 0x70
|
||||
|
||||
// VIS (virtual instruction)
|
||||
#define VIS_RST 0xF0
|
||||
#define VIS_ASK 0x30
|
||||
#define VIS_STI 0xC0
|
||||
#define VIS_FUH 0x90
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_SHIFT_200K 0xA0
|
||||
#define VIS_SHIFT_10K 0xE0
|
||||
#define VIS_SHIFT_200R 0x80
|
||||
#define VIS_DEVICE_SHINY 0x10
|
||||
#define VIS_SHINY_DIS 0x20
|
||||
#define VIS_CC_ZERO 0x40
|
||||
|
||||
// RIS (real instruction)
|
||||
#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 DEV_MODE 0xFF
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
#define CIS_LED_TEST 0x70
|
||||
#define CTL_WRT 0x20
|
||||
#define CTL_RD 0x21
|
||||
#define CTL_RD_DFTR 0x78
|
||||
#define CTL_RD_DFTI 0x7C
|
||||
#define CTL_WRT_WGAMPL 0x3C
|
||||
// mode parameter
|
||||
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
|
||||
#define VMAX(v1,v2) ((v1 >= v2) ? v1 : v2)
|
||||
#define VMIN(v1,v2) ((v1 < v2) ? v1 : v2)
|
||||
#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
|
||||
|
||||
//Elite LED
|
||||
#define COLOR_BLACK 0x00
|
||||
#define COLOR_RED 0x01
|
||||
#define COLOR_ORANGE 0x02
|
||||
#define COLOR_YELLOW 0x03
|
||||
#define COLOR_GREEN 0x04
|
||||
#define COLOR_BLUE 0x05
|
||||
#define COLOR_CYAN 0x06
|
||||
#define COLOR_MAGENTA 0x07
|
||||
#define COLOR_PURPLE 0x08
|
||||
#define COLOR_WHITE 0x09
|
||||
#define COLOR_YELLOWGREEN 0x0A
|
||||
#define LEDPowerON() Elite_led_color(COLOR_GREEN)
|
||||
#define WORKLED() Elite_led_color(COLOR_CYAN)
|
||||
#define KEYLED() Elite_led_color(COLOR_YELLOW)
|
||||
#define BT_WAIT_LED() Elite_led_color(COLOR_YELLOWGREEN)
|
||||
|
||||
|
||||
#define BT_WAIT 0x01
|
||||
#define NO_EVENT 0x02
|
||||
#define PRE_WORK 0x03
|
||||
#define WORKING 0x04
|
||||
#define POST_WORK 0x05
|
||||
|
||||
|
||||
#endif
|
||||
+760
@@ -0,0 +1,760 @@
|
||||
#ifndef ELITE_MODE_ADC_DAC
|
||||
#define ELITE_MODE_ADC_DAC
|
||||
|
||||
#define Vset INSTRUCTION.Vset
|
||||
|
||||
static void readIin(WorkMode *WorkModeData);
|
||||
static int32_t readVinVout(WorkMode *WorkModeData);
|
||||
|
||||
static uint16_t OneWayVoltScan() {
|
||||
static uint16_t DACOutCode;
|
||||
static int32_t Vout;
|
||||
static int32_t DeltaVout;
|
||||
|
||||
if(DACReset){
|
||||
Vout = Vset;
|
||||
DACReset = false;
|
||||
}else{
|
||||
DeltaVout = Vset - (Vout);
|
||||
Vout = Vout + DeltaVout;
|
||||
}
|
||||
|
||||
INSTRUCTION.VoltConstant = Vout / 40000 + 25000; //5nV=>usercode
|
||||
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE)||(INSTRUCTION.eliteFxn == CV_CURVE)||(INSTRUCTION.eliteFxn == CONSTANT_CURRENT)){
|
||||
int32_t RealV;
|
||||
RealV = (int32_t)(Vout / 200);//[1uV]
|
||||
InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
}
|
||||
|
||||
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
static void CalcuResistance(RTMode *RT, int32_t VoltData){
|
||||
/* Elite 100 = 100R
|
||||
Elite 1000 = 1KR
|
||||
Elite 10000 = 10KR
|
||||
Elite 100000 = 100KR
|
||||
Elite 1000000 = 1MR
|
||||
*/
|
||||
static int32_t resister_32 = 0;
|
||||
int32_t Vtemp;
|
||||
Vtemp = (VoltData * 1000) - (RT->_measureCurrent * 10); //V = Vin - Iin * 10
|
||||
resister_32 = Vtemp / RT->_measureCurrent; //R = V / Iin;
|
||||
InputNotify(NOTIFY_IMPEDANCE, resister_32);
|
||||
}
|
||||
|
||||
static void DACenable(WorkMode *WorkModeData, int32_t VoltData ,uint8_t afterRead){
|
||||
if(afterRead == AFTER_READ_I){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case CONSTANT_CURRENT:{
|
||||
CC_Vscan(WorkModeData->CC);
|
||||
OneWayVoltScan();
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:
|
||||
case CV_CURVE:
|
||||
case ZT_CURVE:
|
||||
case IT_CURVE:
|
||||
case VT_CURVE:
|
||||
case CYCLIC_VOLTAMMETRY:
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:
|
||||
case CONSTANT_VSCAN:{
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else if(afterRead == AFTER_READ_V){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:
|
||||
case CV_CURVE:{
|
||||
OneWayVoltScan();
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
CalcuResistance(WorkModeData->RT, VoltData);
|
||||
break;
|
||||
}
|
||||
case IT_CURVE:
|
||||
case VT_CURVE:
|
||||
case CONSTANT_CURRENT:{
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
CV3Curve(WorkModeData->CV3);
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
LSVCurve(WorkModeData->LSV);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
CVSCANCurve(WorkModeData->CVSCAN);
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CC_Plot(WorkMode *WorkModeData){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static uint8_t BatSwitch = 0;
|
||||
static int32_t VoltData = 0;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
if(BatSwitch == 0){
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer),read bat**/
|
||||
readIin(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(ADCSwitch == 1 || ADCSwitch == 3){ /**read Bat**/
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(ADCSwitch == 2){ /**read V(buffer),read bat**/
|
||||
VoltData = readVinVout(WorkModeData);
|
||||
if(INSTRUCTION.VoViSwitch == 0x02){
|
||||
int32_t Vscan = (Vset / 200 - CURRENT_MODE->_measureVin);
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
}else{
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}
|
||||
}else if(BatSwitch == 1){
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}else if(BatSwitch == 2){
|
||||
headstage_battery_volt();
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
}
|
||||
}else{
|
||||
BatSwitch = 0;
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer),read V**/
|
||||
readIin(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_I);
|
||||
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V(buffer),read Iin**/
|
||||
VoltData = readVinVout(WorkModeData);
|
||||
if(INSTRUCTION.VoViSwitch == 0x02){
|
||||
int32_t Vscan = (Vset / 200 - CURRENT_MODE->_measureVin);
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
}else{
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
DACenable(WorkModeData, VoltData, AFTER_READ_V);
|
||||
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 3){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void IT_Plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
EliteADCBattery();
|
||||
if(!batteryCheck_flag){
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 2;
|
||||
}
|
||||
}else{
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
readIin(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void VT_Plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ADC gain is don't care when measuring voltage
|
||||
// INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t VoltData;
|
||||
|
||||
if(batteryCheck_flag){
|
||||
EliteADCBattery();
|
||||
if(!batteryCheck_flag){
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 2;
|
||||
}
|
||||
}else{
|
||||
if(ADCSwitch == 0){ /**read V(buffer)**/
|
||||
VoltData = readVinVout(WorkModeData);
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read V**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
}
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void readIin(WorkMode *WorkModeData){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define TEMP_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define TEMP_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
TEMP_MODE->_measureCurrent = AutoGainReadIin(spi_ADC_rxbuf);
|
||||
// AutoGainChangeIin(TEMP_MODE->_measureCurrent);
|
||||
}else{
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
TEMP_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
if(lastIinADCGainLevel != INSTRUCTION.ADCGainLevel){
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
#undef TEMP_MODE
|
||||
}
|
||||
|
||||
static int32_t readVinVout(WorkMode *WorkModeData){
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define TEMP_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define TEMP_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define TEMP_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define TEMP_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t VoltData;
|
||||
|
||||
if(TEMP_MODE->_VoViSwitch == 0x01 || TEMP_MODE->_VoViSwitch == 0x02){
|
||||
if(INSTRUCTION.VinAutoGainEnable){
|
||||
TEMP_MODE->_measureVin = AutoGainReadVin(spi_ADC_rxbuf);
|
||||
// AutoGainChangeVin(TEMP_MODE->_measureVin);
|
||||
}else{
|
||||
ReadADCVolt(TEMP_MODE->_VoViSwitch);
|
||||
TEMP_MODE->_measureVin = DecodeADCValue(INSTRUCTION.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
if(lastVinADCGainLevel != INSTRUCTION.VinADCGainLevel){
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
VoltData = TEMP_MODE->_measureVin;
|
||||
}else if(TEMP_MODE->_VoViSwitch == 0x00){
|
||||
ReadADCVolt(TEMP_MODE->_VoViSwitch);
|
||||
TEMP_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = TEMP_MODE->_measureVout;
|
||||
}
|
||||
#undef TEMP_MODE
|
||||
return VoltData;
|
||||
}
|
||||
|
||||
static void cali_IT_plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t ADCValueSUM = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CURRENT_MODE->_measureCurrent = 0xFFFF;
|
||||
}else{
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
CURRENT_MODE->_measureCurrent = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if(lastIinADCGainLevel != INSTRUCTION.ADCGainLevel){
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
static uint16_t cali_count = 0;
|
||||
if(cali_count >= 1000){
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = INSTRUCTION.chip_id;
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[3] = 0x00;
|
||||
CIS_buf[4] = INSTRUCTION.ADCGainLevel;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}else{
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + CURRENT_MODE->_measureCurrent;
|
||||
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
|
||||
InputNotify(NOTIFY_VOLT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
static void cali_VT_plot(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IT
|
||||
break;
|
||||
}
|
||||
case VT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->RT
|
||||
break;
|
||||
}
|
||||
case IV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->IV
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
#define CURRENT_MODE WorkModeData->CV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
#define CURRENT_MODE WorkModeData->CC
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->CV3
|
||||
break;
|
||||
}
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
#define CURRENT_MODE WorkModeData->LSV
|
||||
break;
|
||||
}
|
||||
case CONSTANT_VSCAN:{
|
||||
#define CURRENT_MODE WorkModeData->CVSCAN
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
#define CURRENT_MODE WorkModeData->VT
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t VoltData;
|
||||
static int32_t ADCValueSUM = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
if(CURRENT_MODE->_VoViSwitch == 0x01 || CURRENT_MODE->_VoViSwitch == 0x02){
|
||||
if(INSTRUCTION.VinAutoGainEnable){
|
||||
CURRENT_MODE->_measureVin = 0xFFFF;
|
||||
}else{
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
CURRENT_MODE->_measureVin = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if(lastVinADCGainLevel != INSTRUCTION.VinADCGainLevel){
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
VoltData = CURRENT_MODE->_measureVin;
|
||||
}
|
||||
// else if(CURRENT_MODE->_VoViSwitch == 0x00){
|
||||
// ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
// CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
// VoltData = CURRENT_MODE->_measureVout;
|
||||
// }
|
||||
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
static uint16_t cali_count = 0;
|
||||
if(cali_count >= 1000){
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_VOLT, ADCValueAVG);
|
||||
SendNotify();
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = INSTRUCTION.chip_id;
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[3] = 0x00;
|
||||
CIS_buf[4] = INSTRUCTION.VinADCGainLevel;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}else{
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + CURRENT_MODE->_measureVin;
|
||||
InputNotify(NOTIFY_VOLT, CURRENT_MODE->_measureVin);
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
|
||||
}
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read v**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch++;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read v**/
|
||||
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
|
||||
#undef CURRENT_MODE
|
||||
}
|
||||
|
||||
#endif
|
||||
+4
-4
@@ -3,10 +3,10 @@
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 20
|
||||
#define VERSION_DATE_MONTH 7
|
||||
#define VERSION_DATE_DAY 16
|
||||
#define VERSION_DATE_HOUR 18
|
||||
#define VERSION_DATE_MINUTE 19
|
||||
#define VERSION_DATE_MONTH 9
|
||||
#define VERSION_DATE_DAY 7
|
||||
#define VERSION_DATE_HOUR 17
|
||||
#define VERSION_DATE_MINUTE 58
|
||||
|
||||
// this is NOT the version hash !!
|
||||
// it's the last version hash
|
||||
|
||||
+378
-225
@@ -435,8 +435,9 @@ characteristic change event
|
||||
#define MAJOR_PRODUCT_NUMBER 0 //0:Elite ,1:Neulive
|
||||
#define MINOR_PRODUCT_NUMBER 2 //1:Elite_legacy(Ori_Neulive) 2:Elite_zm 3:Elite_bat
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 5
|
||||
#define ELITE_VERSION_1_4
|
||||
#define MINOR_VERSION_NUMBER 6
|
||||
#define ELITE_VERSION_EIS
|
||||
//#define ELITE_VERSION_1_4
|
||||
//#define ELITE_VERSION_1_3
|
||||
|
||||
// buffer size
|
||||
@@ -448,56 +449,7 @@ characteristic change event
|
||||
#define BLE_DAT_BUFF_SIZE SIMPLEPROFILE_CHAR4_LEN
|
||||
#define CHANNEL_COUNT 16
|
||||
|
||||
// define BT instruction
|
||||
#define INS_TYPE_RIS 0x30
|
||||
#define INS_TYPE_VIS 0xC0
|
||||
#define INS_TYPE_CIS 0x70
|
||||
|
||||
// VIS (virtual instruction)
|
||||
#define VIS_RST 0xF0
|
||||
#define VIS_ASK 0x30
|
||||
#define VIS_STI 0xC0
|
||||
#define VIS_FUH 0x90
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_SHIFT_200K 0xA0
|
||||
#define VIS_SHIFT_10K 0xE0
|
||||
#define VIS_SHIFT_200R 0x80
|
||||
#define VIS_DEVICE_SHINY 0x10
|
||||
#define VIS_SHINY_DIS 0x20
|
||||
#define VIS_CC_ZERO 0x40
|
||||
|
||||
// RIS (real instruction)
|
||||
#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_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 0x90
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
|
||||
#define DARKLED 0xE1
|
||||
#define LIGHTLED 0xE8
|
||||
#define LEDPowerON() LED_color(DARKLED, 0x00, 0xFA, 0x00)
|
||||
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
|
||||
#define VMAX(v1,v2) ((v1 >= v2) ? v1 : v2)
|
||||
#define VMIN(v1,v2) ((v1 < v2) ? v1 : v2)
|
||||
#define VDIRECTION(v1,v2) ((v1 > v2) ? 0 : 1)
|
||||
#define AFTER_READ_I 0
|
||||
#define AFTER_READ_V 1
|
||||
#include "Elite_def.h"
|
||||
#include "EliteWorkData.h"
|
||||
|
||||
/**
|
||||
@@ -519,6 +471,19 @@ static uint8_t ins_buf[BLE_INS_BUFF_SIZE] = {0};
|
||||
static uint8_t not_buf[BLE_DAT_BUFF_SIZE] = {0};
|
||||
static uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
|
||||
/**
|
||||
* Latch initialize
|
||||
*/
|
||||
#define LATCH_BUFF_SIZE 8 // define latch
|
||||
struct _LH{
|
||||
bool LATCH0[LATCH_BUFF_SIZE];
|
||||
bool LATCH1[LATCH_BUFF_SIZE];
|
||||
bool LATCH2[LATCH_BUFF_SIZE];
|
||||
uint8_t LoadState;
|
||||
} LH= {0};
|
||||
static void InitLH();
|
||||
|
||||
|
||||
static Clock_Struct periodicClock;
|
||||
static bool PeriodicEvent = false;
|
||||
static bool InitPeriodicEvent = true;
|
||||
@@ -581,40 +546,38 @@ static bool ADC_flag;
|
||||
static bool vscan_flag;
|
||||
static bool notify_flag;
|
||||
static bool notifyFirst_flag;
|
||||
static bool record_flag;
|
||||
static bool vscanReset;
|
||||
static bool EliteWorkReset;
|
||||
static bool leadTimeReset;
|
||||
static int16_t GAIN_200R_counter;
|
||||
static int16_t GAIN_200K_counter;
|
||||
static int16_t GAIN_10K_counter;
|
||||
static int16_t I_GAIN_100R_counter;
|
||||
static int16_t I_GAIN_3K_counter;
|
||||
static int16_t I_GAIN_100K_counter;
|
||||
static int16_t I_GAIN_3M_counter;
|
||||
static int16_t VIN_GAIN_1M_counter;
|
||||
static int16_t VIN_GAIN_30K_counter;
|
||||
static int16_t VIN_GAIN_1K_counter;
|
||||
static int16_t VOUT_GAIN_240K_counter;
|
||||
static int16_t VOUT_GAIN_15K_counter;
|
||||
static uint8_t lastVinADCGainLevel;
|
||||
static uint8_t lastIinADCGainLevel;
|
||||
static bool btWaitLedFlag = 0;
|
||||
static bool noEventLedFlag = 0;
|
||||
static bool preWorkLedFlag = 0;
|
||||
static bool workingLedFlag = 0;
|
||||
static bool postWorkLedFlag = 0;
|
||||
|
||||
// ADC function
|
||||
static void ADC_write(uint8_t ADCin);
|
||||
static void ADC_read(uint8_t *ADCdata);
|
||||
static void ADCGainControl(uint8_t ADCLevel);
|
||||
static void ADCChannelSelect(uint8_t ADCChannel);
|
||||
static void AutoGainChange();
|
||||
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 int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw);
|
||||
static void headstage_battery_volt();
|
||||
static void EliteADCBattery();
|
||||
|
||||
// DAC function
|
||||
static uint16_t DAC_outputV(uint16_t voltLV);
|
||||
static int32_t DAC_to_realV(uint16_t DACcode);
|
||||
static uint16_t Usercode_Correction_to_DAC(uint16_t usercode);
|
||||
static void DACCode2Real2Notify(uint16_t DACcode); // send notify voltage after VoltScan()
|
||||
//static void VinADCGainControl(uint8_t VinADCLevel);
|
||||
|
||||
// Elite key detection & turn on/ shutdown function (peripheral hardware control)
|
||||
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
|
||||
static void WorkModeLED();
|
||||
static void KeyWorkModeLED();
|
||||
static void EliteKeyPress(uint8_t key);
|
||||
static bool TurnOnElite(uint8_t key);
|
||||
static void Elite_led_color(uint16_t color);
|
||||
static void ModeLED(uint16_t modeStatus);
|
||||
//static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
|
||||
static bool If10Von = false;
|
||||
static void TurnOn10V();
|
||||
|
||||
// periodic event control
|
||||
static void EliteADCControl();
|
||||
@@ -634,29 +597,14 @@ static void CalcuResistance(RTMode *RT, int32_t VoltData);
|
||||
static uint16_t CV3Curve(CV3Mode *CV3);
|
||||
static uint16_t LSVCurve(LSVMode *LSV);
|
||||
static uint16_t CVSCANCurve(CVSCANMode *CVSCAN);
|
||||
static uint16_t SWVCurve(WorkMode *WorkModeData);
|
||||
static uint16_t DPVCurve(WorkMode *WorkModeData);
|
||||
|
||||
//mode (notify)
|
||||
static void SendNotify();
|
||||
static void FlushNotify();
|
||||
static void initDATBuf();
|
||||
static void initINSBuf();
|
||||
static void initCISBuf();
|
||||
static void initRawDataBuf();
|
||||
|
||||
//mode (step)
|
||||
static uint32_t OldStep2NewStepTime(uint32_t StepTime);
|
||||
static void step2VsetRate(uint32_t step);
|
||||
|
||||
//init parameter
|
||||
static void InitCT();
|
||||
static void InitGPT();
|
||||
static void InitEliteGPtimer();
|
||||
static void InitFlag();
|
||||
static void InitEliteFlag();
|
||||
static void reset();
|
||||
static void Eliteinterrupt();
|
||||
|
||||
#include "EliteInstruction.h"
|
||||
#include "EliteADC.h"
|
||||
@@ -671,14 +619,14 @@ static void Eliteinterrupt();
|
||||
#include "EliteDeviceCorrection.h"
|
||||
#include "EliteNotify.h"
|
||||
#include "EliteFlagCTInit.h"
|
||||
#include "EliteLatchInit.h"
|
||||
#include "EliteReset.h"
|
||||
#include "EliteLED.h"
|
||||
#include "EliteKeyDetect.h"
|
||||
#include "Elite_mode_ADC_DAC.h"
|
||||
#include "EliteCCMode.h"
|
||||
#include "EliteIVCurve.h"
|
||||
#include "EliteCVCurve.h"
|
||||
#include "EliteITCurve.h"
|
||||
#include "EliteVTCurve.h"
|
||||
#include "EliteZTCurve.h"
|
||||
#include "EliteCCCMode.h"
|
||||
#include "impedance_meter.h"
|
||||
@@ -693,20 +641,15 @@ static void Eliteinterrupt();
|
||||
static void update_ZM_instruction(uint8 *ins) {
|
||||
uint8_t ins_type = ins[0] & 0b11110000;
|
||||
uint8_t chip_ID = ins[0] & 0b00001111;
|
||||
uint8_t oper = ins[1] & 0xFF; // this is don't care in RIS
|
||||
INSTRUCTION.chip_id = chip_ID;
|
||||
|
||||
uint8_t oper = ins[1] & 0xF0; // this is don't care in RIS
|
||||
// uint8_t data_length = ins[1] & 0x0F;
|
||||
|
||||
if (!If10Von) {
|
||||
// TurnOn10V();
|
||||
}
|
||||
|
||||
switch (ins_type) {
|
||||
|
||||
case INS_TYPE_RIS: {
|
||||
switch (ins[2]) {
|
||||
case IV_CURVE: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = IV_CURVE;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
@@ -727,6 +670,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case CV_CURVE: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = CV_CURVE;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
@@ -747,12 +691,15 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case VOLT_OUTPUT: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = VOLT_OUTPUT;
|
||||
INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
|
||||
AutoGainChangeVout((int32_t)INSTRUCTION.VoltConstant);
|
||||
break;
|
||||
}
|
||||
|
||||
case ZT_CURVE: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = ZT_CURVE;
|
||||
INSTRUCTION.notifyRate = (uint32_t)INSTRUCTION.sampleRate;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
@@ -763,6 +710,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case VT_CURVE: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = VT_CURVE;
|
||||
INSTRUCTION.notifyRate = (uint32_t)INSTRUCTION.sampleRate;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
@@ -771,6 +719,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case IT_CURVE: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = IT_CURVE;
|
||||
INSTRUCTION.notifyRate = (uint32_t)INSTRUCTION.sampleRate;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
@@ -779,6 +728,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case CONSTANT_CURRENT:{
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.charge = ins[3]; //0:discharge 1:charge
|
||||
@@ -796,31 +746,36 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case CYCLIC_VOLTAMMETRY: {
|
||||
INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.Vinit = ((int32_t)(ins[3]) << 8) | (int32_t)(ins[4]);
|
||||
INSTRUCTION.Ve1 = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
INSTRUCTION.Ve2 = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
INSTRUCTION.Vmax = (int32_t)VMAX(INSTRUCTION.Ve1,INSTRUCTION.Ve2);
|
||||
INSTRUCTION.Vmin = (int32_t)VMIN(INSTRUCTION.Ve1,INSTRUCTION.Ve2);
|
||||
if(INSTRUCTION.Vinit > INSTRUCTION.Ve1 || INSTRUCTION.Vinit == INSTRUCTION.Vmax){
|
||||
INSTRUCTION.directionInit = 0;//0:reverse 1:forward
|
||||
}else if(INSTRUCTION.Vinit <= INSTRUCTION.Ve1 || INSTRUCTION.Vinit == INSTRUCTION.Vmin){
|
||||
INSTRUCTION.directionInit = 1;
|
||||
if(ins[3] == PARA_1){
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.Vinit = ((int32_t)(ins[4]) << 8) | (int32_t)(ins[5]);
|
||||
INSTRUCTION.Ve1 = ((uint16_t)(ins[6]) << 8) | (uint16_t)(ins[7]);
|
||||
INSTRUCTION.Ve2 = ((uint16_t)(ins[8]) << 8) | (uint16_t)(ins[9]);
|
||||
INSTRUCTION.Vmax = (int32_t)VMAX(INSTRUCTION.Ve1,INSTRUCTION.Ve2);
|
||||
INSTRUCTION.Vmin = (int32_t)VMIN(INSTRUCTION.Ve1,INSTRUCTION.Ve2);
|
||||
if(INSTRUCTION.Vinit > INSTRUCTION.Ve1 || INSTRUCTION.Vinit == INSTRUCTION.Vmax){
|
||||
INSTRUCTION.directionInit = 0;//0:reverse 1:forward
|
||||
}else if(INSTRUCTION.Vinit <= INSTRUCTION.Ve1 || INSTRUCTION.Vinit == INSTRUCTION.Vmin){
|
||||
INSTRUCTION.directionInit = 1;
|
||||
}
|
||||
}else if(ins[3] == PARA_2){
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY;
|
||||
INSTRUCTION.Currentmax = (int32_t)(ins[10]) << 24 | (int32_t)(ins[11]) << 16 | (int32_t)(ins[12]) << 8 | (int32_t)(ins[13]);
|
||||
INSTRUCTION.notifyRate = (uint32_t)(ins[8]) << 8 | (uint32_t)(ins[9]);
|
||||
INSTRUCTION.notifyRate = 10000 / INSTRUCTION.notifyRate * 10;
|
||||
//controller UI 0.01~1000mv send to Elite 1~100000
|
||||
INSTRUCTION.step = (uint32_t)(ins[4]) << 24 | (uint32_t)(ins[5]) << 16 | (uint32_t)(ins[6]) << 8 | (uint32_t)(ins[7]);
|
||||
STEP_TO_VSETRATE(INSTRUCTION.step);
|
||||
INSTRUCTION.VsetRate = VsetRateTable[INSTRUCTION.VsetRateIndex];//N
|
||||
INSTRUCTION.VoViSwitch = 0x01;
|
||||
INSTRUCTION.cycleNumber = ins[14];
|
||||
}
|
||||
INSTRUCTION.Currentmax = (int32_t)(ins[15]) << 24 | (int32_t)(ins[16]) << 16 | (int32_t)(ins[17]) << 8 | (int32_t)(ins[18]);
|
||||
INSTRUCTION.notifyRate = (uint32_t)(ins[13]) << 8 | (uint32_t)(ins[14]);
|
||||
INSTRUCTION.notifyRate = 10000 / INSTRUCTION.notifyRate * 10;
|
||||
//controller UI 0.01~1000mv send to Elite 1~100000
|
||||
INSTRUCTION.step = (uint32_t)(ins[9]) << 24 | (uint32_t)(ins[10]) << 16 | (uint32_t)(ins[11]) << 8 | (uint32_t)(ins[12]);
|
||||
STEP_TO_VSETRATE(INSTRUCTION.step);
|
||||
INSTRUCTION.VsetRate = VsetRateTable[INSTRUCTION.VsetRateIndex];//N
|
||||
INSTRUCTION.VoViSwitch = 0x01;
|
||||
INSTRUCTION.cycleNumber = ins[19];
|
||||
break;
|
||||
}
|
||||
|
||||
case HIGH_CYCLE_CYCLIC_VOLTAMMETRY: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.Vinit = ((int32_t)(ins[3]) << 8) | (int32_t)(ins[4]);
|
||||
@@ -846,6 +801,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case LINEAR_SWEEP_VOLTAMMETRY:{
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = LINEAR_SWEEP_VOLTAMMETRY;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
@@ -867,6 +823,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case CONSTANT_VSCAN:{
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = CONSTANT_VSCAN;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.Vinit = ((int32_t)(ins[3]) << 8) | (int32_t)(ins[4]);
|
||||
@@ -883,16 +840,17 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case DIFFERENTIAL_PULSE_VOLTAMMETRY: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = DIFFERENTIAL_PULSE_VOLTAMMETRY;
|
||||
DACReset = true;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
INSTRUCTION.Ve1 = Usercode_Correction_to_DAC(INSTRUCTION.Ve1);
|
||||
INSTRUCTION.Ve1 = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1);
|
||||
}
|
||||
if (ins[5] | ins[6]) {
|
||||
INSTRUCTION.Ve2 = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
INSTRUCTION.Ve2 = Usercode_Correction_to_DAC(INSTRUCTION.Ve2);
|
||||
INSTRUCTION.Ve2 = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve2);
|
||||
}
|
||||
|
||||
if (ins[7] | ins[8]) {
|
||||
@@ -904,7 +862,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
if (ins[10] | ins[11]) {
|
||||
Amplitude = ((uint16_t)(ins[10]) << 8) | (uint16_t)(ins[11]);
|
||||
Amplitude = Usercode_Correction_to_DAC(Amplitude);
|
||||
Amplitude = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, Amplitude);
|
||||
}
|
||||
if (ins[12]) {
|
||||
PulsePeriod = ins[12];
|
||||
@@ -919,16 +877,17 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case SQUARE_WAVE_VOLTAMMETRY: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = SQUARE_WAVE_VOLTAMMETRY;
|
||||
DACReset = true;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
INSTRUCTION.Ve1 = Usercode_Correction_to_DAC(INSTRUCTION.Ve1);
|
||||
INSTRUCTION.Ve1 = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1);
|
||||
}
|
||||
if (ins[5] | ins[6]) {
|
||||
INSTRUCTION.Ve2 = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
INSTRUCTION.Ve2 = Usercode_Correction_to_DAC(INSTRUCTION.Ve2);
|
||||
INSTRUCTION.Ve2 = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve2);
|
||||
}
|
||||
if (ins[7] | ins[8]) {
|
||||
INSTRUCTION.step = ((uint32_t)(ins[7]) << 8) | (uint32_t)(ins[8]);
|
||||
@@ -939,7 +898,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
if (ins[10] | ins[11]) {
|
||||
Amplitude = ((uint16_t)(ins[10]) << 8) | (uint16_t)(ins[11]);
|
||||
Amplitude = Usercode_Correction_to_DAC(Amplitude);
|
||||
Amplitude = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, Amplitude);
|
||||
}
|
||||
if (ins[12]) {
|
||||
PulseWidth = ins[12];
|
||||
@@ -956,79 +915,287 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
case SET_ADC_GAIN: {
|
||||
INSTRUCTION.ADCGainLevel = ins[3];
|
||||
if(INSTRUCTION.ADCGainLevel != GAIN_AUTO){
|
||||
INSTRUCTION.AutoGainEnable = 0;
|
||||
case SET_ADC_DAC_GAIN: {
|
||||
switch(ins[3]){
|
||||
case IIN_ADC :{
|
||||
INSTRUCTION.ADCGainLevel = ins[4];
|
||||
if(INSTRUCTION.ADCGainLevel != I_GAIN_AUTO){
|
||||
INSTRUCTION.AutoGainEnable = 0;
|
||||
}
|
||||
else{
|
||||
INSTRUCTION.AutoGainEnable = 1;
|
||||
INSTRUCTION.ADCGainLevel = I_GAIN_100R;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIN_ADC :{
|
||||
INSTRUCTION.VinADCGainLevel = ins[4];
|
||||
if(INSTRUCTION.VinADCGainLevel != VIN_GAIN_AUTO){
|
||||
INSTRUCTION.VinAutoGainEnable = 0;
|
||||
}
|
||||
else{
|
||||
INSTRUCTION.VinAutoGainEnable = 1;
|
||||
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VOUT_DAC :{
|
||||
// INSTRUCTION.VoutGainLevel = ins[4];
|
||||
// if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_AUTO){
|
||||
// INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
|
||||
// }
|
||||
INSTRUCTION.VoutGainLevel = ins[4];
|
||||
break;
|
||||
}
|
||||
case HIGH_Z :{
|
||||
switch(ins[4]) {
|
||||
default :{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
INSTRUCTION.AutoGainEnable = 1;
|
||||
}
|
||||
// if(INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
// LED_color(DARKLED, 0x0F, 0x00, 0x00);
|
||||
// }
|
||||
// else if(INSTRUCTION.ADCGainLevel == GAIN_10K){
|
||||
// LED_color(DARKLED, 0x0F, 0x00, 0x0F);
|
||||
// }
|
||||
// else if(INSTRUCTION.ADCGainLevel == GAIN_200K){
|
||||
// LED_color(DARKLED, 0x0F, 0x02, 0xFF);
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
case ADC_TEST: {
|
||||
INSTRUCTION.eliteFxn = ADC_TEST;
|
||||
int32_t ADCRealValue = 0;
|
||||
// int32_t ADCRealValue = 0;
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
uint16_t ADCValueAVG_RAW = 0;
|
||||
uint8_t ADC_input = 0;
|
||||
bool AVG_done = 0;
|
||||
|
||||
// for(int i=0 ; i<10 ; i++){
|
||||
ADCGainControl(ins[3]);
|
||||
ADCChannelSelect(ins[4]);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
// CPUdelay(10);
|
||||
//
|
||||
// ADCValueTemp = ( uint16_t) (spi_ADC_rxbuf[0]) << 8 | (uint16_t) (spi_ADC_rxbuf[1]);
|
||||
// ADCValueAVG = ADCValueAVG + ADCValueTemp;
|
||||
// }
|
||||
// ADCValueAVG = ADCValueAVG / 10;
|
||||
// ADCValueTemp = (uint16_t) (ADCValueAVG);
|
||||
|
||||
CIS_buf[0] = chip_ID;
|
||||
for(int i=0; i<4 ; i++){
|
||||
CIS_buf[i+1] = spi_ADC_rxbuf[i];
|
||||
}
|
||||
// CIS_buf[1] = (uint8_t) ((ADCValueTemp & 0xFF00) >> 8);
|
||||
// CIS_buf[2] = (uint8_t) (ADCValueTemp & 0x00FF);
|
||||
// CIS_buf[3] = spi_ADC_rxbuf[2];
|
||||
// CIS_buf[4] = spi_ADC_rxbuf[3];
|
||||
|
||||
// decode ADC measure value
|
||||
ADCRealValue = DecodeADCValue(ins[3], ins[4], spi_ADC_rxbuf);
|
||||
|
||||
// test ADC output through CIS
|
||||
if (ins[4] == ADC_CH_VOLT) {
|
||||
// return ADC volt measure
|
||||
CIS_buf[5] = (uint8_t)(ADCRealValue >> 24);
|
||||
CIS_buf[6] = (uint8_t)((ADCRealValue & 0x00FF0000) >> 16);
|
||||
CIS_buf[7] = (uint8_t)((ADCRealValue & 0x0000FF00) >> 8);
|
||||
CIS_buf[8] = (uint8_t)(ADCRealValue & 0x000000FF);
|
||||
} else if (ins[4] == ADC_CH_CURRENT) {
|
||||
// return ADC current measure
|
||||
CIS_buf[5] = (uint8_t)(ADCRealValue >> 24);
|
||||
CIS_buf[6] = (uint8_t)((ADCRealValue & 0x00FF0000) >> 16);
|
||||
CIS_buf[7] = (uint8_t)((ADCRealValue & 0x0000FF00) >> 8);
|
||||
CIS_buf[8] = (uint8_t)(ADCRealValue & 0x000000FF);
|
||||
} else {
|
||||
// CIS = 0xFF...FF using as an error report
|
||||
for (int i = 1; i < 9; i++) {
|
||||
CIS_buf[i + 1] = 0xFF;
|
||||
switch(ins[3]) {
|
||||
case IIN_ADC :{ // 0x00
|
||||
// IinADCGainControl(ins[4]);
|
||||
AVG_done = 1;
|
||||
ADC_input = CMD_CURRENT_MEASURE;
|
||||
break;
|
||||
}
|
||||
case VIN_ADC :{ // 0x01
|
||||
// VinADCGainControl(ins[4]);
|
||||
AVG_done = 1;
|
||||
ADC_input = CMD_VOLT_MEASURE;
|
||||
break;
|
||||
}
|
||||
case VOUT_DAC :{ // 0x02
|
||||
AVG_done = 0;
|
||||
break;
|
||||
}
|
||||
case HIGH_Z :{ // 0x03
|
||||
switch(ins[4]) {
|
||||
default :{
|
||||
break;
|
||||
}
|
||||
}
|
||||
AVG_done = 0;
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
AVG_done = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (AVG_done) {
|
||||
CPUdelay(100);
|
||||
ADCValueAVG_RAW = ADC_CURRENT_AVG_calibration(ADC_input);
|
||||
} else {
|
||||
AVG_done = 0;
|
||||
for (int i = 1; i < 9; i++) {
|
||||
CIS_buf[i + 1] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
CIS_buf[0] = chip_ID;
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG_RAW & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG_RAW & 0x00FF);
|
||||
CIS_buf[3] = spi_ADC_rxbuf[2];
|
||||
CIS_buf[4] = spi_ADC_rxbuf[3];
|
||||
|
||||
// decode ADC measure value
|
||||
// ADCRealValue = DecodeADCValue(ins[4], ins[3], spi_ADC_rxbuf);
|
||||
|
||||
// test ADC output through CIS
|
||||
// if (ins[3] == ADC_CH_VOLT) {
|
||||
// // return ADC volt measure
|
||||
// CIS_buf[5] = (uint8_t)(ADCRealValue >> 24);
|
||||
// CIS_buf[6] = (uint8_t)((ADCRealValue & 0x00FF0000) >> 16);
|
||||
// CIS_buf[7] = (uint8_t)((ADCRealValue & 0x0000FF00) >> 8);
|
||||
// CIS_buf[8] = (uint8_t)(ADCRealValue & 0x000000FF);
|
||||
// } else if (ins[3] == ADC_CH_CURRENT) {
|
||||
// // return ADC current measure
|
||||
// CIS_buf[5] = (uint8_t)(ADCRealValue >> 24);
|
||||
// CIS_buf[6] = (uint8_t)((ADCRealValue & 0x00FF0000) >> 16);
|
||||
// CIS_buf[7] = (uint8_t)((ADCRealValue & 0x0000FF00) >> 8);
|
||||
// CIS_buf[8] = (uint8_t)(ADCRealValue & 0x000000FF);
|
||||
// } else {
|
||||
// // CIS = 0xFF...FF using as an error report
|
||||
// for (int i = 1; i < 9; i++) {
|
||||
// CIS_buf[i + 1] = 0xFF;
|
||||
// }
|
||||
// }
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
// SendNotify();
|
||||
break;
|
||||
}
|
||||
|
||||
case CALI_DAC_MODE: {
|
||||
ModeLED(WORKING);
|
||||
INSTRUCTION.eliteFxn = CALI_DAC_MODE;
|
||||
INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
|
||||
break;
|
||||
}
|
||||
|
||||
case CALI_ADC_MODE: {
|
||||
switch(ins[3]) {
|
||||
case IIN_ADC :{ // 0x00
|
||||
INSTRUCTION.eliteFxn = CALI_ADC_MODE;
|
||||
INSTRUCTION.AdcChannel = IIN_ADC;
|
||||
INSTRUCTION.notifyRate = 1000;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.VoViSwitch = 0x01;
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case VIN_ADC :{ // 0x01
|
||||
INSTRUCTION.eliteFxn = CALI_ADC_MODE;
|
||||
INSTRUCTION.AdcChannel = VIN_ADC;
|
||||
INSTRUCTION.notifyRate = 1000;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.VoViSwitch = 0x01;
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DEV_MODE: { // INS_TYPE_RIS:0x30, DEV_MODE:0xFF
|
||||
switch (ins[3]) {
|
||||
case CTL_WRT: { // ble write: 0x3000FF 20FFFFFFFFFFFF
|
||||
uint32_t address = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]);
|
||||
uint32_t data = ((uint16_t)(ins[6]) << 24) | (uint16_t)(ins[7]) << 16 |
|
||||
(uint16_t)(ins[8]) << 8 | (uint16_t)(ins[9]);
|
||||
|
||||
select_REG(address);
|
||||
w32_REG(data);
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = (uint8_t)((address & 0x0000FF00) >> 8);
|
||||
cis_buf[1] = (uint8_t)(address & 0x000000FF);
|
||||
cis_buf[2] = (uint8_t)((data & 0xFF000000) >> 24);
|
||||
cis_buf[3] = (uint8_t)((data & 0x00FF0000) >> 16);
|
||||
cis_buf[4] = (uint8_t)((data & 0x0000FF00) >> 8);
|
||||
cis_buf[5] = (uint8_t)(data & 0x000000FF);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case CTL_RD: { // ble write: 0x3000FF 21FFFFFFFF
|
||||
|
||||
uint32_t address = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]);
|
||||
select_REG(address);
|
||||
r32_REG();
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = (uint8_t)((address & 0x0000FF00) >> 8);
|
||||
cis_buf[1] = (uint8_t)(address & 0x000000FF);
|
||||
cis_buf[2] = spi_rxbuf[2];
|
||||
cis_buf[3] = spi_rxbuf[3];
|
||||
cis_buf[4] = spi_rxbuf[4];
|
||||
cis_buf[5] = spi_rxbuf[5];
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case CTL_RD_DFTR: { // ble write: 0x3000FF 78FFFFFFFF
|
||||
select_REG(0x2078);
|
||||
r32_REG();
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = (uint8_t)(0x20);
|
||||
cis_buf[1] = (uint8_t)(0x78);
|
||||
cis_buf[2] = spi_rxbuf[2];
|
||||
cis_buf[3] = spi_rxbuf[3];
|
||||
cis_buf[4] = spi_rxbuf[4];
|
||||
cis_buf[5] = spi_rxbuf[5];
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case CTL_RD_DFTI: { // ble write: 0x3000FF 7CFFFFFFFF
|
||||
select_REG(0x207C);
|
||||
r32_REG();
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = (uint8_t)(0x20);
|
||||
cis_buf[1] = (uint8_t)(0x7C);
|
||||
cis_buf[2] = spi_rxbuf[2];
|
||||
cis_buf[3] = spi_rxbuf[3];
|
||||
cis_buf[4] = spi_rxbuf[4];
|
||||
cis_buf[5] = spi_rxbuf[5];
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case CTL_WRT_WGAMPL: { // ble write: 0x3000FF 3CFFFFFFFF
|
||||
uint32_t data = ((uint16_t)(ins[4]) << 24) | (uint16_t)(ins[5]) << 16 | (uint16_t)(ins[6]) << 8 | (uint16_t)(ins[7]);
|
||||
|
||||
select_REG(0x2014);
|
||||
w32_REG(0x0);
|
||||
|
||||
select_REG(0x203C);
|
||||
w32_REG(data);
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = (uint8_t)(0x20);
|
||||
cis_buf[1] = (uint8_t)(0x3C);
|
||||
cis_buf[2] = (uint8_t)((data & 0xFF000000) >> 24);
|
||||
cis_buf[3] = (uint8_t)((data & 0x00FF0000) >> 16);
|
||||
cis_buf[4] = (uint8_t)((data & 0x0000FF00) >> 8);
|
||||
cis_buf[5] = (uint8_t)(data & 0x000000FF);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
|
||||
select_REG(0x2014);
|
||||
w32_REG(0x4);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x01: { // ble write: 0x3000FF 01
|
||||
if (ins[4] == 1) {
|
||||
Elite_led_color(COLOR_RED); //0101
|
||||
} else if (ins[4] == 2){
|
||||
Elite_led_color(COLOR_ORANGE); //0102
|
||||
} else if (ins[4] == 3){
|
||||
Elite_led_color(COLOR_YELLOW);
|
||||
} else if (ins[4] == 4){
|
||||
Elite_led_color(COLOR_GREEN);
|
||||
} else if (ins[4] == 5){
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
} else if (ins[4] == 6){
|
||||
Elite_led_color(COLOR_MAGENTA);
|
||||
}
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = (uint8_t)(0x11);
|
||||
cis_buf[1] = (uint8_t)(0xFF);
|
||||
cis_buf[2] = ins[4];
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1050,14 +1217,10 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case VIS_ASK: {
|
||||
// uint16_t volt = 0;
|
||||
// volt = ( ((uint16_t) (ins[2])) <<8 ) | (uint16_t) (ins[3]);
|
||||
// DAC_outputV(DACOUT, volt);
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++) {
|
||||
not_buf[i] = i;
|
||||
}
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1083,32 +1246,11 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_SHIFT_200K: {
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 0);
|
||||
LED_color(DARKLED, 0xFF, 0xB4, 0x00);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_SHIFT_10K: {
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 1);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 0);
|
||||
LED_color(DARKLED, 0x14, 0xC8, 0xFF);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_SHIFT_200R: {
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon200R, 1);
|
||||
LED_color(DARKLED, 0xFF, 0xFF, 0xFF);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_DEVICE_SHINY:{
|
||||
LED_color(DARKLED, 0xFF, 0x00, 0xFF);
|
||||
Elite_led_color(COLOR_PURPLE);
|
||||
// uint8_t deviceShinySwitch = (ins[2] & 0b11110000) >> 4;//1:open 0:close
|
||||
// if(deviceShinySwitch == 1){
|
||||
// LED_color(DARKLED, 0xFF, 0x00, 0xFF);
|
||||
// Elite_led_color(COLOR_PURPLE);
|
||||
// }else if(deviceShinySwitch == 0){
|
||||
// if(PeriodicEvent){
|
||||
// WORKLED();
|
||||
@@ -1129,6 +1271,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case VIS_CC_ZERO:{
|
||||
ModeLED(PRE_WORK);
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
INSTRUCTION.sampleRate = 15;
|
||||
INSTRUCTION.charge = 0x01;
|
||||
@@ -1150,7 +1293,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
case INS_TYPE_CIS: {
|
||||
switch (oper) {
|
||||
case 0x00: {
|
||||
I2CWrite(0x01, 0xAB);
|
||||
// I2CWrite(0x01, 0xAB);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1174,6 +1317,16 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
case CIS_LED_TEST: { //0x7070
|
||||
if( ins[2] == 0 ){
|
||||
Elite_led_color(ins[3]);
|
||||
}else if( ins[2] == 1 ){
|
||||
LED_color(LIGHTLED, ins[3], ins[4], ins[5]);
|
||||
}else if( ins[2] == 2 ){
|
||||
LED_color(DARKLED, ins[3], ins[4], ins[5]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1190,6 +1343,18 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ZM_instruction_update_handle(uint8_t characteristic) {
|
||||
switch (characteristic) {
|
||||
case BLE_INS_BUFF_CHAR:
|
||||
// LED_color(0xf8, 0x00, 0xFF, 0xFF);
|
||||
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, ins_buf);
|
||||
update_ZM_instruction(ins_buf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// static void update_clock_period() {
|
||||
// uint32_t clock_rate = INSTRUCTION.adc_clock_rate;
|
||||
//
|
||||
@@ -1212,18 +1377,6 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
// }
|
||||
//}
|
||||
|
||||
static void ZM_instruction_update_handle(uint8_t characteristic) {
|
||||
switch (characteristic) {
|
||||
case BLE_INS_BUFF_CHAR:
|
||||
// LED_color(0xf8, 0x00, 0xFF, 0xFF);
|
||||
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, ins_buf);
|
||||
update_ZM_instruction(ins_buf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*===================================
|
||||
==== system function implements ====
|
||||
==================================*/
|
||||
|
||||
+42
-36
@@ -47,18 +47,11 @@ static void ZM_init() {
|
||||
// initialize
|
||||
pin_handle = PIN_open(&ZM_rst, BLE_IO);
|
||||
|
||||
PIN_setOutputValue(pin_handle, shutdown_6994, 1); // OFF = 1 => turn off 6994
|
||||
PIN_setOutputValue(pin_handle, enable_10v, 0); // enable 10V
|
||||
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, AD_CS, 1); // AD_CS HIGH
|
||||
|
||||
InitEliteInstruction();
|
||||
ADCGainControl(GAIN_AUTO);
|
||||
elite_gptimer_open();
|
||||
|
||||
// PIN_registerIntCb(pin_handle, switch_on_callback);
|
||||
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
|
||||
elite_gptimer_open();
|
||||
}
|
||||
|
||||
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins) {}
|
||||
@@ -66,7 +59,7 @@ static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, ui
|
||||
|
||||
static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
int32_t RealV;
|
||||
RealV = DAC_to_realV(DACcode);
|
||||
RealV = DAC_to_realV(INSTRUCTION.VoutGainLevel, DACcode);
|
||||
|
||||
NotifyVolt[0] = (uint8_t)((RealV & 0xFF000000) >> 24);
|
||||
NotifyVolt[1] = (uint8_t)((RealV & 0x00FF0000) >> 16);
|
||||
@@ -83,7 +76,8 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) || \
|
||||
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
|
||||
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) || \
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_VSCAN) \
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_VSCAN) || \
|
||||
(INSTRUCTION.eliteFxn == CALI_ADC_MODE) \
|
||||
)
|
||||
|
||||
#define Ve1MatchVe2Mode() ( \
|
||||
@@ -93,18 +87,6 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) \
|
||||
)
|
||||
|
||||
#define SendLastDataMode() ( \
|
||||
(INSTRUCTION.eliteFxn == IV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == CV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == IT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == VT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) || \
|
||||
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
|
||||
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) || \
|
||||
(INSTRUCTION.eliteFxn == CONSTANT_VSCAN) \
|
||||
)
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_performPeriodicTask
|
||||
*
|
||||
@@ -125,12 +107,16 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
|
||||
|
||||
if(EliteWorkReset){
|
||||
InitEliteGPtimer();
|
||||
EliteWorkReset = false;
|
||||
EliteWorkReset = false;
|
||||
batteryADC_flag = false;
|
||||
record_flag = true;
|
||||
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
|
||||
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
if( Ve1MatchVe2Mode() ){
|
||||
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.Ve1));
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1));
|
||||
PeriodicEvent = false;
|
||||
ModeLED(NO_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,7 +137,12 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
|
||||
//vscan counter
|
||||
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
|
||||
if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate){
|
||||
GPT.VscanRateCounter -= INSTRUCTION.VsetRate; //To get right time
|
||||
if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate * 2){
|
||||
GPT.GptimerMultiple = GPT.VscanRateCounter / INSTRUCTION.VsetRate;
|
||||
}else{
|
||||
GPT.GptimerMultiple = 1;
|
||||
}
|
||||
GPT.VscanRateCounter -= INSTRUCTION.VsetRate * GPT.GptimerMultiple; //To get right time
|
||||
vscan_flag = true;
|
||||
if(vscan_flag){
|
||||
EliteVscanControl(WorkModeData);
|
||||
@@ -198,13 +189,18 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
|
||||
}
|
||||
}
|
||||
|
||||
EliteDone();
|
||||
// EliteDone();
|
||||
}else if(INSTRUCTION.eliteFxn == VOLT_OUTPUT){
|
||||
WorkModeData->VO->_Vset = INSTRUCTION.VoltConstant;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(WorkModeData->VO->_Vset)); //UserCode -> DAC code -> DAC out
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, WorkModeData->VO->_Vset)); //UserCode -> DAC code -> DAC out
|
||||
FreeWorkMode(WorkModeData);
|
||||
PeriodicEvent = false;
|
||||
}else{
|
||||
}else if(INSTRUCTION.eliteFxn == CALI_DAC_MODE){
|
||||
DAC_outputV(INSTRUCTION.VoltConstant); //UserCode -> DAC code -> DAC out
|
||||
FreeWorkMode(WorkModeData);
|
||||
PeriodicEvent = false;
|
||||
}
|
||||
else{
|
||||
InitFlag();
|
||||
}
|
||||
}
|
||||
@@ -212,11 +208,11 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
|
||||
static void EliteADCControl(WorkMode *WorkModeData) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:{
|
||||
ZT_Plot(WorkModeData);
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
ZT_Plot(WorkModeData);
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case IT_CURVE:{
|
||||
@@ -228,7 +224,7 @@ static void EliteADCControl(WorkMode *WorkModeData) {
|
||||
break;
|
||||
}
|
||||
case ZT_CURVE:{
|
||||
ZT_Plot(WorkModeData);
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
@@ -247,6 +243,15 @@ static void EliteADCControl(WorkMode *WorkModeData) {
|
||||
CC_Plot(WorkModeData);
|
||||
break;
|
||||
}
|
||||
case CALI_ADC_MODE:{
|
||||
if(INSTRUCTION.AdcChannel == IIN_ADC){
|
||||
cali_IT_plot(WorkModeData);
|
||||
}else if(INSTRUCTION.AdcChannel == VIN_ADC){
|
||||
cali_VT_plot(WorkModeData);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
@@ -257,7 +262,7 @@ static void EliteDone() {
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE) || (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY)) {
|
||||
if (!PeriodicEvent) {
|
||||
SendNotify();
|
||||
reset();
|
||||
Eliteinterrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,8 +360,9 @@ static void InitEliteFlag() {
|
||||
vscanReset = true;
|
||||
EliteWorkReset = true;
|
||||
leadTimeReset = true;
|
||||
GAIN_200R_counter = 0;
|
||||
GAIN_200K_counter = 0;
|
||||
GAIN_10K_counter = 0;
|
||||
I_GAIN_100R_counter = 0;
|
||||
I_GAIN_3K_counter = 0;
|
||||
I_GAIN_100K_counter = 0;
|
||||
I_GAIN_3M_counter = 0;
|
||||
}
|
||||
#endif /* IMPEDANCE_METER_H_ */
|
||||
|
||||
+35
-62
@@ -548,7 +548,6 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
SimpleBLEPeripheral_init();
|
||||
|
||||
ZM_init();
|
||||
Elite_SPI_init();
|
||||
WorkMode *WorkModeData = CreateWorkMode();
|
||||
|
||||
uint8_t key = 0;
|
||||
@@ -556,13 +555,13 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
bool EliteOn = 0;
|
||||
|
||||
// init DAC, set output ~= 0 V
|
||||
DAC_outputV(Usercode_Correction_to_DAC(25000));
|
||||
// DAC_outputV(25000);
|
||||
elite_gptimer_start();
|
||||
|
||||
// Application main loops
|
||||
GPT.GptimerCounter0 = GPT.GptimerCounter;
|
||||
batteryADC_flag = false;
|
||||
headstage_battery_volt();
|
||||
// headstage_battery_volt();
|
||||
headstage_init_device_info();
|
||||
|
||||
for (;;) {
|
||||
@@ -620,61 +619,36 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
if (counter6994 < CLOCK_ONE_SECOND/2) { // counter6994 enable a IC after 35 counts
|
||||
counter6994++;
|
||||
} else if (counter6994 == CLOCK_ONE_SECOND/2) {
|
||||
PIN_setOutputValue(pin_handle, shutdown_6994, 1); // OFF = 1 => turn off 6994
|
||||
counter6994++;
|
||||
}
|
||||
EliteKeyPress(key);
|
||||
if(key != 0){ //detect Elite battery power when no periodic event
|
||||
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;
|
||||
}
|
||||
|
||||
if(GPT.BatteryADCCounter >= 15 && batteryCheck_flag){
|
||||
GPT.BatteryADCCounter = 0; //To get the data right, ADC must be delay 1.5ms
|
||||
batteryADC_flag = true;
|
||||
if(batteryADC_flag){
|
||||
EliteADCBattery();
|
||||
batteryADC_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
|
||||
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
|
||||
if( bat < 768 && bat > 20){
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 0);
|
||||
}
|
||||
|
||||
}
|
||||
if(Free_Work_Mode){
|
||||
FreeWorkMode(WorkModeData);
|
||||
InitEliteInstruction();
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
|
||||
Free_Work_Mode = false;
|
||||
}
|
||||
// if(key != 0){ //detect Elite battery power when no periodic event
|
||||
// measureBat();
|
||||
// }
|
||||
// if(Free_Work_Mode){
|
||||
// FreeWorkMode(WorkModeData);
|
||||
// InitEliteInstruction();
|
||||
//// IinADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant));
|
||||
//
|
||||
// Free_Work_Mode = false;
|
||||
// }
|
||||
} else {
|
||||
EliteOn = TurnOnElite(key);
|
||||
}
|
||||
}
|
||||
else { // if there is periodic event
|
||||
if(InitPeriodicEvent){
|
||||
InitWorkMode(WorkModeData);
|
||||
InitPeriodicEvent = false;
|
||||
}
|
||||
|
||||
// Perform periodic application task
|
||||
SimpleBLEPeripheral_performPeriodicTask(WorkModeData);
|
||||
key = PIN_getInputValue(switch_on);
|
||||
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
|
||||
}
|
||||
// else { // if there is periodic event
|
||||
// if(InitPeriodicEvent){
|
||||
// InitWorkMode(WorkModeData);
|
||||
// InitPeriodicEvent = false;
|
||||
// }
|
||||
//
|
||||
// // Perform periodic application task
|
||||
// SimpleBLEPeripheral_performPeriodicTask(WorkModeData);
|
||||
// key = PIN_getInputValue(switch_on);
|
||||
// EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
|
||||
// }
|
||||
}
|
||||
|
||||
#ifdef FEATURE_OAD
|
||||
@@ -950,17 +924,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
|
||||
@@ -996,7 +969,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
|
||||
|
||||
case GAPROLE_WAITING:
|
||||
SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
|
||||
|
||||
ModeLED(BT_WAIT);
|
||||
break;
|
||||
|
||||
case GAPROLE_WAITING_AFTER_TIMEOUT:
|
||||
|
||||
@@ -85,7 +85,7 @@ extern "C"
|
||||
|
||||
// Length of Characteristic 5 in bytes
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 200
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR3_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 20
|
||||
|
||||
|
||||
Reference in New Issue
Block a user