[update] new hsrtia function

This commit is contained in:
ROY
2022-11-09 16:02:38 +08:00
parent c617910ea5
commit ee3b6c8f6f
6 changed files with 127 additions and 132 deletions
@@ -14,7 +14,7 @@ static void setEIS_EIS (void)
AD5940_SPIWriteReg(DFTCON, 0x00000091);
AD5940_SPIWriteReg(SWCON, 0x00026355); //D5 | P5 | N3 | T6 | T9 0b010 0110 0011 0101 0101
if (instru.gain_lv_hstia != HSRTIA_GAIN_AUTO) {
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
@@ -56,7 +56,7 @@ static void setEIS_EIS_cali(void)
AD5940_SPIWriteReg(DFTCON, 0x00000091);
AD5940_SPIWriteReg(SWCON, 0x00026355); //D5 | P5 | N3 | T6 | T9 0b010 0110 0011 0101 0101
if (instru.gain_lv_hstia != HSRTIA_GAIN_AUTO) {
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
@@ -109,39 +109,27 @@ static void HSTIAGainCtrl(uint8_t HSTIALevel) {
HSRTIACON[3:0] = RTIA */
uint32_t reg;
uint8_t data;
uint8_t g = HSTIALevel;
if (g >= HSRTIA_MAX)
return;
reg = 0x00001000;
if (HSTIALevel == HSRTIA_160K) {
// ADC gain level = 0, using 160k resister
if (g == HSRTIA_160K)
data = RTIA160k;
}
else if (HSTIALevel == HSRTIA_20K) {
// ADC gain level = 1, using 20k resister
else if (g == HSRTIA_20K)
data = RTIA20k;
}
else if (HSTIALevel == HSRTIA_5K) {
// ADC gain level = 2, using 5k resister
else if (g == HSRTIA_5K)
data = RTIA5k;
}
else if (HSTIALevel == HSRTIA_200R) {
// ADC gain level = 3, using 200R resister
else if (g == HSRTIA_200R)
data = RTIA200R;
}
else if (HSTIALevel == HSRTIA_GAIN_AUTO) {
data = RTIA200R;
}
reg = (reg) | ((uint32_t)(data));
AD5940_SPIWriteReg(HSRTIACON, reg);
if(HSTIALevel == 0 || HSTIALevel == 1 || HSTIALevel == 2 || HSTIALevel == 3){
last_gain_hstia = HSTIALevel;
}else{
last_gain_hstia = 3;
}
AD5940_SPIWriteReg(HSRTIACON, reg | (uint32_t)data);
last_gain_hstia = g;
record_flag = false;
return;
}
static void LPTIAGainCtrl(uint8_t LPTIALevel){
@@ -121,11 +121,14 @@ struct HEADSTAGE_INSTRUCTION {
#define DISCONNECT_RTIA 0x05
// EIS HSTIA Iin Gain Level
#define HSRTIA_160K 0x00
#define HSRTIA_20K 0x01
#define HSRTIA_5K 0x02
#define HSRTIA_200R 0x03
#define HSRTIA_GAIN_AUTO 0x04
enum hsrtia_gain_e {
HSRTIA_160K = 0,
HSRTIA_20K,
HSRTIA_5K,
HSRTIA_200R,
HSRTIA_MAX,
};
/** ADC Vin gain level **/
#define VIN_GAIN_1M 0x00
@@ -99,16 +99,4 @@ enum all_mode_e {
#define WORKING 0x04
#define POST_WORK 0x05
/* EIS define */
// cutoff frequency of the filter in AD5940
#define cutoff_auto 0x00
#define cutoff_50k 0x01
#define cutoff_100k 0x02
#define cutoff_250k 0x03
#define LOW_PW_MODE 0x00
#define HIGH_PW_MODE 0x01
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
#endif
@@ -232,20 +232,6 @@ static void decode_ris_ins(uint8 *ins)
case 0xFF: { // 0x3000FF DEV_MODE
switch (ins[3]) {
case 0x13: { //HIGH_Z
SetEISHIGHZ(ins[4]); //0:open highz, CE0 no output
break;
}
case 0x18: {
uint16_t b;
uint8_t z;
z = ins[4];
b = (uint16_t)ins[5] << 8 | (uint16_t)ins[6];
set_lpdac_ce_1100mv(z, b);
break;
}
case 0x01: {
// headstage_battery_volt();
@@ -261,66 +247,6 @@ static void decode_ris_ins(uint8 *ins)
break;
}
case CTL_WRT: { // ble write: 0x3000FF 20FFFFFFFFFFFF
uint16_t address = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
uint32_t data = (uint32_t)ins[6] << 24 | (uint32_t)ins[7] << 16 |
(uint32_t)ins[8] << 8 | (uint32_t)ins[9];
AD5940_SPIWriteReg(address, data);
initCISBuf();
cis_buf[0] = 6;
cis_buf[1] = (uint8_t)(address >> 8);
cis_buf[2] = (uint8_t)(address);
cis_buf[3] = (uint8_t)(data >> 24);
cis_buf[4] = (uint8_t)(data >> 16);
cis_buf[5] = (uint8_t)(data >> 8);
cis_buf[6] = (uint8_t)(data);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CTL_RD: { // ble write: 0x3000FF 21FFFF
uint16_t address = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
uint32_t rd;
rd = AD5940_SPIReadReg(address);
initCISBuf();
cis_buf[0] = 6;
cis_buf[1] = (uint8_t)(address >> 8);
cis_buf[2] = (uint8_t)(address);
cis_buf[3] = (uint8_t)(rd >> 24);
cis_buf[4] = (uint8_t)(rd >> 16);
cis_buf[5] = (uint8_t)(rd >> 8);
cis_buf[6] = (uint8_t)rd;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CTL_RD_ADC: { // ble write: 0x3000FF 7AFFFF
// select_REG_RRR(ADCDAT);
uint32_t rd;
rd = AD5940_SPIReadReg(ADCDAT);
initCISBuf();
cis_buf[0] = 6;
cis_buf[1] = (uint8_t)((ADCDAT & 0xFF00) >> 8);
cis_buf[2] = (uint8_t)(ADCDAT & 0x00FF);
cis_buf[3] = (uint8_t)(rd >> 24);
cis_buf[4] = (uint8_t)(rd >> 16);
cis_buf[5] = (uint8_t)(rd >> 8);
cis_buf[6] = (uint8_t)rd;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CTL_RESET: { //UI write: 11
AD5940_HWReset();
AD5940_Initialize();
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
break;
}
case 0x03: { // ble write: 0x3000FF 03
if (ins[4] == 1) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_RED);
@@ -340,6 +266,19 @@ static void decode_ris_ins(uint8 *ins)
break;
}
case 0x70: { // SET_GENERAL_HS_RTIA
instru.gain_lv_hstia = ins[4];
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
}
break;
}
// 0xF0 ~ 0xF3 are cali mode function
case 0xF0: { //AC Amplitude
instru.gain_lv_hstia = HSRTIA_160K;
@@ -395,14 +334,6 @@ static void decode_ris_ins(uint8 *ins)
break;
}
case 0xF4: { //debug function: fixed DC voltage
instru.Vinit = (int32_t)ins[4] << 8 | (int32_t)ins[5];
instru.Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
setEIS_CV();
DAC_outputV(instru.Vinit);
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
break;
}
case 0xF5: { //debug function: set AC dcbias & acamp & freq
uint8_t use_cali = ins[12];
instru.gain_lv_hstia = HSRTIA_160K;
@@ -421,6 +352,89 @@ static void decode_ris_ins(uint8 *ins)
}
break;
}
case CTL_RD_ADC: { // ble write: 0x3000FF 7AFFFF
// select_REG_RRR(ADCDAT);
uint32_t rd;
rd = AD5940_SPIReadReg(ADCDAT);
initCISBuf();
cis_buf[0] = 6;
cis_buf[1] = (uint8_t)((ADCDAT & 0xFF00) >> 8);
cis_buf[2] = (uint8_t)(ADCDAT & 0x00FF);
cis_buf[3] = (uint8_t)(rd >> 24);
cis_buf[4] = (uint8_t)(rd >> 16);
cis_buf[5] = (uint8_t)(rd >> 8);
cis_buf[6] = (uint8_t)rd;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CTL_WRT: { // ble write: 0x3000FF 20FFFFFFFFFFFF
uint16_t address = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
uint32_t data = (uint32_t)ins[6] << 24 | (uint32_t)ins[7] << 16 |
(uint32_t)ins[8] << 8 | (uint32_t)ins[9];
AD5940_SPIWriteReg(address, data);
initCISBuf();
cis_buf[0] = 6;
cis_buf[1] = (uint8_t)(address >> 8);
cis_buf[2] = (uint8_t)(address);
cis_buf[3] = (uint8_t)(data >> 24);
cis_buf[4] = (uint8_t)(data >> 16);
cis_buf[5] = (uint8_t)(data >> 8);
cis_buf[6] = (uint8_t)(data);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CTL_RD: { // ble write: 0x3000FF 21FFFF
uint16_t address = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
uint32_t rd;
rd = AD5940_SPIReadReg(address);
initCISBuf();
cis_buf[0] = 6;
cis_buf[1] = (uint8_t)(address >> 8);
cis_buf[2] = (uint8_t)(address);
cis_buf[3] = (uint8_t)(rd >> 24);
cis_buf[4] = (uint8_t)(rd >> 16);
cis_buf[5] = (uint8_t)(rd >> 8);
cis_buf[6] = (uint8_t)rd;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CTL_RESET: { //UI write: 11
AD5940_HWReset();
AD5940_Initialize();
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
break;
}
// case 0x13: { //HIGH_Z
// SetEISHIGHZ(ins[4]); //0:open highz, CE0 no output
// break;
// }
// case 0x18: {
// uint16_t b;
// uint8_t z;
// z = ins[4];
// b = (uint16_t)ins[5] << 8 | (uint16_t)ins[6];
// set_lpdac_ce_1100mv(z, b);
// break;
// }
// case 0xF4: { //debug function: fixed DC voltage
// instru.Vinit = (int32_t)ins[4] << 8 | (int32_t)ins[5];
// instru.Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
// setEIS_CV();
// DAC_outputV(instru.Vinit);
// led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
// break;
// }
}
break;
}
@@ -25,15 +25,17 @@ Current range Auto
[CC2650] att_write 360BD10261A801000004000A00
***/
#define INS_1 0x01
#define INS_2 0x02
#define INS_MODE 0xFF
#define DECODE_INS_1 0x01
#define DECODE_INS_2 0x02
#define DECODE_INS_MODE 0xFF
static void decode_eis_mode(uint8 *ins)
static void decode_eis_mode(uint8_t *instruction)
{
uint8_t *ins = instruction;
uint8_t ins_step = ins[3];
if (ins_step == INS_1) {
if (ins_step == DECODE_INS_1) {
instru.f1 = (uint32_t)ins[4] << 24 | (uint32_t)ins[5] << 16 | (uint32_t)ins[6] << 8 | (uint32_t)ins[7]; //FREQ_START //13333333
instru.f2 = (uint32_t)ins[8] << 24 | (uint32_t)ins[9] << 16 | (uint32_t)ins[10] << 8 | (uint32_t)ins[11]; //FREQ_STOP //7
//instru.sampleRate = 15;//CalcDelayTime(User2Freq(instru.f1), true); //ms //read
@@ -48,7 +50,7 @@ static void decode_eis_mode(uint8 *ins)
return;
}
if (ins_step == INS_2) {
if (ins_step == DECODE_INS_2) {
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5]; //25000
instru.acamp = (uint16_t)ins[6] << 8 | (uint16_t)ins[7]; //256
instru.avgnum = (uint8_t)ins[8]; //0
@@ -59,7 +61,7 @@ static void decode_eis_mode(uint8 *ins)
return;
}
if (ins_step == INS_MODE) {
if (ins_step == DECODE_INS_MODE) {
instru.eliteFxn = CURVE_EIS;
setEIS_EIS();
ModeLED(WORKING);