diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/AD5940.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/AD5940.h index 1a2b076..3ac39b6 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/AD5940.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/AD5940.h @@ -2,10 +2,6 @@ #ifndef AD5940 #define AD5940 -bool cali_flag = false; - - - static void setEIS_EIS (void) { AD5940_SPIWriteReg(LPDACCON0, 0x00000001); // DC on // LPDAC enabled @@ -27,19 +23,53 @@ static void setEIS_EIS (void) HSTIAGainCtrl(instru.gain_lv_hstia); } - int32_t LPVolt, UserDCbias = 0; - if (!cali_flag) { - UserDCbias = Cali_LPDAC(instru.dcbias); - LPVolt = (UserDCbias - 25000) * 4 * 4000; - DAC_outputV(LPVolt); - SetWGAmp(instru.acamp); + int32_t LPVolt = 0; + LPVolt = Cali_LPDAC(instru.dcbias); + LPVolt = (LPVolt - 25000) * 4 * 4000; + DAC_outputV(LPVolt); + SetWGAmp(instru.acamp); + + + AD5940_SPIWriteReg(AFECON, 0x0031CFC0); + + //HIGH POWER MODE + AD5940_SPIWriteReg(PMBW, 0x0000000D); //switch to active high power mode + AD5940_SPIWriteReg(CLKSEL, 0x0000); + AD5940_SPIWriteReg(CLKCON0KEY, 0xA815); + AD5940_SPIWriteReg(CLKCON0, 0x0442); //16bit system clock divider //set divider = 2 + AD5940_SPIWriteReg(HSOSCCON, 0x00000000); //switch to 32MHz output + AD5940_SPIWriteReg(ADCFILTERCON, 0x00000311); + AD5940_SPIWriteReg(HSDACCON, 0x0000000E); //DAC gain = 2, > 80 kHz + AD5940_SPIWriteReg(ADCBUFCON, 0x005F3D0F); //recommended + SetEISHIGHZ(0); +} + +static void setEIS_EIS_cali(void) +{ + AD5940_SPIWriteReg(LPDACCON0, 0x00000001); // DC on // LPDAC enabled + AD5940_SPIWriteReg(LPDACSW0, 0b111111); // operation // 0b101011 + + AD5940_SPIWriteReg(HSRTIACON, 0x00000000); //200R | 1pF + AD5940_SPIWriteReg(HSTIACON, 0x00000001); // Vzero + + AD5940_SPIWriteReg(ADCCON, 0x00000101); + 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) { + instru.HSTIAAutoGainEnable = 0; + HSTIAGainCtrl(instru.gain_lv_hstia); } else { - LPVolt = (instru.dcbias - 25000) * 4 * 4000; - DAC_outputV(LPVolt); - cali_SetWGAmp(instru.acamp); - cali_flag = false; + instru.HSTIAAutoGainEnable = 1; + instru.gain_lv_hstia = HSRTIA_200R; + HSTIAGainCtrl(instru.gain_lv_hstia); } + int32_t LPVolt = 0; + LPVolt = ((int32_t)instru.dcbias - 25000) * 4 * 4000; + DAC_outputV(LPVolt); + cali_SetWGAmp(instru.acamp); + AD5940_SPIWriteReg(AFECON, 0x0031CFC0); //HIGH POWER MODE diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/eis_cali_table.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/eis_cali_table.h index 2c3c818..e4de476 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/eis_cali_table.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/eis_cali_table.h @@ -317,16 +317,16 @@ struct _CaliTable{ { .DeviceName = "BOARD_1", - .DAC_offset_a = 7, - .DAC_offset_b = 8380353, - .DAC_offset_c = 131800610362, + .DAC_offset_a = 4, + .DAC_offset_b = 6784398, + .DAC_offset_c = 55694071755, //only for EIS 1e10 - .HSDAC_AMP_a = -4, - .HSDAC_AMP_b = 9713058, - .HSDAC_AMP_c = 38850337, + .HSDAC_AMP_a = 9, + .HSDAC_AMP_b = 9677258, + .HSDAC_AMP_c = 992688, - .OffsetZero = 0x6504, + .OffsetZero = 22708, .Ft[0][0].Phase_coeff = 146743, .Ft[0][0].Phase_offset = -89745967, @@ -1200,17 +1200,17 @@ struct _CaliTable{ /* Ft[4][4]; Lv[4][4] */ /* [Phase][HSTIA] */ -static int32_t Cali_LPDAC (int32_t value) { +static int32_t Cali_LPDAC (uint32_t value) { /* res = a*x + b */ - int32_t res; + int64_t res; if (value == 25000) { // if DC offset = 0V; force DC bias to OffsetZero - res = (int32_t)(CaliTable.OffsetZero); + res = CaliTable.OffsetZero; } else { - res = (int32_t)(((int64_t)CaliTable.DAC_offset_a * value * value + - (int64_t)CaliTable.DAC_offset_b * value + - (int64_t)CaliTable.DAC_offset_c) / 1e7); + res = (CaliTable.DAC_offset_a * value * value + + CaliTable.DAC_offset_b * value + + CaliTable.DAC_offset_c) / 1e7; } - return res; + return (int32_t)res; } static uint32_t Cali_HSAMP (uint16_t value) { diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h index 326299c..fb9d404 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h @@ -428,26 +428,24 @@ static void update_ZM_instruction(uint8 *ins) { break; } - case cali_HSDAC_amp: { // 0x49 + case cali_HSDAC_amp: { // 0x49 //DACAMP instru.gain_lv_hstia = HSRTIA_160K; instru.dcbias = 0x65C4; instru.acamp = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]); instru.fset = 0x00002EE0; - cali_flag = true; - setEIS_EIS(); + setEIS_EIS_cali(); DAC_outputF(instru.fset); led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE); break; } - case cali_DCbias: { // 0x79 + case cali_DCbias: { // 0x79 //DACoffset instru.gain_lv_hstia = HSRTIA_160K; instru.dcbias = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]); instru.acamp = 0x0000; instru.fset = 0x0000; - cali_flag = true; - setEIS_EIS(); + setEIS_EIS_cali(); freq_out(); led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE); @@ -489,6 +487,49 @@ static void update_ZM_instruction(uint8 *ins) { break; } + case 0xF0: { //cali_HSDAC_amp // 0xF0 //DACAMP + instru.gain_lv_hstia = HSRTIA_160K; + instru.dcbias = 0x65C4; + instru.acamp = (uint16_t)(ins[4]) << 8 | (uint16_t)(ins[5]); + instru.fset = 0x00002EE0; //12000 + setEIS_EIS_cali(); + DAC_outputF(instru.fset); + led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE); + break; + } + + case 0xF1: { //cali_DCbias // 0xF1 //DACoffset + instru.gain_lv_hstia = HSRTIA_160K; + instru.dcbias = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]); + instru.acamp = 0x0000; + instru.fset = 0x0000; + setEIS_EIS_cali(); + freq_out(); + led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE); + break; + } + + case 0xF2: { // 0xF2 //AMP + instru.gain_lv_hstia = HSRTIA_160K; + instru.dcbias = 0x65C4; + instru.acamp = (uint16_t)(ins[4]) << 8 | (uint16_t)(ins[5]); + instru.fset = 0x00002EE0; //12000 + setEIS_EIS(); + DAC_outputF(instru.fset); + led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE); + break; + } + + case 0xF3: { // 0xF3 //DACoffset + instru.gain_lv_hstia = HSRTIA_160K; + instru.dcbias = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]); + instru.acamp = 0x0000; + instru.fset = 0x0000; + setEIS_EIS(); + freq_out(); + led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE); + break; + } } break; }