Compare commits
197 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 440158f806 | |||
| 307308825e | |||
| aaf166d187 | |||
| 38ff1f8c2b | |||
| 82f58b3255 | |||
| 31d22f02e1 | |||
| ff1f517af5 | |||
| fb340fbec6 | |||
| e208bfd4d9 | |||
| b9f4967a23 | |||
| 539a388ec4 | |||
| f770ba8783 | |||
| 6d2ef3e106 | |||
| e483c58f10 | |||
| b07c10bb53 | |||
| bb10a463dc | |||
| 93e0db98fc | |||
| 51fc4553a3 | |||
| 5184fe76e7 | |||
| ee264a6f18 | |||
| d290201085 | |||
| 5ab5bdc301 | |||
| de995e2cec | |||
| 81fb68264c | |||
| b05a245cf4 | |||
| f3376a2ab3 | |||
| 48faeeaf1d | |||
| 5560899c94 | |||
| 85e7b34da1 | |||
| 013a2b9ede | |||
| e984572847 | |||
| 591c01bb98 | |||
| 7b053c506e | |||
| e8fcdc18da | |||
| b65ff2383a | |||
| b69e9017bf | |||
| 09a40e1912 | |||
| 6fa630e6e4 | |||
| 95d3c0bbc4 | |||
| 9bf2ab20a8 | |||
| 15a10b2405 | |||
| a4093cdc70 | |||
| 8713d743e1 | |||
| 4d3129782e | |||
| 53ed3f7d6c | |||
| 91d68e665b | |||
| 0bc606c3a8 | |||
| d19b709324 | |||
| 74742ca45b | |||
| 2678b0c02f | |||
| 5576c071c5 | |||
| 27c51a6c54 | |||
| 98c4a62130 | |||
| 7bf8620baf | |||
| 1f742b24df | |||
| 3ac1d77651 | |||
| ae74c4e5cd | |||
| 434be00a44 | |||
| 0b365f098d | |||
| 54e1aab5fc | |||
| 76c8b49553 | |||
| 085d51adcf | |||
| 0b75801ed6 | |||
| eb712ed4bb | |||
| c6f6f4c8f7 | |||
| ab8c29021d | |||
| 62961eeaa4 | |||
| b32c3048d7 | |||
| bc18b12227 | |||
| 28734c52a4 | |||
| cd38d00496 | |||
| e613ae4542 | |||
| 4439a83382 | |||
| 64ef6657be | |||
| 35760ace39 | |||
| 72e6e9acae | |||
| eecc7236ad | |||
| bdb280c029 | |||
| 77b1259bf3 | |||
| 6b9ffacb89 | |||
| 523a98cf8a | |||
| 98db6a0390 | |||
| 164d5209eb | |||
| 4b8a1960dd | |||
| 2e25a129d6 | |||
| 3fc2ccbc6a | |||
| 78853da803 | |||
| 4668654d3c | |||
| 55503b209b | |||
| 0fdd8bf693 | |||
| a6459e4302 | |||
| b256a61876 | |||
| a59c70f75b | |||
| 59f608a4d0 | |||
| 70543a2bd5 | |||
| 7743b6ef62 | |||
| a7f3120fb9 | |||
| 16525b0d19 | |||
| c96b9db716 | |||
| a8bdface95 | |||
| ea8bf21ffd | |||
| 24efe9d896 | |||
| 3ae0520f39 | |||
| 035ca66237 | |||
| 66fd1a5f2f | |||
| ba4a082834 | |||
| ac7b4e8ac3 | |||
| 7e79b2e12c | |||
| 0da686a78b | |||
| 474e3cb8d9 | |||
| e649bd9a25 | |||
| 1f5bf25d16 | |||
| 14cc86bce1 | |||
| 5f636db5ed | |||
| 72c84deb85 | |||
| a0cc1cf228 | |||
| 41b35655a6 | |||
| 68169aed0d | |||
| 645b971b6b | |||
| f669739b4e | |||
| 9f5912c649 | |||
| 8dac9ea12c | |||
| 9f2e6547d2 | |||
| 164be3061d | |||
| f4acbf75d8 | |||
| a3f710f398 | |||
| fdd9ee173c | |||
| 5c581869da | |||
| f1bb7e6217 | |||
| bc553c66af | |||
| 2bb80a06ed | |||
| d44dd996a7 | |||
| 36de918cfc | |||
| 4b45002129 | |||
| 2d23da34c2 | |||
| ff58ec8a1e | |||
| 6ae419b537 | |||
| 96350c19c2 | |||
| ab52989e0e | |||
| 035f01fb0a | |||
| e235fd3adf | |||
| 272d0e423d | |||
| e227b395f9 | |||
| 91d8d1a4d0 | |||
| c5543e777a | |||
| ddfcd11fb4 | |||
| 03ef7ef734 | |||
| 4d84788f51 | |||
| 6d48245d82 | |||
| a2070d1073 | |||
| 40bb5b8e0a | |||
| ac3bee4609 | |||
| 4166c2721c | |||
| 8455fe9422 | |||
| ed3a24a9c9 | |||
| d93464e970 | |||
| 0909855fbb | |||
| dc32d4fb13 | |||
| 36e0be6f9b | |||
| ea5355f413 | |||
| 27960395de | |||
| cdbcb85640 | |||
| db2d8e4217 | |||
| 1b9aedf7a0 | |||
| 1cba7efeeb | |||
| ec7e721fcc | |||
| dcfb390243 | |||
| 2cd7161694 | |||
| a84ec8c438 | |||
| 33805dd480 | |||
| a033919d47 | |||
| 72674329bc | |||
| 6d690d80da | |||
| e607ae50e1 | |||
| 750c13ee00 | |||
| b66a5c1cc5 | |||
| 732ef11d7f | |||
| 1187ead2cf | |||
| c6ddc19fdc | |||
| e864d8fc10 | |||
| 3a0d730c11 | |||
| 773b9f5e48 | |||
| 3218b3a531 | |||
| 658ed58412 | |||
| 9d288dee41 | |||
| e975789be4 | |||
| bf2ef89a7f | |||
| f81aa9a47b | |||
| 2a82ac65e2 | |||
| 6a506898a8 | |||
| 8606e0ca9d | |||
| 5951d1c9e2 | |||
| e741d1b252 | |||
| f85d687a77 | |||
| 142b006c63 | |||
| 5e59e60b4e | |||
| 4a37fa8668 |
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+310
@@ -0,0 +1,310 @@
|
||||
|
||||
#ifndef ELITECCMODE
|
||||
#define ELITECCMODE
|
||||
|
||||
#define CURRENT_LV_FOUR 4
|
||||
#define CURRENT_LV_THREE 3
|
||||
#define CURRENT_LV_TWO 2
|
||||
#define CURRENT_LV_ONE 1
|
||||
#define CURRENT_LV_ZERO 0
|
||||
|
||||
/*********************************************************************
|
||||
* @struct Constant Current Code
|
||||
*
|
||||
* @brief A struct to handle CC mode command
|
||||
*/
|
||||
typedef struct _CURRENT_USER_CODE {
|
||||
/** current level range: 0-4 **/
|
||||
// current level = 0 => 0-499 nA => ADCGainLevel = 200K
|
||||
// current level = 1 => 500-999 nA => ADCGainLevel = 10K
|
||||
// current level = 2 => 0-499 uA => ADCGainLevel = 10K
|
||||
// current level = 3 => 500-999 uA => ADCGainLevel = 200R
|
||||
// current level = 4 => 0-499 mA => ADCGainLevel = 200R
|
||||
uint8_t lv;
|
||||
|
||||
/** current value **/
|
||||
// current value divide current level into 50000 pieces
|
||||
uint16_t value;
|
||||
|
||||
/** Measure Current **/
|
||||
int32_t _MeasureCurrent;
|
||||
|
||||
/** transform a current user code (IUC) to real current in pA **/
|
||||
// handle current lv 0~2
|
||||
int32_t (*_Transform2RealpA)(struct _CURRENT_USER_CODE *);
|
||||
|
||||
/** transform an IUC to real current in nA **/
|
||||
// handle current lv 3~4
|
||||
int32_t (*_Transform2RealnA)(struct _CURRENT_USER_CODE *);
|
||||
|
||||
/** MeasureCurrent operation **/
|
||||
void (*SetMeasureCurrent)(struct _CURRENT_USER_CODE *, int32_t);
|
||||
|
||||
int32_t (*GetMeasureCurrent)(struct _CURRENT_USER_CODE *);
|
||||
}CURRENT_USER_CODE;
|
||||
|
||||
//static CURRENT_USER_CODE CurrentUserCode;
|
||||
|
||||
static int32_t CCModeReadCurrent(CURRENT_USER_CODE *CurrentUserCode){
|
||||
int32_t Real_Current = 0;
|
||||
CCModeReset = 0; // This flag will control DAC working
|
||||
|
||||
CCCurrent2IUC(CurrentUserCode);
|
||||
|
||||
// if(CurrentUserCode->lv == CURRENT_LV_FOUR){
|
||||
// Real_Current = CurrentUserCode->_Transform2RealnA(CurrentUserCode);
|
||||
// }
|
||||
// else{
|
||||
// Real_Current = CurrentUserCode->_Transform2RealpA(CurrentUserCode);
|
||||
// }
|
||||
|
||||
// set ADC gain according to constant current value
|
||||
SetCCModeGain(CurrentUserCode);
|
||||
|
||||
// read ADC current
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
Real_Current = 8787877;
|
||||
|
||||
CurrentUserCode->SetMeasureCurrent(CurrentUserCode, Real_Current);
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
static int32_t CCModeVoltOut(CURRENT_USER_CODE *CurrentUserCode){
|
||||
int32_t MeasureCurrent = 0;
|
||||
|
||||
if(CCModeReset){
|
||||
// DAC should not work now
|
||||
return 0;
|
||||
}
|
||||
|
||||
// MeasureCurrent = CurrentUserCode->GetMeasureCurrent(CurrentUserCode);
|
||||
|
||||
NotifyCurrent[0] = (uint8_t) (MeasureCurrent >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((MeasureCurrent & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((MeasureCurrent & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (MeasureCurrent & 0x000000FF);
|
||||
|
||||
NotifyVolt[0] = (uint8_t) (MeasureCurrent >> 24);
|
||||
NotifyVolt[1] = (uint8_t) ((MeasureCurrent & 0x00FF0000) >> 16);
|
||||
NotifyVolt[2] = (uint8_t) ((MeasureCurrent & 0x0000FF00) >> 8);
|
||||
NotifyVolt[3] = (uint8_t) (MeasureCurrent & 0x000000FF);
|
||||
|
||||
// INSTRUCTION.VoltConstant = 24999 + 500;
|
||||
// DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
return MeasureCurrent;
|
||||
}
|
||||
|
||||
static void SetCCModeGain(CURRENT_USER_CODE *CurrentUserCode){
|
||||
switch(CurrentUserCode->lv){
|
||||
case CURRENT_LV_FOUR:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_THREE:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_TWO:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_ONE:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_ZERO:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CCCurrent2IUC(CURRENT_USER_CODE *CurrentUserCode){
|
||||
if (INSTRUCTION.CurrentLV == CURRENT_LV_MA){
|
||||
// largest current ( 0~500 mA)
|
||||
CurrentUserCode->lv = CURRENT_LV_FOUR;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent);
|
||||
}
|
||||
else if (INSTRUCTION.CurrentLV == CURRENT_LV_UA){
|
||||
if(INSTRUCTION.ConstantCurrent >= 50000){
|
||||
// mid range current ( 500 uA ~ 999 uA)
|
||||
CurrentUserCode->lv = CURRENT_LV_THREE;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent - 50000);
|
||||
}
|
||||
else{
|
||||
// mid range current ( 0 uA ~ 499 uA)
|
||||
CurrentUserCode->lv = CURRENT_LV_TWO;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(INSTRUCTION.ConstantCurrent >= 50000){
|
||||
// mid range current ( 500 nA ~ 999 nA)
|
||||
CurrentUserCode->lv = CURRENT_LV_ONE;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent - 50000);
|
||||
}
|
||||
else{
|
||||
// mid range current ( 0 nA ~ 499 nA)
|
||||
CurrentUserCode->lv = CURRENT_LV_ZERO;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//static int32_t IUC2RealnA(){
|
||||
//
|
||||
//}
|
||||
//
|
||||
//static int32_t IUC2RealpA{
|
||||
//
|
||||
//}
|
||||
/*********************************************************************
|
||||
* @fn Transform2RealpA
|
||||
*
|
||||
* @brief transform an IUC into real current value in pA.
|
||||
*
|
||||
* @param self, which is an IUC
|
||||
*
|
||||
* @return an int32_t current value in pA
|
||||
*/
|
||||
static int32_t _Transform2RealpA(CURRENT_USER_CODE *self){
|
||||
int32_t IUCReal;
|
||||
/** current level range: 0-4 **/
|
||||
// current level = 0 => 0-499 nA => ADCGainLevel = 200K
|
||||
// current level = 1 => 500-999 nA => ADCGainLevel = 10K
|
||||
// current level = 2 => 0-499 uA => ADCGainLevel = 10K
|
||||
// current level = 3 => 500-999 uA => ADCGainLevel = 200R
|
||||
// current level = 4 => 0-499 mA => ADCGainLevel = 200R
|
||||
|
||||
// Saturate if current > 500 uA
|
||||
if (self->lv == CURRENT_LV_FOUR){
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
if (self->lv == CURRENT_LV_THREE){
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
// 0-499 nA
|
||||
if (self->lv == CURRENT_LV_ZERO){
|
||||
IUCReal = (int32_t) (self->value) * 1e3;
|
||||
}
|
||||
|
||||
// 500-999 nA
|
||||
else if (self->lv == CURRENT_LV_ONE){
|
||||
IUCReal = ((int32_t) (self->value) * 1e3);
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 uA
|
||||
else if (self->lv == CURRENT_LV_TWO){
|
||||
IUCReal = (int32_t) (self->value) * 1e6;
|
||||
}
|
||||
return IUCReal;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Transform2RealnA
|
||||
*
|
||||
* @brief transform an IUC into real current value in nA.
|
||||
*
|
||||
* @param self, which is an IUC
|
||||
*
|
||||
* @return an int32_t current value in nA
|
||||
*/
|
||||
static int32_t _Transform2RealnA(CURRENT_USER_CODE *self){
|
||||
int32_t IUCReal;
|
||||
|
||||
// Saturate if current < 500 uA
|
||||
if (self->lv == CURRENT_LV_ZERO | self->lv == CURRENT_LV_ONE | self->lv == CURRENT_LV_TWO){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 500-999 uA
|
||||
if (self->lv == CURRENT_LV_THREE){
|
||||
IUCReal = (int32_t) (self->value) * 1e3;
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 mA
|
||||
else if (self->lv == 4){
|
||||
IUCReal = (int32_t) (self->value) * 1e6;
|
||||
}
|
||||
return IUCReal;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn CompareCurrent
|
||||
*
|
||||
* @brief compare an int32 current with CURRENT_USER_CODE (IUC) type current.
|
||||
*
|
||||
* @param unit is current unit (0 = pA, 1 = nA)
|
||||
* value is current value
|
||||
*
|
||||
* @return 0 if equal
|
||||
* 1 if IUC is larger
|
||||
* 2 if int32 current is larger.
|
||||
*/
|
||||
static uint8_t CompareCurrent(CURRENT_USER_CODE *self, uint8_t unit, int32_t value){
|
||||
int32_t ErrorRangeIUCReal;
|
||||
|
||||
// unit = pA
|
||||
if (unit == 0){
|
||||
if (self->_Transform2RealpA(self) > value){
|
||||
return 1;
|
||||
}
|
||||
else if (self->_Transform2RealpA(self) < value){
|
||||
return 2;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// unit = nA
|
||||
else if (unit == 1){
|
||||
if (self->_Transform2RealnA(self) > value){
|
||||
return 1;
|
||||
}
|
||||
else if (self->_Transform2RealnA(self) < value){
|
||||
return 2;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void SetMeasureCurrent(CURRENT_USER_CODE *self, int32_t current){
|
||||
self->_MeasureCurrent = current;
|
||||
}
|
||||
|
||||
static int32_t GetMeasureCurrent(CURRENT_USER_CODE *self){
|
||||
LED_color(DARKLED, 0x0F, 0x00, 0xFF);
|
||||
return self->_MeasureCurrent;
|
||||
}
|
||||
|
||||
static CURRENT_USER_CODE *InitCurrentUserCode(){
|
||||
CURRENT_USER_CODE *CurrentUserCode = malloc(sizeof(CURRENT_USER_CODE));
|
||||
CurrentUserCode->lv = 0;
|
||||
CurrentUserCode->value = 0;
|
||||
CurrentUserCode->_MeasureCurrent = 0;
|
||||
CurrentUserCode->_Transform2RealnA = &_Transform2RealnA;
|
||||
CurrentUserCode->_Transform2RealpA = &_Transform2RealpA;
|
||||
CurrentUserCode->SetMeasureCurrent = &SetMeasureCurrent;
|
||||
CurrentUserCode->GetMeasureCurrent = &GetMeasureCurrent;
|
||||
return CurrentUserCode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
|
||||
#ifndef ELITECV
|
||||
#define ELITECV
|
||||
|
||||
static uint16_t SWVCurve() {
|
||||
static uint8_t counter;
|
||||
static uint16_t outputV;
|
||||
static uint16_t Volt;
|
||||
static bool direction_up;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACReset) {
|
||||
Volt = INSTRUCTION.VoltOrigin;
|
||||
outputV = INSTRUCTION.VoltOrigin;
|
||||
if (INSTRUCTION.VoltOrigin < INSTRUCTION.VoltFinal)
|
||||
direction_up = true;
|
||||
else
|
||||
direction_up = false;
|
||||
counter = 1;
|
||||
DACReset = false;
|
||||
}
|
||||
|
||||
if (counter == 2 * PulseWidth)
|
||||
counter = 1;
|
||||
else
|
||||
counter++;
|
||||
|
||||
// output a certain volt
|
||||
outputV = Volt;
|
||||
DAC_outputV(outputV);
|
||||
|
||||
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
|
||||
|
||||
// check if we reach the final volt
|
||||
if ((outputV >= INSTRUCTION.VoltFinal && direction_up) || (outputV <= INSTRUCTION.VoltFinal && !direction_up)) {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
}
|
||||
|
||||
// prepare the next output volt
|
||||
if (direction_up) {
|
||||
if (counter == PulseWidth)
|
||||
Volt = Volt + Amplitude;
|
||||
else if (counter == 2 * PulseWidth)
|
||||
Volt = Volt - (Amplitude - INSTRUCTION.Step);
|
||||
else
|
||||
Volt = Volt;
|
||||
} else {
|
||||
if (counter == PulseWidth)
|
||||
Volt = Volt - Amplitude;
|
||||
else if (counter == 2 * PulseWidth)
|
||||
Volt = Volt + (Amplitude - INSTRUCTION.Step);
|
||||
else
|
||||
Volt = Volt;
|
||||
}
|
||||
|
||||
return outputV;
|
||||
}
|
||||
|
||||
static uint16_t DPVCurve() {
|
||||
static uint8_t counter;
|
||||
static uint16_t Volt1;
|
||||
static uint16_t Volt2;
|
||||
static uint16_t outputV;
|
||||
static bool direction_up;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACReset) {
|
||||
if (INSTRUCTION.VoltOrigin < INSTRUCTION.VoltFinal)
|
||||
direction_up = true;
|
||||
else
|
||||
direction_up = false;
|
||||
|
||||
Volt1 = INSTRUCTION.VoltOrigin;
|
||||
if (direction_up)
|
||||
Volt2 = INSTRUCTION.VoltOrigin + Amplitude;
|
||||
else
|
||||
Volt2 = INSTRUCTION.VoltOrigin - Amplitude;
|
||||
|
||||
counter = 1;
|
||||
DACReset = false;
|
||||
}
|
||||
|
||||
if (counter == PulsePeriod)
|
||||
counter = 1;
|
||||
else
|
||||
counter++;
|
||||
|
||||
// output a certain volt
|
||||
if (counter <= (PulsePeriod - PulseWidth)) {
|
||||
outputV = Volt1;
|
||||
DAC_outputV(Volt1);
|
||||
} else {
|
||||
outputV = Volt2;
|
||||
DAC_outputV(Volt2);
|
||||
}
|
||||
|
||||
|
||||
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
|
||||
|
||||
// check if we reach the final volt
|
||||
if (((outputV >= INSTRUCTION.VoltFinal) && direction_up) || ((outputV <= INSTRUCTION.VoltFinal) && !direction_up)) {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
}
|
||||
|
||||
// check overflow/underflow and prepare for next output
|
||||
if (direction_up) {
|
||||
if (Volt1 + INSTRUCTION.Step < Volt1)
|
||||
Volt1 = 0xffff;
|
||||
else
|
||||
Volt1 = Volt1 + INSTRUCTION.Step;
|
||||
if (Volt2 + INSTRUCTION.Step < Volt2)
|
||||
Volt2 = 0xffff;
|
||||
else
|
||||
Volt2 = Volt2 + INSTRUCTION.Step;
|
||||
} else {
|
||||
if (Volt1 - INSTRUCTION.Step > Volt1)
|
||||
Volt1 = 0x0000;
|
||||
else
|
||||
Volt1 = Volt1 - INSTRUCTION.Step;
|
||||
if (Volt2 - INSTRUCTION.Step > Volt2)
|
||||
Volt2 = 0x0000;
|
||||
else
|
||||
Volt2 = Volt2 - INSTRUCTION.Step;
|
||||
}
|
||||
|
||||
if (counter + 1 <= (PulsePeriod - PulseWidth)) {
|
||||
return Volt1;
|
||||
} else {
|
||||
return Volt2;
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t CVCurve() {
|
||||
static uint8_t ramp0;
|
||||
static uint8_t ramp1;
|
||||
static uint16_t outputV;
|
||||
static bool direction_up;
|
||||
static bool current_direction_up;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACReset) {
|
||||
outputV = INSTRUCTION.VoltOrigin;
|
||||
if (INSTRUCTION.VoltFinal > INSTRUCTION.VoltOrigin) {
|
||||
direction_up = true;
|
||||
current_direction_up = true;
|
||||
} else {
|
||||
direction_up = false;
|
||||
current_direction_up = false;
|
||||
}
|
||||
ramp0 = (uint8_t)(INSTRUCTION.VoltOrigin & 0x00FF); // right byte
|
||||
ramp1 = (uint8_t)((INSTRUCTION.VoltOrigin >> 8) & 0x00FF); // left byte
|
||||
DACReset = false;
|
||||
}
|
||||
|
||||
// output a certain volt
|
||||
DAC_outputV(outputV);
|
||||
|
||||
if (direction_up) {
|
||||
if (outputV >= INSTRUCTION.VoltFinal) {
|
||||
current_direction_up = false; // problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
} else if (outputV <= INSTRUCTION.VoltOrigin) {
|
||||
current_direction_up = true;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; // periodic event end
|
||||
DACReset = true;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
} else {
|
||||
if (outputV <= INSTRUCTION.VoltFinal) {
|
||||
current_direction_up = true; // problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
} else if (outputV >= INSTRUCTION.VoltOrigin) {
|
||||
current_direction_up = false;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; // periodic event end
|
||||
DACReset = true;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_direction_up) {
|
||||
if (outputV + INSTRUCTION.Step < outputV)
|
||||
outputV = 0xffff;
|
||||
else
|
||||
outputV = outputV + INSTRUCTION.Step;
|
||||
} else {
|
||||
if (outputV - INSTRUCTION.Step > outputV)
|
||||
outputV = 0x0000;
|
||||
else
|
||||
outputV = outputV - INSTRUCTION.Step;
|
||||
}
|
||||
|
||||
return outputV;
|
||||
}
|
||||
|
||||
#endif
|
||||
+26
-28
@@ -2,41 +2,38 @@
|
||||
#ifndef EliteDAC
|
||||
#define EliteDAC
|
||||
|
||||
static bool DACreset = true;
|
||||
/* DAC reset parameter */
|
||||
#define DACzero 0x85B2
|
||||
#define DACposMax 0x0000
|
||||
#define DACnegMax 0xFFFF
|
||||
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 void DAC_outputV(uint16_t voltLV) {
|
||||
static uint16_t DAC_outputV(uint16_t voltLV) {
|
||||
// C = command, X = don't care, D = data
|
||||
// CCCC CCCC = command
|
||||
// DDDD DDDD = v1
|
||||
@@ -55,6 +52,7 @@ static void DAC_outputV(uint16_t voltLV) {
|
||||
spi_DACtxbuf[2] = v2;
|
||||
|
||||
DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
|
||||
return voltLV;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+355
-130
@@ -1,30 +1,10 @@
|
||||
|
||||
#ifndef EliteCorrection
|
||||
#define EliteCorrection
|
||||
|
||||
#include "EliteDAC.h"
|
||||
#include "EliteADC.h"
|
||||
|
||||
/* DAC reset parameter */
|
||||
#define DACzero 0x85A2
|
||||
#define DACposMax 0x0000
|
||||
#define DACnegMax 0xFFFF
|
||||
|
||||
typedef struct _formula{
|
||||
|
||||
int32_t coeff = 0;
|
||||
int32_t offset = 0;
|
||||
|
||||
}Formula;
|
||||
|
||||
typedef struct _correction{
|
||||
|
||||
Formula ADC_volt = 0;
|
||||
Formula ADC_current[3] = 0;
|
||||
uint32_t Gain0Boundary[2] = {0, 0};
|
||||
uint32_t Gain1BoundARY[2] = {0, 0};
|
||||
|
||||
}Correction_data;
|
||||
|
||||
/*
|
||||
* Correction Array include all the correction coeff and offset
|
||||
@@ -34,140 +14,397 @@ typedef struct _correction{
|
||||
* code is the code we read from ADC buffer
|
||||
*
|
||||
* ADC measure Voltage
|
||||
* Correction[0] = ADC Volt coeff
|
||||
* Correction[1] = ADC Volt offset => RealVolt = Correction[0] * code + Correction[1]
|
||||
* RealVolt = Correction.ADC_volt.coeff * code + Correction.ADC_volt.offset
|
||||
*
|
||||
* ADC measure Current
|
||||
* Correctino[2] = ADC gain_lv0 coeff
|
||||
* Correction[3] = ADC gain_lv0 offset => RealCurrent = Correction[2] * code + Correction[3]
|
||||
* Correctino[4] = ADC gain_lv1 coeff
|
||||
* Correction[5] = ADC gain_lv1 offset => RealCurrent = Correction[4] * code + Correction[5]
|
||||
* Correctino[6] = ADC gain_lv2 coeff
|
||||
* Correction[7] = ADC gain_lv2 offset => RealCurrent = Correction[6] * code + Correction[7]
|
||||
* ADCGain: 0 => 200k, 1 => 10k, 2 => 200R
|
||||
* RealCurrent = Correction.ADC_current[ADCGain].coeff * code + Correction.ADC_current[ADCGain].offset
|
||||
*
|
||||
* DAC output Voltage
|
||||
* Correction[8] = DAC coeff
|
||||
* Correction[9] = DAC offset => RealVolt = Correction[8] * DACcode + Correction[9]
|
||||
* RealVolt = Correction.DAC2RealV.coeff * DACcode + Correction.DAC2RealV.offset
|
||||
*
|
||||
* Usercode to DACcode
|
||||
* DACcode = Correction.Usercode2DAC.coeff * code + Correction.Usercode2DAC.offset
|
||||
*
|
||||
*/
|
||||
#define BORAD_Chao_I
|
||||
|
||||
#ifdef BORAD_CLASS_LEADER
|
||||
static Correction_data Correction;
|
||||
|
||||
Correction.ADC_volt.coeff = (-629);
|
||||
Correction.ADC_volt.offset = 15447740;
|
||||
#define BOARD_GENIUS
|
||||
|
||||
Correction.ADC_current_200k.coeff = 3056;
|
||||
Correction.ADC_current_200k.offset = -74771591;
|
||||
typedef struct _formula{
|
||||
|
||||
Correction.ADC_current_10K.coeff = 65461;
|
||||
Correction.ADC_current_10K.offset = -1601786957;
|
||||
long long coeff;
|
||||
long long offset;
|
||||
|
||||
Correction.ADC_current_200R.coeff = 3369;
|
||||
Correction.ADC_current_200R.offset = -82598293;
|
||||
}Formula;
|
||||
|
||||
Correction.Gain0Boundary[0] = 0x5F75;
|
||||
Correction.Gain0Boundary[1] = 0x5FB2;
|
||||
struct _correction{
|
||||
|
||||
Correction.Gain1Boundary[0] = 0x5999;
|
||||
Correction.Gain1Boundary[1] = 0x6589;
|
||||
Formula ADC_volt;
|
||||
Formula ADC_current[3];
|
||||
Formula DAC2RealV;
|
||||
Formula Usercode2DAC;
|
||||
uint16_t Gain0Boundary[2];
|
||||
uint16_t Gain1Boundary[4];
|
||||
uint16_t Gain2Boundary[2];
|
||||
|
||||
} Correction =
|
||||
#ifdef BOARD_CLASS_LEADER
|
||||
{
|
||||
.ADC_volt.coeff = (-6292889),
|
||||
.ADC_volt.offset = 103042367157,
|
||||
|
||||
.ADC_current[0].coeff = 310073435,
|
||||
.ADC_current[0].offset = -5059684947850,
|
||||
|
||||
.ADC_current[1].coeff = 655940088,
|
||||
.ADC_current[1].offset = -10703396200801,
|
||||
|
||||
.ADC_current[2].coeff = 31129894,
|
||||
.ADC_current[2].offset = -507980196120,
|
||||
|
||||
.DAC2RealV.coeff = (-18959656),
|
||||
.DAC2RealV.offset = 565743281498,
|
||||
|
||||
.Usercode2DAC.coeff = (-10548714),
|
||||
.Usercode2DAC.offset = 562100522714,
|
||||
|
||||
.Gain0Boundary[0] = 0x5F75,
|
||||
.Gain0Boundary[1] = 0x5FB2,
|
||||
|
||||
.Gain1Boundary[0] = 0x5999,
|
||||
.Gain1Boundary[1] = 0x6589
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BORAD_TRICERATOPS
|
||||
static Correction_data Correction;
|
||||
{
|
||||
.ADC_volt.coeff = (-6259045),
|
||||
.ADC_volt.offset = 150606390230,
|
||||
|
||||
Correction.ADC_volt.coeff = (-626);
|
||||
Correction.ADC_volt.offset = 15065046;
|
||||
.ADC_current[0].coeff = 27661202,
|
||||
.ADC_current[0].offset = (-664225386769),
|
||||
|
||||
Correction.ADC_current_200k.coeff = 0;
|
||||
Correction.ADC_current_200k.offset = 0;
|
||||
.ADC_current[1].coeff = 663176124,
|
||||
.ADC_current[1].offset = (-15925056526152),
|
||||
|
||||
Correction.ADC_current_10K.coeff = 0;
|
||||
Correction.ADC_current_10K.offset = 0;
|
||||
.ADC_current[2].coeff = 31242587,
|
||||
.ADC_current[2].offset = (-750184492407),
|
||||
|
||||
Correction.ADC_current_200R.coeff = 0;
|
||||
Correction.ADC_current_200R.offset = 0;
|
||||
.DAC2RealV.coeff = (-18909689),
|
||||
.DAC2RealV.offset = 644251481046,
|
||||
|
||||
Correction.Gain0Boundary[0] = 0;
|
||||
Correction.Gain0Boundary[1] = 0;
|
||||
.Usercode2DAC.coeff = (-10576588),
|
||||
.Usercode2DAC.offset = 605113842000,
|
||||
|
||||
Correction.Gain1Boundary[0] = 0;
|
||||
Correction.Gain1Boundary[1] = 0;
|
||||
.Gain0Boundary[0] = 0x5DAA,
|
||||
.Gain0Boundary[1] = 0x5DF2,
|
||||
|
||||
.Gain1Boundary[0] = 0x57E8,
|
||||
.Gain1Boundary[1] = 0x63B1
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BORAD_Chao_I
|
||||
static Correction_data Correction;
|
||||
#ifdef BORAD_CHAO_I
|
||||
{
|
||||
.ADC_volt.coeff = (-6278082),
|
||||
.ADC_volt.offset = 151228681410,
|
||||
|
||||
Correction.ADC_volt.coeff = (-627);
|
||||
Correction.ADC_volt.offset = 15122868;
|
||||
.ADC_current[0].coeff = 30908391,
|
||||
.ADC_current[0].offset = (-741477595514),
|
||||
|
||||
Correction.ADC_current_200k.coeff = 3091;
|
||||
Correction.ADC_current_200k.offset = (-74147760);
|
||||
.ADC_current[1].coeff = 661271310,
|
||||
.ADC_current[1].offset = (-15864495597969),
|
||||
|
||||
Correction.ADC_current_10K.coeff = 66127;
|
||||
Correction.ADC_current_10K.offset = (-1586449560);
|
||||
.ADC_current[2].coeff = 31183513,
|
||||
.ADC_current[2].offset = (-748178468530),
|
||||
|
||||
Correction.ADC_current_200R.coeff = 3118;
|
||||
Correction.ADC_current_200R.offset = (74817847);
|
||||
.DAC2RealV.coeff = (-18975108),
|
||||
.DAC2RealV.offset = 644442607989,
|
||||
|
||||
Correction.Gain0Boundary[0] = 0x5D96;
|
||||
Correction.Gain0Boundary[1] = 0x5DD9;
|
||||
.Usercode2DAC.coeff = (-10540121),
|
||||
.Usercode2DAC.offset = 603128277368,
|
||||
|
||||
Correction.Gain1Boundary[0] = 0x57CD;
|
||||
Correction.Gain1Boundary[1] = 0x639F;
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_TWENTY_ONE
|
||||
static Correction_data Correction;
|
||||
{
|
||||
.ADC_volt.coeff = (-6258074),
|
||||
.ADC_volt.offset = 152210580945,
|
||||
|
||||
Correction.ADC_volt.coeff = (-625);
|
||||
Correction.ADC_volt.offset = 15221058;
|
||||
.ADC_current[0].coeff = 30022512,
|
||||
.ADC_current[0].offset = -729552647201,
|
||||
|
||||
Correction.ADC_current[0].coeff = 3002;
|
||||
Correction.ADC_current[0].offset = -72955265;
|
||||
.ADC_current[1].coeff = 658398533,
|
||||
.ADC_current[1].offset = -16001498741131,
|
||||
|
||||
Correction.ADC_current[1].coeff = 65840;
|
||||
Correction.ADC_current[1].offset = -1600149874;
|
||||
.ADC_current[2].coeff = 30908351,
|
||||
.ADC_current[2].offset = -746548614824,
|
||||
|
||||
Correction.ADC_current[2].coeff = 3090;
|
||||
Correction.ADC_current[2].offset = -75102578;
|
||||
.DAC2RealV.coeff = (-19007867),
|
||||
.DAC2RealV.offset = 646316924837,
|
||||
|
||||
Correction.Gain0Boundary[0] = 0x5ECD;
|
||||
Correction.Gain0Boundary[1] = 0x5F0D;
|
||||
.Usercode2DAC.coeff = (-10521952),
|
||||
.Usercode2DAC.offset = 603074812599,
|
||||
|
||||
Correction.Gain1Boundary[0] = 0x5900;
|
||||
Correction.Gain1Boundary[1] = 0x64DD;
|
||||
.Gain0Boundary[0] = 0x5ECD,
|
||||
.Gain0Boundary[1] = 0x5F0D,
|
||||
|
||||
.Gain1Boundary[0] = 0x5900,
|
||||
.Gain1Boundary[1] = 0x64DD
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_JOHN_CENA
|
||||
{
|
||||
.ADC_volt.coeff = (-6286465),
|
||||
.ADC_volt.offset = 151630618248,
|
||||
|
||||
.ADC_current[0].coeff = 30960625,
|
||||
.ADC_current[0].offset = -747979808432,
|
||||
|
||||
.ADC_current[1].coeff = 652738209,
|
||||
.ADC_current[1].offset = -15767733896990,
|
||||
|
||||
.ADC_current[2].coeff = 30959456,
|
||||
.ADC_current[2].offset = -748026885843,
|
||||
|
||||
.DAC2RealV.coeff = (-18880478),
|
||||
.DAC2RealV.offset = 629012735316,
|
||||
|
||||
.Usercode2DAC.coeff = (-10592952),
|
||||
.Usercode2DAC.offset = 604535526400,
|
||||
|
||||
.Gain0Boundary[0] = 0x7653, // 20 uA
|
||||
.Gain0Boundary[1] = 0x4504, // -20 uA
|
||||
|
||||
.Gain1Boundary[0] = 0x7C69, // 500 uA
|
||||
.Gain1Boundary[1] = 0x405D, // -500 uA
|
||||
.Gain1Boundary[2] = 0x5F4A, // 10 uA
|
||||
.Gain1Boundary[3] = 0x5D7D, // -10 uA
|
||||
|
||||
.Gain2Boundary[0] = 0x5EC2, // 300 uA
|
||||
.Gain2Boundary[1] = 0x5E01, // -300 uA
|
||||
//.Gain0SupportRange =
|
||||
//.Gain1SupportRange[0] =
|
||||
//.Gain1SupportRange[1] =
|
||||
//.Gain2SupportRange =
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BOARD_GENIUS
|
||||
{
|
||||
.ADC_volt.coeff = (-6236652),
|
||||
.ADC_volt.offset = 101533279052,
|
||||
|
||||
.ADC_current[0].coeff = 309083900,
|
||||
.ADC_current[0].offset = (-7414775955140),
|
||||
|
||||
.ADC_current[1].coeff = 31218018,
|
||||
.ADC_current[1].offset = (-508593562044),
|
||||
|
||||
.ADC_current[2].coeff = 557826631,
|
||||
.ADC_current[2].offset = (-9088752534070),
|
||||
|
||||
.DAC2RealV.coeff = (-18990774),
|
||||
.DAC2RealV.offset = 570886531263,
|
||||
|
||||
.Usercode2DAC.coeff = (-10605006),
|
||||
.Usercode2DAC.offset = 566878948150,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_DA_SHUN
|
||||
{
|
||||
.ADC_volt.coeff = (-6280824),
|
||||
.ADC_volt.offset = 151787055168,
|
||||
|
||||
.ADC_current[0].coeff = 25109217,
|
||||
.ADC_current[0].offset = (-606888506534),
|
||||
|
||||
.ADC_current[1].coeff = 657619639,
|
||||
.ADC_current[1].offset = (-15894373245404),
|
||||
|
||||
.ADC_current[2].coeff = 31040178,
|
||||
.ADC_current[2].offset = (-750263570000),
|
||||
|
||||
.DAC2RealV.coeff = (-18975834),
|
||||
.DAC2RealV.offset = 647359124391,
|
||||
|
||||
.Usercode2DAC.coeff = (-10539718),
|
||||
.Usercode2DAC.offset = 604829309500,
|
||||
|
||||
.Gain0Boundary[0] = 0x5E2F,
|
||||
.Gain0Boundary[1] = 0x5E96,
|
||||
|
||||
.Gain1Boundary[0] = 0x5878,
|
||||
.Gain1Boundary[1] = 0x645A
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_CHIEN_YU
|
||||
{
|
||||
.ADC_volt.coeff = (-6279056),
|
||||
.ADC_volt.offset = 150985844279,
|
||||
|
||||
.ADC_current[0].coeff = 31788227 ,
|
||||
.ADC_current[0].offset = (-765340735866),
|
||||
|
||||
.ADC_current[1].coeff = 657619858,
|
||||
.ADC_current[1].offset = (-15835988865283),
|
||||
|
||||
.ADC_current[2].coeff = 31116362,
|
||||
.ADC_current[2].offset = (-749402214847),
|
||||
|
||||
.DAC2RealV.coeff = (-18935149),
|
||||
.DAC2RealV.offset = 643063752893,
|
||||
|
||||
.Usercode2DAC.coeff = (-10567567),
|
||||
.Usercode2DAC.offset = 603991718526,
|
||||
|
||||
.Gain0Boundary[0] = 0x5DE5,
|
||||
.Gain0Boundary[1] = 0x5E30,
|
||||
|
||||
.Gain1Boundary[0] = 0x5820,
|
||||
.Gain1Boundary[1] = 0x6408
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_BAY_BAY
|
||||
{
|
||||
.ADC_volt.coeff = (-6279056),
|
||||
.ADC_volt.offset = 150985844279,
|
||||
|
||||
.ADC_current[0].coeff = 31788227 ,
|
||||
.ADC_current[0].offset = (-765340735866),
|
||||
|
||||
.ADC_current[1].coeff = 657619858,
|
||||
.ADC_current[1].offset = (-15835988865283),
|
||||
|
||||
.ADC_current[2].coeff = 31116362,
|
||||
.ADC_current[2].offset = (-749402214847),
|
||||
|
||||
.DAC2RealV.coeff = (-18935149),
|
||||
.DAC2RealV.offset = 643063752893,
|
||||
|
||||
.Usercode2DAC.coeff = (-10567567),
|
||||
.Usercode2DAC.offset = 603991718526,
|
||||
|
||||
.Gain0Boundary[0] = 0x5DE5,
|
||||
.Gain0Boundary[1] = 0x5E30,
|
||||
|
||||
.Gain1Boundary[0] = 0x5820,
|
||||
.Gain1Boundary[1] = 0x6408
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_KELLY
|
||||
{
|
||||
.ADC_volt.coeff = (-6279056),
|
||||
.ADC_volt.offset = 150985844279,
|
||||
|
||||
.ADC_current[0].coeff = 31788227 ,
|
||||
.ADC_current[0].offset = (-765340735866),
|
||||
|
||||
.ADC_current[1].coeff = 657619858,
|
||||
.ADC_current[1].offset = (-15835988865283),
|
||||
|
||||
.ADC_current[2].coeff = 31116362,
|
||||
.ADC_current[2].offset = (-749402214847),
|
||||
|
||||
.DAC2RealV.coeff = (-18935149),
|
||||
.DAC2RealV.offset = 643063752893,
|
||||
|
||||
.Usercode2DAC.coeff = (-10567567),
|
||||
.Usercode2DAC.offset = 603991718526,
|
||||
|
||||
.Gain0Boundary[0] = 0x5DE5,
|
||||
.Gain0Boundary[1] = 0x5E30,
|
||||
|
||||
.Gain1Boundary[0] = 0x5820,
|
||||
.Gain1Boundary[1] = 0x6408
|
||||
};
|
||||
#endif
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into real voltage
|
||||
// unit should be mV
|
||||
static int32_t DecodeADCVolt(uint16_t ADC_measure){
|
||||
int32_t ADCRealVolt = 0;
|
||||
long long ADCRealVolt = 0;
|
||||
|
||||
ADCRealVolt = (Correction.ADC_volt.coeff * ADC_measure + Correction.ADC_volt.offset);
|
||||
ADCRealVolt = ADCRealVolt / 1000;
|
||||
return ADCRealVolt;
|
||||
ADCRealVolt = ADCRealVolt / 1e7;
|
||||
|
||||
return (int32_t) (ADCRealVolt);
|
||||
}
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into real current
|
||||
// unit should be pA
|
||||
/* Decode ADC current for twenty-one */
|
||||
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
int32_t ADCRealCurrent = 0;
|
||||
int32_t coeff[3] = {0}, offset[3] = {0};
|
||||
long long ADCRealCurrent = 0;
|
||||
|
||||
ADCRealCurrent = (Correction.ADC_current[ADCGain].coeff * ADC_measure + Correction.ADC_current[ADCGain].offset)/1000;
|
||||
return ADCRealCurrent;
|
||||
ADCRealCurrent = (Correction.ADC_current[ADCGain].coeff * ADC_measure + Correction.ADC_current[ADCGain].offset)/1e7;
|
||||
|
||||
// Current unit is pA;
|
||||
// If ADCGain is GAIN_200R unit is nA
|
||||
return (int32_t) (ADCRealCurrent);
|
||||
}
|
||||
|
||||
static int32_t DecodeResister(uint8_t ADCGainLevel, uint16_t CurrentMeasure, uint16_t VoltMeasure){
|
||||
long long ADCRealResister = 0, ADCRealCurrent=0, ADCRealVolt=0;
|
||||
int32_t current_32, volt_32, resister_32;
|
||||
|
||||
// get measure current
|
||||
ADCRealCurrent = (Correction.ADC_current[ADCGainLevel].coeff * CurrentMeasure + Correction.ADC_current[ADCGainLevel].offset)/1e7;
|
||||
current_32 = (int32_t) (ADCRealCurrent);
|
||||
|
||||
// get measure volt
|
||||
// This step is necessary, if the measure resister !>> 10 ohm
|
||||
ADCRealVolt = (Correction.ADC_volt.coeff * VoltMeasure + Correction.ADC_volt.offset);
|
||||
ADCRealVolt = ADCRealVolt / 1e4;
|
||||
volt_32 = (int32_t) (ADCRealVolt);
|
||||
|
||||
if (INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
resister_32 = (int32_t) ((ADCRealVolt) / (ADCRealCurrent/1e3)); // nV / uA = mV
|
||||
}
|
||||
else{
|
||||
resister_32 = (int32_t) ((ADCRealVolt) / (ADCRealCurrent/1e6)); // nV / uA = mV
|
||||
}
|
||||
// NotifyVolt[0] = (uint8_t) (volt_32 >> 24);
|
||||
// NotifyVolt[1] = (uint8_t) ((volt_32 & 0x00FF0000) >> 16);
|
||||
// NotifyVolt[2] = (uint8_t) ((volt_32 & 0x0000FF00) >> 8);
|
||||
// NotifyVolt[3] = (uint8_t) (volt_32 & 0x000000FF);
|
||||
//
|
||||
// NotifyCurrent[0] = (uint8_t) (current_32 >> 24);
|
||||
// NotifyCurrent[1] = (uint8_t) ((current_32 & 0x00FF0000) >> 16);
|
||||
// NotifyCurrent[2] = (uint8_t) ((current_32 & 0x0000FF00) >> 8);
|
||||
// NotifyCurrent[3] = (uint8_t) (current_32 & 0x000000FF);
|
||||
|
||||
NotifyImpedance[0] = (uint8_t) (resister_32 >> 24);
|
||||
NotifyImpedance[1] = (uint8_t) ((resister_32 & 0x00FF0000) >> 16);
|
||||
NotifyImpedance[2] = (uint8_t) ((resister_32 & 0x0000FF00) >> 8);
|
||||
NotifyImpedance[3] = (uint8_t) (resister_32 & 0x000000FF);
|
||||
|
||||
return resister_32;
|
||||
}
|
||||
|
||||
// Decode ADC measure value (could be a volt or current) and put it into notify buffer
|
||||
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){
|
||||
|
||||
uint16_t ADC_measure = (uint16_t) (ADC_raw[0] << 8) | (uint16_t) (ADC_raw[1]);
|
||||
int32_t ADCRealVolt = 0, ret = 0;
|
||||
int32_t ADCRealVolt = 0, ret = 0, ADCRealCurrent = 0, ADCRealResister = 0;
|
||||
|
||||
// return real volt to controller
|
||||
if(ADCChannel == ADC_CH_VOLT){
|
||||
@@ -181,26 +418,20 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
|
||||
|
||||
// return real current to controller
|
||||
else if(ADCChannel == ADC_CH_CURRENT){
|
||||
|
||||
if (INSTRUCTION.eliteFxn == IVCurve) {
|
||||
ADCRealCurrent += DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
|
||||
if ((SampleRate_counter % 10) == 0) {
|
||||
ADCRealCurrent = ADCRealCurrent / 10;
|
||||
|
||||
if (avg_number > 2) { // to discard the first 20 current sample data
|
||||
ADCRealCurrent_avg = (ADCRealCurrent + ADCRealCurrent_avg*(avg_number - 3)) / (avg_number - 2);
|
||||
}
|
||||
avg_number ++;
|
||||
ADCRealCurrent = 0;
|
||||
}
|
||||
if (StepTimeCounter == StepTime - 1) {
|
||||
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent_avg >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent_avg & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent_avg & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent_avg & 0x000000FF);
|
||||
avg_number = 1;
|
||||
ADCRealCurrent_avg = 0;
|
||||
if (INSTRUCTION.eliteFxn == IV_CURVE) {
|
||||
|
||||
ADCRealCurrent_long += DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
avg_number++;
|
||||
|
||||
if (StepTimeCounter == INSTRUCTION.StepTime) {
|
||||
ADCRealCurrent_long = ADCRealCurrent_long / avg_number;
|
||||
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent_long >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent_long & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent_long & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent_long & 0x000000FF);
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -211,7 +442,7 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
|
||||
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent & 0x000000FF);
|
||||
ret = ADCRealCurrent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
@@ -256,35 +487,29 @@ static void ADC_overflow(uint8_t gain, uint8_t *rawdata){
|
||||
// User will enter -5V~+5V in UI.
|
||||
// websever and controler use 0~50000 represent -5~+5V
|
||||
// this function should turn 0~50000 into DACcode which output the exactly voltage user want
|
||||
|
||||
static uint16_t Usercode_Correction_to_DAC(uint16_t usercode)
|
||||
{
|
||||
// DACcode to real_voltage correction function
|
||||
//DACcode = -1.0548523(usercode) + 60597.718
|
||||
int32_t usercode_32;
|
||||
long long usercode_32;
|
||||
uint16_t DACcode = 0;
|
||||
int32_t coeff = (-1054), offset = 60597718;
|
||||
|
||||
usercode_32 = (int32_t)(usercode);
|
||||
usercode_32 = (long long)(usercode);
|
||||
|
||||
DACcode = (uint16_t) ((coeff * usercode_32 + offset)/1000);
|
||||
DACcode = (uint16_t) ((Correction.Usercode2DAC.coeff * usercode_32 + Correction.Usercode2DAC.offset)/1e7);
|
||||
|
||||
return DACcode;
|
||||
}
|
||||
|
||||
|
||||
static int32_t DAC_to_realV(uint16_t DACcode)
|
||||
{
|
||||
//volt = (DAC -6.4893275)/(-0.0001896)
|
||||
|
||||
int32_t RealV = 0;
|
||||
int32_t volt_32 = 0;
|
||||
int32_t coeff = (-1896), offset = 64893275;//*10e7
|
||||
long long usercode_32;
|
||||
|
||||
volt_32 = DACcode;
|
||||
// RealV = (volt_32 - offset) / coeff;
|
||||
RealV = (-1896) * volt_32 + offset;
|
||||
RealV = RealV / 10e3; //(mV)
|
||||
usercode_32 = ((DACcode * 1e7) - Correction.Usercode2DAC.offset) / Correction.Usercode2DAC.coeff;
|
||||
|
||||
RealV = (int32_t) (usercode_32 / 5) - 5000;
|
||||
|
||||
// return mV
|
||||
return RealV;
|
||||
}
|
||||
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/* Copyright (c) 2019. BioPro. Scientific.
|
||||
*/
|
||||
#ifndef HEADSTAGE_GPTIMER_H
|
||||
#define HEADSTAGE_GPTIMER_H
|
||||
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/timer/GPTimerCC26XX.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <xdc/runtime/Types.h>
|
||||
|
||||
#define EVT_PERIODIC_GPTIMER EVT_PERIODIC_0
|
||||
|
||||
static GPTimerCC26XX_Handle gptimer_handle;
|
||||
|
||||
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
|
||||
|
||||
#define elite_gptimer_start() GPTimerCC26XX_start(gptimer_handle)
|
||||
#define elite_gptimer_stop() GPTimerCC26XX_stop(gptimer_handle)
|
||||
#define elite_gptimer_close() GPTimerCC26XX_close(gptimer_handle)
|
||||
#define CLOCK_FREQ 4000 // clock freq = 0.1 ms
|
||||
|
||||
#define elite_gptimer_open() \
|
||||
do { \
|
||||
GPTimerCC26XX_Params params; \
|
||||
GPTimerCC26XX_Params_init(¶ms); \
|
||||
params.width = GPT_CONFIG_16BIT; \
|
||||
params.mode = GPT_MODE_PERIODIC_DOWN; \
|
||||
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; \
|
||||
gptimer_handle = GPTimerCC26XX_open(Board_GPTIMER0A, ¶ms); \
|
||||
Types_FreqHz freq; \
|
||||
BIOS_getCpuFreq(&freq); \
|
||||
GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; /*47999*/ \
|
||||
GPTimerCC26XX_setLoadValue(gptimer_handle, loadVal); \
|
||||
GPTimerCC26XX_setLoadValue(gptimer_handle, CLOCK_FREQ); /* 0.1 ms*/ \
|
||||
GPTimerCC26XX_registerInterrupt(gptimer_handle, elite_gptimer_callback, GPT_INT_TIMEOUT); \
|
||||
} while (0)
|
||||
|
||||
#endif // HEADSTAGE_GPTIMER_H
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
|
||||
#ifndef ELITEIT
|
||||
#define ELITEIT
|
||||
|
||||
static int32_t IT_Plot() {
|
||||
// read ADC current
|
||||
int32_t Real_Current = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// check if ADC over/under flow
|
||||
// let the output saturate if over/under flow
|
||||
// ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
#endif
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
|
||||
#ifndef ELITEIV
|
||||
#define ELITEIV
|
||||
|
||||
static uint16_t VoltScan() {
|
||||
uint16_t Voltage;
|
||||
if (INSTRUCTION.VoltOrigin == INSTRUCTION.VoltFinal) {
|
||||
Voltage = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
|
||||
DAC_outputV(Voltage);
|
||||
PeriodicEvent = false;
|
||||
return Voltage;
|
||||
} else if (INSTRUCTION.eliteFxn == SQUARE_WAVE_VOLTAMMETRY) {
|
||||
Voltage = SWVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) {
|
||||
Voltage = DPVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) {
|
||||
Voltage = CVCurve();
|
||||
}
|
||||
|
||||
// IV plot mode
|
||||
else {
|
||||
Voltage = OneWayVoltScan();
|
||||
}
|
||||
|
||||
return Voltage;
|
||||
}
|
||||
|
||||
static uint16_t OneWayVoltScan() {
|
||||
static uint16_t DACOutCode;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACReset) {
|
||||
DACUserCode = INSTRUCTION.VoltOrigin;
|
||||
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
|
||||
DACReset = false;
|
||||
|
||||
// output VOLT_ORIGIN
|
||||
DAC_outputV(DACOutCode);
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
if (StepTimeCounter == INSTRUCTION.StepTime) {
|
||||
if (INSTRUCTION.VoltOrigin < INSTRUCTION.VoltFinal) {
|
||||
// output the next output volt
|
||||
DACUserCode = DACUserCode + INSTRUCTION.Step;
|
||||
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
// end IV task if we reach INSTRUCTION.VoltFinal
|
||||
if (DACUserCode >= INSTRUCTION.VoltFinal) {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
}
|
||||
} else {
|
||||
// output the next output volt
|
||||
DACUserCode = DACUserCode - INSTRUCTION.Step;
|
||||
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
// end IV task if we reach INSTRUCTION.VoltFinal
|
||||
if (DACUserCode <= INSTRUCTION.VoltFinal) {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
#endif
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
|
||||
#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
|
||||
|
||||
/** Resister meter **/
|
||||
#define RESISTER_METER_SMALL 0x00
|
||||
#define RESISTER_METER_MIDDLE1 0x01
|
||||
#define RESISTER_METER_MIDDLE2 0x02
|
||||
#define RESISTER_METER_LARGE 0x03
|
||||
|
||||
/** CC mode parameter **/
|
||||
// CurrentLV
|
||||
#define CURRENT_LV_NA 0x00
|
||||
#define CURRENT_LV_UA 0x01
|
||||
#define CURRENT_LV_MA 0x02
|
||||
|
||||
/*==============================
|
||||
==== headstage instruction ====
|
||||
=============================*/
|
||||
struct HEADSTAGE_INSTRUCTION {
|
||||
/** chip ID */
|
||||
uint8_t chip_id;
|
||||
|
||||
/** Sample rate **/
|
||||
// SampleRate = SampleRateTable[SampleRateIndex]
|
||||
uint8_t SampleRateIndex;
|
||||
uint16_t SampleRate;
|
||||
|
||||
/** DAC parameter **/
|
||||
// volt san parameter
|
||||
uint16_t VoltOrigin;
|
||||
uint16_t VoltFinal;
|
||||
uint16_t Step;
|
||||
uint8_t StepTime;
|
||||
// constant volt
|
||||
uint16_t VoltConstant;
|
||||
|
||||
/** ADC parameter **/
|
||||
uint8_t ADCGainLevel;
|
||||
|
||||
/** Constant Current Parameter **/
|
||||
uint8_t CurrentLV; // nA? uA? mA?
|
||||
uint32_t ConstantCurrent;
|
||||
|
||||
/** Resister Measure **/
|
||||
uint8_t ResisterMeter;
|
||||
|
||||
// elite function
|
||||
uint8_t eliteFxn;
|
||||
|
||||
uint8_t CycleNumber;
|
||||
|
||||
} INSTRUCTION = {0};
|
||||
|
||||
/*********************************************************************
|
||||
* @fn InitEliteInstruction
|
||||
*
|
||||
* @brief Init all INSTRUCTION variable.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void InitEliteInstruction(){
|
||||
INSTRUCTION.chip_id = 0;
|
||||
INSTRUCTION.SampleRateIndex = 1;
|
||||
INSTRUCTION.SampleRate = 10;
|
||||
INSTRUCTION.VoltOrigin = DAC_ZERO;
|
||||
INSTRUCTION.VoltFinal = DAC_POS_MAX;
|
||||
INSTRUCTION.Step = 0x0005; // 0x0005 = 1mV
|
||||
INSTRUCTION.StepTime = STEPTIME_HALF_SEC; // about 0.5 sec
|
||||
INSTRUCTION.VoltConstant = 24999; // is about 0V
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
INSTRUCTION.ResisterMeter = RESISTER_METER_SMALL;
|
||||
INSTRUCTION.CurrentLV = 0x00;
|
||||
INSTRUCTION.ConstantCurrent = 0x00000000;
|
||||
INSTRUCTION.eliteFxn = 0; // default is a null event
|
||||
INSTRUCTION.CycleNumber = 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
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
|
||||
#ifndef ELITEKEYDETECT
|
||||
#define ELITEKEYDETECT
|
||||
|
||||
#define CLOCK_ONE_SECOND 10000
|
||||
|
||||
static bool TurnOnElite(uint8_t key) {
|
||||
static uint16_t TurnOnCounter = 0;
|
||||
|
||||
if (key == 0) {
|
||||
// press 1 sec, power on LED
|
||||
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 1); // enable 5V
|
||||
TurnOn10V();
|
||||
LEDPowerON();
|
||||
return true;
|
||||
} else {
|
||||
TurnOnCounter++;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
TurnOnCounter = 0;
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 0); // enable 5V
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteKeyPress(uint8_t key) {
|
||||
static uint16_t ShutDownCounter = 0;
|
||||
static uint8_t OriginEliteFxn = 0;
|
||||
|
||||
if (key == 0) {
|
||||
// key = 0 if press
|
||||
// press key => bight LED
|
||||
|
||||
if (ShutDownCounter == CLOCK_ONE_SECOND) {
|
||||
KeyWorkModeLED();
|
||||
}
|
||||
|
||||
// press 3~4 sec, shutdown 2650
|
||||
else if (ShutDownCounter > (CLOCK_ONE_SECOND*3) ) {
|
||||
LED_color(DARKLED, 0xFF, 0xFF, 0x00);
|
||||
PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
|
||||
}
|
||||
ShutDownCounter ++;
|
||||
} else {
|
||||
if (OriginEliteFxn == INSTRUCTION.eliteFxn) { // old function == currunt instruction
|
||||
if (ShutDownCounter != 0) {
|
||||
// dark LED
|
||||
WorkModeLED();
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
} else { // old function != currunt instruction
|
||||
OriginEliteFxn = INSTRUCTION.eliteFxn;
|
||||
if (ShutDownCounter != 0) {
|
||||
ShutDownCounter = 0;
|
||||
}
|
||||
// dark mode LED
|
||||
WorkModeLED();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TurnOn10V() {
|
||||
If10Von = true;
|
||||
PIN_setOutputValue(pin_handle, enable_10v, 1);
|
||||
CPUdelay(8000);
|
||||
}
|
||||
|
||||
#endif
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
|
||||
#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)
|
||||
|
||||
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
spi_LEDtxbuf[0] = 0x0000;
|
||||
spi_LEDtxbuf[1] = 0x0000;
|
||||
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
|
||||
spi_LEDtxbuf[i] = 0xE000 | ((uint16_t)bright << 8) | blue;
|
||||
spi_LEDtxbuf[i + 1] = ((uint16_t)green << 8) | red;
|
||||
}
|
||||
|
||||
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
|
||||
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();
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY: {
|
||||
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 VIS_RST: {
|
||||
LEDPowerON();
|
||||
break;
|
||||
}
|
||||
case ADC_TEST: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
LEDPowerON();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void KeyWorkModeLED() {
|
||||
KEYLED();
|
||||
/*
|
||||
switch(INSTRUCTION.eliteFxn){
|
||||
case IV_CURVE:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#endif
|
||||
+52
@@ -30,6 +30,37 @@ static uint8_t NotifyImpedance[4] = {0};
|
||||
*/
|
||||
static uint32_t notify_counter = 0;
|
||||
|
||||
// ****************** New Notify Format ******************************** //
|
||||
/*
|
||||
* Notify format
|
||||
*
|
||||
*
|
||||
| | 1 | 2 | 3 |
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
|
||||
-----------------------------------------------------------------
|
||||
| header |
|
||||
| current |
|
||||
| voltage or impedance |
|
||||
| mode & gain |
|
||||
| time stamp |
|
||||
| cycle number |
|
||||
|
||||
|
||||
mode & gain
|
||||
this byte include Elite working mode and ADC gain level
|
||||
we use "(mode & 0xF0) | (gain & 0x0F)" to encode these two information
|
||||
|
||||
cycle number
|
||||
for cyclic voltammetry use, we save it as channel number.
|
||||
0xFF
|
||||
|
||||
* header = device ID
|
||||
* I = current (0.001nA), V = voltage (mV),
|
||||
* Z = impedance (k ohm), T = time (ms)
|
||||
*
|
||||
*
|
||||
*/
|
||||
// ********* End New Format Notify ***************************************** //
|
||||
|
||||
/*
|
||||
* Notify format
|
||||
@@ -55,6 +86,27 @@ static uint32_t notify_counter = 0;
|
||||
*
|
||||
*
|
||||
*/
|
||||
static void SendNotify() {
|
||||
not_buf[0] = INSTRUCTION.chip_id;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
not_buf[i + 1] = NotifyCurrent[i];
|
||||
not_buf[i + 5] = NotifyVolt[i];
|
||||
not_buf[i + 9] = NotifyImpedance[i];
|
||||
}
|
||||
|
||||
// 1 Timestamp = 32 usec; 31 Timestamp ~= 1 msec
|
||||
not_time_stamp = (Timestamp_get32()) / 31; // msec
|
||||
|
||||
not_buf[13] = not_time_stamp & 0xff;
|
||||
not_buf[14] = (not_time_stamp >> 8) & 0xff;
|
||||
not_buf[15] = (not_time_stamp >> 16) & 0xff;
|
||||
not_buf[16] = (not_time_stamp >> 24) & 0xff;
|
||||
|
||||
// cyclic voltametry cycle number
|
||||
not_buf[17] = INSTRUCTION.CycleNumber;
|
||||
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
|
||||
#ifndef ELITERESET
|
||||
#define ELITERESET
|
||||
|
||||
static void reset() {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
CCModeReset = 1;
|
||||
InitEliteInstruction();
|
||||
SampleRate_counter = 1;
|
||||
StepTimeCounter = 1;
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
if (INSTRUCTION.eliteFxn == CONSTANT_CURRENT){
|
||||
INSTRUCTION.eliteFxn = 0;
|
||||
|
||||
}
|
||||
|
||||
LEDPowerON();
|
||||
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++) {
|
||||
ins_buf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_LED_SIZE; i++) {
|
||||
spi_LEDtxbuf[i] = 0;
|
||||
spi_LEDrxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_DAC_SIZE; i++) {
|
||||
spi_DACtxbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_ADC_SIZE; i++) {
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++) {
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
CPUdelay(1600);
|
||||
}
|
||||
|
||||
static void Eliteinterrupt() {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
CCModeReset = 1;
|
||||
InitEliteInstruction();
|
||||
StepTimeCounter = 1;
|
||||
SampleRate_counter = 1;
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
|
||||
LEDPowerON();
|
||||
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++) {
|
||||
ins_buf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_LED_SIZE; i++) {
|
||||
spi_LEDtxbuf[i] = 0;
|
||||
spi_LEDrxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_DAC_SIZE; i++) {
|
||||
spi_DACtxbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_ADC_SIZE; i++) {
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++) {
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
CPUdelay(8000);
|
||||
}
|
||||
|
||||
static void CleanBuffer() {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
CCModeReset = 1;
|
||||
// InitEliteInstruction();
|
||||
SampleRate_counter = 1;
|
||||
StepTimeCounter = 1;
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
|
||||
for (int i = 0; i < SPI_LED_SIZE; i++) {
|
||||
spi_LEDtxbuf[i] = 0;
|
||||
spi_LEDrxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_DAC_SIZE; i++) {
|
||||
spi_DACtxbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SPI_ADC_SIZE; i++) {
|
||||
spi_ADC_txbuf[i] = 0;
|
||||
spi_ADC_rxbuf[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++) {
|
||||
not_buf[i] = 0;
|
||||
}
|
||||
|
||||
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
CPUdelay(8000);
|
||||
}
|
||||
|
||||
#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
#ifndef ELITEVT
|
||||
#define ELITEVT
|
||||
|
||||
static void VT_Plot() {
|
||||
// ADC gain is don't care when measuring voltage
|
||||
uint8_t ADCGain = 0;
|
||||
|
||||
// read ADC volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
DecodeADCValue(ADCGain, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
#endif
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
|
||||
#ifndef ELITEZT
|
||||
#define ELITEZT
|
||||
|
||||
static void ZT_notify(int32_t impedance);
|
||||
|
||||
// output a certain voltage e.g. 2v
|
||||
// and measure the input voltage
|
||||
// => calculate the resister
|
||||
// change the output voltage step
|
||||
// => get a R-T curve (with resolution = 1 sample/volt step )
|
||||
static void ZT_Plot() {
|
||||
int32_t Real_Resister = 0;
|
||||
static uint16_t CurrentMeasure=0, VoltMeasure=0;
|
||||
uint8_t SPICurrent[SPI_ADC_SIZE]={0}, SPIVolt[SPI_ADC_SIZE]={0};
|
||||
static uint8_t VoltCurrentSwitch = 0;
|
||||
|
||||
// set ADC GAIN
|
||||
if(INSTRUCTION.ResisterMeter == RESISTER_METER_SMALL){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
}
|
||||
else if(INSTRUCTION.ResisterMeter == RESISTER_METER_MIDDLE1){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
}
|
||||
else if(INSTRUCTION.ResisterMeter == RESISTER_METER_MIDDLE2){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
}
|
||||
else{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
}
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
|
||||
if(VoltCurrentSwitch < 9){
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPICurrent);
|
||||
VoltCurrentSwitch ++;
|
||||
}
|
||||
else if(VoltCurrentSwitch == 9){
|
||||
// read current
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPICurrent);
|
||||
CurrentMeasure = (uint16_t) (SPICurrent[0] << 8) | (uint16_t) (SPICurrent[1]);
|
||||
VoltCurrentSwitch ++;
|
||||
}
|
||||
else if(VoltCurrentSwitch <18){
|
||||
// read volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPIVolt);
|
||||
VoltCurrentSwitch++;
|
||||
}
|
||||
else if(VoltCurrentSwitch == 18){
|
||||
// read volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPIVolt);
|
||||
VoltMeasure = (uint16_t) (SPIVolt[0] << 8) | (uint16_t) (SPIVolt[1]);
|
||||
VoltCurrentSwitch++;
|
||||
}
|
||||
else{
|
||||
VoltCurrentSwitch = 0;
|
||||
}
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
DecodeResister(INSTRUCTION.ADCGainLevel, CurrentMeasure, VoltMeasure);
|
||||
// Real_Resister = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
+159
-189
@@ -402,21 +402,12 @@ characteristic change event
|
||||
#endif // ICALL_EVENTS
|
||||
#include <ti/sysbios/hal/Hwi.h>
|
||||
#include <ti/sysbios/knl/Queue.h>
|
||||
#include "EliteADC.h"
|
||||
#include "EliteDAC.h"
|
||||
#include "EliteSPI.h"
|
||||
#include "Elite_PIN.h"
|
||||
|
||||
|
||||
#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)
|
||||
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
#include "EliteI2C.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_ICALL
|
||||
#include <icall.h>
|
||||
#else
|
||||
@@ -426,11 +417,11 @@ static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
|
||||
// Internal Events for RTOS application
|
||||
#ifndef RTOSPARA
|
||||
#define RTOSPARA
|
||||
#define SBP_STATE_CHANGE_EVT 0x0001
|
||||
#define SBP_CHAR_CHANGE_EVT 0x0002
|
||||
#define SBP_PERIODIC_EVT 0x0004
|
||||
#define SBP_CONN_EVT_END_EVT 0x0008
|
||||
#define SBP_KEY_CHANGE_EVT 0x0010
|
||||
#define SBP_STATE_CHANGE_EVT 0x0001
|
||||
#define SBP_CHAR_CHANGE_EVT 0x0002
|
||||
#define SBP_PERIODIC_EVT 0x0004
|
||||
#define SBP_CONN_EVT_END_EVT 0x0008
|
||||
#define SBP_KEY_CHANGE_EVT 0x0010
|
||||
#endif
|
||||
|
||||
static Clock_Struct periodicClock;
|
||||
@@ -500,60 +491,6 @@ static uint8 channel_table[CHANNEL_COUNT] = {0};
|
||||
*/
|
||||
static int8 channel_pointer = -1;
|
||||
static uint8_t not_buf[BLE_DAT_BUFF_SIZE] = {0};
|
||||
/*==============================
|
||||
==== headstage instruction ====
|
||||
=============================*/
|
||||
struct HEADSTAGE_INSTRUCTION {
|
||||
/** chip ID */
|
||||
uint8_t chip_id;
|
||||
|
||||
/** RATE. ADC clock/sampling rate value*/
|
||||
uint32_t adc_clock_rate;
|
||||
|
||||
/** CS **/
|
||||
uint8_t chip_select;
|
||||
|
||||
// ADC
|
||||
|
||||
/** SS **/
|
||||
uint8_t single_short;
|
||||
|
||||
/** MUX **/
|
||||
uint8_t multi_config;
|
||||
|
||||
/** PGA **/
|
||||
uint8_t gain_amp_config;
|
||||
|
||||
/** M **/
|
||||
uint8_t operating_mode;
|
||||
|
||||
/** DR **/
|
||||
uint8_t adc_data_rate;
|
||||
|
||||
uint8_t temp_sensor;
|
||||
|
||||
uint8_t pullup_R_enable;
|
||||
|
||||
uint8_t no_operation;
|
||||
|
||||
uint8_t reserved;
|
||||
|
||||
// LED
|
||||
|
||||
uint8_t global;
|
||||
|
||||
uint8_t blue;
|
||||
|
||||
uint8_t green;
|
||||
|
||||
uint8_t red;
|
||||
|
||||
// elite function
|
||||
uint8_t eliteFxn;
|
||||
|
||||
uint8_t CycleNumber;
|
||||
|
||||
} INSTRUCTION = {0};
|
||||
|
||||
/*=====================================
|
||||
==== headstage function prototype ====
|
||||
@@ -599,8 +536,9 @@ static void ADCGainControl(uint8_t ADCLevel);
|
||||
static void ADCChannelSelect(uint8_t ADCChannel);
|
||||
static int32_t DecodeADCVolt(uint16_t ADC_measure);
|
||||
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure);
|
||||
static void Impedance_Calculate(uint16_t Voltage, int32_t Current);
|
||||
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw);
|
||||
static void ADC_overflow(uint8_t gain, uint8_t *rawdata);
|
||||
static void ADC_overflow(uint8_t gain, uint8_t *rawdata);
|
||||
|
||||
// DAC function
|
||||
static uint16_t Usercode_Correction_to_DAC(uint16_t usercode);
|
||||
@@ -640,47 +578,55 @@ static void set_update_instruction_callback(update_instruction_callback_type cal
|
||||
#define VIS_SHIFT_100R 0b10000000
|
||||
|
||||
// real instruction
|
||||
#define IVCurve 0b00010000
|
||||
#define CyclicVoltammetry 0b00100000
|
||||
#define fxnGen 0b00110000
|
||||
#define ZTCurve 0b01000000
|
||||
#define VTCurve 0b01010000
|
||||
#define ITCurve 0b01100000
|
||||
#define SetSampleRate 0b01110000
|
||||
#define SetADCGain 0b10000000
|
||||
#define DifferentialPulseVoltammetry 0b10100000
|
||||
#define SquareWaveVoltammetry 0b10110000
|
||||
#define PotentialState 0b11000000
|
||||
#define IV_CURVE 0b00010000
|
||||
#define CYCLIC_VOLTAMMETRY 0b00100000
|
||||
#define VOLT_OUTPUT 0b00110000
|
||||
#define ZT_CURVE 0b01000000
|
||||
#define VT_CURVE 0b01010000
|
||||
#define IT_CURVE 0b01100000
|
||||
#define SET_SAMPLE_RATE 0b01110000
|
||||
#define SET_ADC_GAIN 0b10000000
|
||||
#define DIFFERENTIAL_PULSE_VOLTAMMETRY 0b10100000
|
||||
#define SQUARE_WAVE_VOLTAMMETRY 0b10110000
|
||||
#define POTENTIAL_STATE 0b11000000
|
||||
#define CONSTANT_CURRENT 0b11010000
|
||||
#define SET_RESISTER_LEVEL 0b11100000
|
||||
|
||||
// CIS instruction
|
||||
|
||||
// test instruction
|
||||
|
||||
#define ADCTEST 0b10010000
|
||||
#define ADC_TEST 0b10010000
|
||||
|
||||
// DAC and ADC function
|
||||
static void DAC_outputV(uint16_t voltLV);
|
||||
static uint16_t DAC_outputV(uint16_t voltLV);
|
||||
static int32_t DAC_to_realV(uint16_t DACcode);
|
||||
|
||||
// input parameter
|
||||
static uint16_t VoltOrigin = DACzero;
|
||||
static uint16_t VoltFinal = DACposMax;
|
||||
static uint16_t Step = 0x009E; // 10 => 0xA0 ~= 30.5 mv
|
||||
/* DAC reset parameter */
|
||||
#define DAC_ZERO 0x85B2
|
||||
#define DAC_POS_MAX 0x0000
|
||||
#define DAC_NEG_MAX 0xFFFF
|
||||
static uint16_t DACUserCode = 0x0000;
|
||||
|
||||
static uint16_t SampleRateTable[6] = {1, 10, 100, 500, 1000, 10000}; // 1 =>100 Hz, 10000=>0.01 Hz
|
||||
static uint16_t SampleRate = 1;
|
||||
static uint32_t SampleRateTable[6] = {10, 100, 1000, 5000, 10000, 100000}; // 1 =>100 Hz, 10000=>0.01 Hz
|
||||
static uint16_t SampleRate_counter = 1;
|
||||
|
||||
// record value for IV curve to calculate average current
|
||||
static int16_t avg_number = 1;
|
||||
static int32_t ADCRealCurrent = 0;
|
||||
static int32_t ADCRealCurrent_avg = 0;
|
||||
static int16_t avg_number = 0;
|
||||
static long long ADCRealCurrent_long = 0;
|
||||
|
||||
#define GAIN_200K 0x00
|
||||
#define GAIN_10K 0x01
|
||||
#define GAIN_200R 0x02
|
||||
#define GAIN_AUTO 0x03
|
||||
static uint8_t ADCGainLevel = GAIN_200K;
|
||||
// Step time macro
|
||||
#define STEPTIME_HALF_SEC 5000
|
||||
#define STEPTIME_ONE_SEC 10000
|
||||
#define STEPTIME_TWO_SEC 20000
|
||||
|
||||
// Constant Current Mode function
|
||||
static uint8_t CCModeReset = 1;
|
||||
static int32_t CCModeReadCurrent();
|
||||
static int32_t CCModeVoltOut();
|
||||
static void SetCCModeGain();
|
||||
static void CCCurrent2IUC();
|
||||
static int32_t IUC2RealnA();
|
||||
static int32_t IUC2RealpA();
|
||||
|
||||
// for DPVCurve SWVCurve
|
||||
static uint16_t Amplitude;
|
||||
@@ -689,28 +635,27 @@ static uint16_t PulseWidth_16;
|
||||
static uint8_t PulsePeriod;
|
||||
static uint16_t PulsePeriod_16;
|
||||
|
||||
static uint8_t StepTime = 20; // 0x30 = 2'd48 ~= 2 second, 24 = 0x18 = 1 sec
|
||||
static uint16_t StepTime_16 = 0;
|
||||
static uint8_t StepTimeCounter = 1;
|
||||
|
||||
// real instruction fxn
|
||||
static uint16_t VoltScan(); // used in I-V and cyclic
|
||||
static void Notify_IV(uint16_t Voltage); // send notify voltage after VoltScan()
|
||||
static void DACCode2Real2Notify(uint16_t DACcode); // send notify voltage after VoltScan()
|
||||
|
||||
static void fxn_Gen();
|
||||
static void ZT_plot(uint16_t outV, uint16_t inV);
|
||||
static void VT_Plot();
|
||||
//static void VOLT_OUTPUT();
|
||||
static void ZT_Plot();
|
||||
static void VT_Plot();
|
||||
static int32_t IT_Plot();
|
||||
|
||||
// the following fxn do the same thing
|
||||
// IVCurve_T is called if Vorigin > Vfinal, vice versa
|
||||
static uint16_t OldDAC2UserCode(uint16_t OldDAC);
|
||||
static uint16_t StepCode2DACcode(uint16_t StepCode);
|
||||
static uint8_t OldStep2NewStep(uint8_t OldStep);
|
||||
static uint8_t OldStep2NewStepTime(uint8_t StepTime);
|
||||
static uint16_t OldStep2NewStepTime(uint8_t StepTime);
|
||||
static uint8_t IVdone = 0;
|
||||
|
||||
static uint16_t IVCurve_T();
|
||||
static uint16_t IVCurve_T2();
|
||||
static uint16_t OneWayVoltScan();
|
||||
static void ramp_test();
|
||||
static uint16_t DPVCurve();
|
||||
static uint16_t CVCurve();
|
||||
@@ -725,6 +670,29 @@ static void SendNotify();
|
||||
static bool If10Von = false;
|
||||
static void TurnOn10V();
|
||||
|
||||
#include "EliteInstruction.h"
|
||||
#include "EliteADC.h"
|
||||
#include "EliteDAC.h"
|
||||
#include "EliteSPI.h"
|
||||
#include "Elite_PIN.h"
|
||||
|
||||
#ifdef ELITE_VERSION_1_4
|
||||
#include "EliteI2C.h"
|
||||
#endif
|
||||
|
||||
#include "EliteDeviceCorrection.h"
|
||||
#include "EliteNotify.h"
|
||||
#include "EliteReset.h"
|
||||
#include "EliteLED.h"
|
||||
#include "EliteKeyDetect.h"
|
||||
#include "EliteCCMode.h"
|
||||
#include "EliteIVCurve.h"
|
||||
#include "EliteCVCurve.h"
|
||||
#include "EliteITCurve.h"
|
||||
#include "EliteVTCurve.h"
|
||||
#include "EliteZTCurve.h"
|
||||
#include "impedance_meter.h"
|
||||
|
||||
// update instruction for Z meter
|
||||
static void update_ZM_instruction(uint8 *ins) {
|
||||
uint8_t ins_type = ins[0] & 0b11110000;
|
||||
@@ -734,8 +702,6 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
uint8_t oper = ins[1] & 0xF0; // this is don't care in RIS
|
||||
uint8_t data_length = ins[1] & 0x0F;
|
||||
|
||||
DACreset = true;
|
||||
|
||||
if (!If10Von) {
|
||||
// TurnOn10V();
|
||||
}
|
||||
@@ -744,52 +710,53 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
/*** These are real instruction ***/
|
||||
case INS_TYPE_RIS: {
|
||||
switch (ins[2]) {
|
||||
case IVCurve: {
|
||||
case IV_CURVE: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = IVCurve;
|
||||
DACreset = true;
|
||||
INSTRUCTION.eliteFxn = IV_CURVE;
|
||||
DACReset = true;
|
||||
INSTRUCTION.SampleRate = 10;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
VoltOrigin = Usercode_Correction_to_DAC(VoltOrigin);
|
||||
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
// INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
|
||||
}
|
||||
if (ins[5] | ins[6]) {
|
||||
VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
VoltFinal = Usercode_Correction_to_DAC(VoltFinal);
|
||||
INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
// INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
|
||||
}
|
||||
|
||||
if (ins[7] | ins[8]) {
|
||||
Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
Step = Usercode_Correction_to_DAC(Step);
|
||||
INSTRUCTION.Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
INSTRUCTION.Step = StepCode2DACcode(INSTRUCTION.Step);
|
||||
}
|
||||
if (ins[9]) {
|
||||
StepTime = ins[9];
|
||||
StepTime = OldStep2NewStepTime(StepTime);
|
||||
INSTRUCTION.StepTime = ins[9];
|
||||
INSTRUCTION.StepTime = OldStep2NewStepTime(INSTRUCTION.StepTime);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DifferentialPulseVoltammetry: {
|
||||
case DIFFERENTIAL_PULSE_VOLTAMMETRY: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = DifferentialPulseVoltammetry;
|
||||
DACreset = true;
|
||||
INSTRUCTION.eliteFxn = DIFFERENTIAL_PULSE_VOLTAMMETRY;
|
||||
DACReset = true;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
VoltOrigin = Usercode_Correction_to_DAC(VoltOrigin);
|
||||
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
|
||||
}
|
||||
if (ins[5] | ins[6]) {
|
||||
VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
VoltFinal = Usercode_Correction_to_DAC(VoltFinal);
|
||||
INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
|
||||
}
|
||||
|
||||
if (ins[7] | ins[8]) {
|
||||
Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
Step = Usercode_Correction_to_DAC(Step);
|
||||
INSTRUCTION.Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
INSTRUCTION.Step = StepCode2DACcode(INSTRUCTION.Step);
|
||||
}
|
||||
if (ins[9]) {
|
||||
StepTime = ins[9];
|
||||
StepTime = OldStep2NewStepTime(StepTime);
|
||||
INSTRUCTION.StepTime = ins[9];
|
||||
INSTRUCTION.StepTime = OldStep2NewStepTime(INSTRUCTION.StepTime);
|
||||
}
|
||||
if (ins[10] | ins[11]) {
|
||||
Amplitude = ((uint16_t)(ins[10]) << 8) | (uint16_t)(ins[11]);
|
||||
@@ -804,26 +771,26 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
case SquareWaveVoltammetry: {
|
||||
case SQUARE_WAVE_VOLTAMMETRY: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = SquareWaveVoltammetry;
|
||||
DACreset = true;
|
||||
INSTRUCTION.eliteFxn = SQUARE_WAVE_VOLTAMMETRY;
|
||||
DACReset = true;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
VoltOrigin = Usercode_Correction_to_DAC(VoltOrigin);
|
||||
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
|
||||
}
|
||||
if (ins[5] | ins[6]) {
|
||||
VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
VoltFinal = Usercode_Correction_to_DAC(VoltFinal);
|
||||
INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
|
||||
}
|
||||
if (ins[7] | ins[8]) {
|
||||
Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
Step = Usercode_Correction_to_DAC(Step);
|
||||
INSTRUCTION.Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
INSTRUCTION.Step = StepCode2DACcode(INSTRUCTION.Step);
|
||||
}
|
||||
if (ins[9]) {
|
||||
StepTime = ins[9];
|
||||
StepTime = OldStep2NewStepTime(StepTime);
|
||||
INSTRUCTION.StepTime = ins[9];
|
||||
INSTRUCTION.StepTime = OldStep2NewStepTime(INSTRUCTION.StepTime);
|
||||
}
|
||||
if (ins[10] | ins[11]) {
|
||||
Amplitude = ((uint16_t)(ins[10]) << 8) | (uint16_t)(ins[11]);
|
||||
@@ -835,27 +802,27 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
case CyclicVoltammetry: {
|
||||
case CYCLIC_VOLTAMMETRY: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = CyclicVoltammetry;
|
||||
DACreset = true;
|
||||
INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY;
|
||||
DACReset = true;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
VoltOrigin = Usercode_Correction_to_DAC(VoltOrigin);
|
||||
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
|
||||
}
|
||||
if (ins[5] | ins[6]) {
|
||||
VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
VoltFinal = Usercode_Correction_to_DAC(VoltFinal);
|
||||
INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
|
||||
}
|
||||
|
||||
if (ins[7] | ins[8]) {
|
||||
Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
Step = Usercode_Correction_to_DAC(Step);
|
||||
INSTRUCTION.Step = ((uint16_t)(ins[7]) << 8) | (uint16_t)(ins[8]);
|
||||
INSTRUCTION.Step = StepCode2DACcode(INSTRUCTION.Step);
|
||||
}
|
||||
if (ins[9]) {
|
||||
StepTime = ins[9];
|
||||
StepTime = OldStep2NewStepTime(StepTime);
|
||||
INSTRUCTION.StepTime = ins[9];
|
||||
INSTRUCTION.StepTime = OldStep2NewStepTime(INSTRUCTION.StepTime);
|
||||
}
|
||||
if (ins[10]) {
|
||||
INSTRUCTION.CycleNumber = ins[10];
|
||||
@@ -864,72 +831,75 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
case fxnGen: {
|
||||
INSTRUCTION.eliteFxn = fxnGen;
|
||||
uint16_t volt = 0;
|
||||
int32_t RealV = 0;
|
||||
volt = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
// DAC_outputV(DACOUT, volt); //delete 'command' parameter
|
||||
volt = Usercode_Correction_to_DAC(volt);
|
||||
DAC_outputV(volt);
|
||||
// RealV = DAC_to_realV(volt);
|
||||
|
||||
case VOLT_OUTPUT: {
|
||||
INSTRUCTION.eliteFxn = VOLT_OUTPUT;
|
||||
INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
|
||||
// DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
DAC_outputV(INSTRUCTION.VoltConstant);
|
||||
break;
|
||||
}
|
||||
|
||||
// impedance test
|
||||
case ZTCurve: {
|
||||
case ZT_CURVE: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = ZTCurve;
|
||||
INSTRUCTION.eliteFxn = ZT_CURVE;
|
||||
// INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
|
||||
break;
|
||||
}
|
||||
|
||||
case VTCurve: {
|
||||
case VT_CURVE: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = VTCurve;
|
||||
StepTime = 0x01;
|
||||
|
||||
INSTRUCTION.eliteFxn = VT_CURVE;
|
||||
// SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
// VT_Plot(); // enable 10v = 0
|
||||
break;
|
||||
}
|
||||
|
||||
case ITCurve: {
|
||||
case IT_CURVE: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = ITCurve;
|
||||
StepTime = 0x01;
|
||||
// IT_Plot(); // enable 10v = 1
|
||||
|
||||
|
||||
INSTRUCTION.eliteFxn = IT_CURVE;
|
||||
// IT_Plot(); // enable 10v = 1
|
||||
break;
|
||||
}
|
||||
case SetSampleRate: {
|
||||
uint8_t index = 0;
|
||||
index = ins[3];
|
||||
SampleRate = SampleRateTable[index];
|
||||
case SET_SAMPLE_RATE: {
|
||||
INSTRUCTION.SampleRateIndex = ins[3];
|
||||
INSTRUCTION.SampleRate = SampleRateTable[INSTRUCTION.SampleRateIndex];
|
||||
SampleRate_counter = 1;
|
||||
break;
|
||||
}
|
||||
case PotentialState: {
|
||||
INSTRUCTION.eliteFxn = PotentialState;
|
||||
case POTENTIAL_STATE: {
|
||||
INSTRUCTION.eliteFxn = POTENTIAL_STATE;
|
||||
|
||||
// test
|
||||
not_buf[0] = ins[3];
|
||||
not_buf[1] = ins[4];
|
||||
not_buf[2] = ins[5];
|
||||
not_buf[3] = ins[6];
|
||||
// SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
|
||||
// SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case SetADCGain: {
|
||||
ADCGainLevel = ins[3];
|
||||
case CONSTANT_CURRENT:{
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
INSTRUCTION.CurrentLV = ins[3];
|
||||
INSTRUCTION.ConstantCurrent = ( (uint32_t) (ins[4])<<24 | (uint32_t) (ins[5])<<16 | (uint32_t) (ins[6])<<8 | (uint32_t) (ins[7]) );
|
||||
// GetInstructionParameter(ins+2);
|
||||
// CCCurrent2IUC();
|
||||
break;
|
||||
}
|
||||
|
||||
case ADCTEST: {
|
||||
INSTRUCTION.eliteFxn = ADCTEST;
|
||||
case SET_ADC_GAIN: {
|
||||
INSTRUCTION.ADCGainLevel = ins[3];
|
||||
break;
|
||||
}
|
||||
|
||||
case SET_RESISTER_LEVEL:{
|
||||
INSTRUCTION.ResisterMeter = ins[3];
|
||||
break;
|
||||
}
|
||||
|
||||
case ADC_TEST: {
|
||||
INSTRUCTION.eliteFxn = ADC_TEST;
|
||||
int32_t ADCRealValue = 0;
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
|
||||
@@ -1166,12 +1136,12 @@ static void headstage_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26X
|
||||
/*=======================================
|
||||
==== headstage specific declaration ====
|
||||
======================================*/
|
||||
#include "EliteDeviceCorrection.h"
|
||||
#include "EliteNotify.h"
|
||||
#include "impedance_meter.h"
|
||||
|
||||
/*========================
|
||||
==== gap information ====
|
||||
|
||||
|
||||
|
||||
p information ====
|
||||
=======================*/
|
||||
|
||||
#ifndef DEVICE_NAME
|
||||
|
||||
+129
-922
File diff suppressed because it is too large
Load Diff
+20
-20
@@ -102,6 +102,7 @@
|
||||
|
||||
#include "simple_peripheral.h"
|
||||
|
||||
#include "EliteGPTimer.h"
|
||||
#include "headstage.h"
|
||||
|
||||
#if defined(USE_FPGA) || defined(DEBUG_SW_TRACE)
|
||||
@@ -527,6 +528,8 @@ static void SimpleBLEPeripheral_init(void) {
|
||||
HCI_LE_ReadMaxDataLenCmd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_taskFxn
|
||||
*
|
||||
@@ -540,20 +543,23 @@ static void SimpleBLEPeripheral_init(void) {
|
||||
// static void detectKey_clockHandler(UArg arg);
|
||||
|
||||
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
|
||||
#define CLOCK_ONE_SECOND 10000
|
||||
// Initialize application
|
||||
SimpleBLEPeripheral_init();
|
||||
headstage_init_device_info();
|
||||
// headstage_gptimer_init();
|
||||
|
||||
ZM_init();
|
||||
Elite_SPI_init();
|
||||
CURRENT_USER_CODE *CurrentUserCode = InitCurrentUserCode();
|
||||
|
||||
uint8_t key = 0;
|
||||
uint8_t counter6994 = 0;
|
||||
uint16_t counter6994 = 0;
|
||||
bool EliteOn = 0;
|
||||
|
||||
Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler, SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT); // create a clock clockduration = 42(~=0.01 sec)
|
||||
Util_startClock(&periodicClock); // start the clock, timeup => call SimpleBLEPeripheral_clockHandler => wake up the device
|
||||
// init DAC, set output ~= 0 V
|
||||
DAC_outputV(Usercode_Correction_to_DAC(24999));
|
||||
elite_gptimer_start();
|
||||
|
||||
// Application main loops
|
||||
for (;;) {
|
||||
@@ -602,16 +608,16 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
ICall_free(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(events & SBP_PERIODIC_EVT){
|
||||
events &= ~SBP_PERIODIC_EVT;
|
||||
if (!PeriodicEvent) { // if there is no periodic event
|
||||
Util_startClock(&periodicClock); // manually restart the clock
|
||||
key = PIN_getInputValue(switch_on);
|
||||
if (EliteOn) {
|
||||
if (counter6994 < 175) { // counter6994 enable a IC after 35 counts
|
||||
if (counter6994 < CLOCK_ONE_SECOND/2) { // counter6994 enable a IC after 35 counts
|
||||
counter6994++;
|
||||
} else if (counter6994 == 175) {
|
||||
} else if (counter6994 == CLOCK_ONE_SECOND/2) {
|
||||
PIN_setOutputValue(pin_handle, shutdown_6994, 1); // OFF = 1 => turn off 6994
|
||||
|
||||
// #ifdef ELITE_VERSION_1_4
|
||||
// SPI_close(spiHandle0);
|
||||
// I2Cinit();
|
||||
@@ -621,26 +627,20 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
counter6994++;
|
||||
}
|
||||
EliteKeyPress(key);
|
||||
|
||||
} else {
|
||||
EliteOn = TurnOnElite(key);
|
||||
}
|
||||
// if(DAC_reset) DAC_outputV(0x0000); //set DAC to 0v when no periodic event
|
||||
} else { // if there is periodic event
|
||||
Util_startClock(&periodicClock); // manually restart the clock
|
||||
SimpleBLEPeripheral_performPeriodicTask();
|
||||
}
|
||||
// if there is periodic event
|
||||
else {
|
||||
// Perform periodic application task
|
||||
SimpleBLEPeripheral_performPeriodicTask(CurrentUserCode);
|
||||
|
||||
key = PIN_getInputValue(switch_on);
|
||||
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
|
||||
}
|
||||
}
|
||||
// if(events & SBP_PERIODIC_EVT){
|
||||
// Util_startClock(&periodicClock);
|
||||
// events &= ~SBP_PERIODIC_EVT;
|
||||
|
||||
// // Perform periodic application task
|
||||
// SimpleBLEPeripheral_performPeriodicTask();
|
||||
// }
|
||||
// if (events & SBP_PERIODIC_EVT)
|
||||
// {
|
||||
// events &= ~SBP_PERIODIC_EVT;
|
||||
|
||||
Reference in New Issue
Block a user