Elite 1.4-re RT mode
This commit is contained in:
-142
@@ -8,148 +8,6 @@
|
||||
#define CURRENT_LV_ONE 1
|
||||
#define CURRENT_LV_ZERO 0
|
||||
|
||||
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;
|
||||
|
||||
/** transform an IUC to real current in pA **/
|
||||
// handle current lv 0~2
|
||||
int32_t (*Transform2RealpA)(struct _CURRENT_USER_CODE *self);
|
||||
|
||||
/** transform an IUC to real current in nA **/
|
||||
// handle current lv 3~4
|
||||
int32_t (*Transform2RealnA)(struct _CURRENT_USER_CODE *self);
|
||||
|
||||
/** larger than a given int32 ? **/
|
||||
uint8_t (*Compare)(struct _CURRENT_USER_CODE *self, uint8_t, int32_t);
|
||||
}CURRENT_USER_CODE;
|
||||
|
||||
/*********************************************************************
|
||||
* @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;
|
||||
|
||||
// Saturate if current > 500 uA
|
||||
if (self->lv > 2){
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
// 0-499 nA
|
||||
if (self->lv == 0){
|
||||
IUCReal = (int32_t) (self->value) * 10;
|
||||
}
|
||||
|
||||
// 500-999 nA
|
||||
else if (self->lv == 1){
|
||||
IUCReal = ((int32_t) (self->value) * 10);
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 uA
|
||||
else if (self->lv == 2){
|
||||
IUCReal = (int32_t) (self->value) * 10e3;
|
||||
}
|
||||
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 < 3){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 500-999 uA
|
||||
if (self->lv == 3){
|
||||
IUCReal = (int32_t) (self->value) * 10;
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 mA
|
||||
else if (self->lv == 4){
|
||||
IUCReal = (int32_t) (self->value) * 10e3;
|
||||
}
|
||||
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 CURRENT_USER_CODE *InitCurrentUserCode(){
|
||||
CURRENT_USER_CODE *CurrentUserCode = malloc(sizeof(CURRENT_USER_CODE));
|
||||
CurrentUserCode->lv = 0;
|
||||
CurrentUserCode->value = 0;
|
||||
CurrentUserCode->Transform2RealnA = &Transform2RealnA;
|
||||
CurrentUserCode->Transform2RealpA = &Transform2RealpA;
|
||||
CurrentUserCode->Compare = &CompareCurrent;
|
||||
return CurrentUserCode;
|
||||
}
|
||||
|
||||
static int32_t CCModeReadCurrent(CURRENT_USER_CODE *CurrentUserCode){
|
||||
int32_t Real_Current = 0;
|
||||
CCModeReset = 0; // This flag will control DAC working
|
||||
|
||||
+149
@@ -23,6 +23,145 @@
|
||||
#define CURRENT_RANGE_LOW 0x00
|
||||
#define CURRENT_RANGE_HIGH 0x01
|
||||
|
||||
/*********************************************************************
|
||||
* @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;
|
||||
|
||||
/** 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);
|
||||
|
||||
/** larger than a given int32 ? **/
|
||||
uint8_t (*Compare)(struct _CURRENT_USER_CODE, uint8_t, int32_t);
|
||||
}CURRENT_USER_CODE;
|
||||
|
||||
static CURRENT_USER_CODE CurrentUserCode;
|
||||
|
||||
/*********************************************************************
|
||||
* @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;
|
||||
|
||||
// Saturate if current > 500 uA
|
||||
if (self->lv > 2){
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
// 0-499 nA
|
||||
if (self->lv == 0){
|
||||
IUCReal = (int32_t) (self->value) * 10;
|
||||
}
|
||||
|
||||
// 500-999 nA
|
||||
else if (self->lv == 1){
|
||||
IUCReal = ((int32_t) (self->value) * 10);
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 uA
|
||||
else if (self->lv == 2){
|
||||
IUCReal = (int32_t) (self->value) * 10e3;
|
||||
}
|
||||
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 < 3){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 500-999 uA
|
||||
if (self->lv == 3){
|
||||
IUCReal = (int32_t) (self->value) * 10;
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 mA
|
||||
else if (self->lv == 4){
|
||||
IUCReal = (int32_t) (self->value) * 10e3;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*==============================
|
||||
==== headstage instruction ====
|
||||
=============================*/
|
||||
@@ -62,6 +201,16 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
|
||||
} INSTRUCTION = {0};
|
||||
|
||||
static void InitCurrentUserCode(){
|
||||
// CURRENT_USER_CODE *CurrentUserCode = malloc(sizeof(CURRENT_USER_CODE));
|
||||
CurrentUserCode.lv = 0;
|
||||
CurrentUserCode.value = 0;
|
||||
CurrentUserCode.Transform2RealnA = &Transform2RealnA;
|
||||
CurrentUserCode.Transform2RealpA = &Transform2RealpA;
|
||||
CurrentUserCode.Compare = &CompareCurrent;
|
||||
// return CurrentUserCode;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn InitEliteInstruction
|
||||
*
|
||||
|
||||
+4
-1
@@ -11,7 +11,10 @@ static void reset() {
|
||||
StepTimeCounter = 1;
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
|
||||
if (INSTRUCTION.eliteFxn == CONSTANT_CURRENT){
|
||||
INSTRUCTION.eliteFxn = 0;
|
||||
free
|
||||
};
|
||||
|
||||
LEDPowerON();
|
||||
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++) {
|
||||
|
||||
+1
-1
@@ -882,7 +882,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
case CONSTANT_CURRENT:{
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
CURRENT_USER_CODE *CurrentUserCode = InitCurrentUserCode();
|
||||
// CURRENT_USER_CODE *CurrentUserCode = InitCurrentUserCode();
|
||||
GetInstructionParameter(ins+2);
|
||||
break;
|
||||
}
|
||||
|
||||
+1
@@ -45,6 +45,7 @@ static void ZM_init() {
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
|
||||
InitEliteInstruction();
|
||||
InitCurrentUserCode();
|
||||
|
||||
// PIN_registerIntCb(pin_handle, switch_on_callback);
|
||||
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
|
||||
|
||||
Reference in New Issue
Block a user