From d11b9cdbe2bfe4dc1fffe496e2238f04e29cb0ff Mon Sep 17 00:00:00 2001 From: alan Date: Thu, 27 Jun 2019 10:46:23 +0800 Subject: [PATCH] read current --- .../cc26xx/app/headstage/headstage.h | 99 ++++++++++++++- .../cc26xx/app/headstage/impedance_meter.h | 118 ++++-------------- 2 files changed, 124 insertions(+), 93 deletions(-) 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 cecb6f85b..0fa157204 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 @@ -929,7 +929,6 @@ static void update_ZM_instruction(uint8 *ins) { PeriodicEvent = true; StepTime = 0x14; - // SimpleProfile_S // IT_Plot(); // enable 10v = 1 break; } @@ -954,6 +953,104 @@ static void update_ZM_instruction(uint8 *ins) { case ADCTEST:{ INSTRUCTION.eliteFxn = ADCTEST; PeriodicEvent = true; +// uint8_t ADCin = 0; +// int32_t AIN = 0; +// switch(ins[3]){ +// // AINp is AIN0; AINn is GND +// +// // V1 = AIN0 voltage +// // V1 / 10^6 = Iin (mA) +// case 0 :{ +// ADCin = 0xC1; +// ADC_write(ADCin); +// CPUdelay(16000); +// ADC_read(spi_ADC_rxbuf); +// +// float Vo; +// int16_t decode = (int16_t)(spi_ADC_rxbuf[0] << 8) | (uint16_t)(spi_ADC_rxbuf[1]); +// Vo = decode * (-176.91125719) + 1400190.030591624; +// AIN = (int32_t) (Vo / 1); +// +// NotifyCurrent[0] = (uint8_t) (AIN >> 24) & (0xFF); +// NotifyCurrent[1] = (uint8_t) (AIN >> 16) & (0xFF); +// NotifyCurrent[2] = (uint8_t) (AIN >> 8) & (0xFF); +// NotifyCurrent[3] = (uint8_t) (AIN) & (0xFF); +// +// SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); +// SendNotify(); +// +// // (GNDS - Vin)100 = Vo - GNDS +// // Vo = 101 GNDS - 100 Vin +// // Vo = +// +// break; +// } +// +// // AINp is AIN1; AINn is GND +// // AIN1 = 25 * AIN0 +// // Iin = AIN1 / (25*10^6) +// case 1 :{ +// ADCin = 0xD1; +// ADC_write(ADCin); +// CPUdelay(16000); +// ADC_read(spi_ADC_rxbuf); +// +// float Vo; +// int16_t decode = (int16_t)(spi_ADC_rxbuf[0] << 8) | (uint16_t)(spi_ADC_rxbuf[1]); +// Vo = decode * (-5855081.65485084) + 47350.844772584; +// AIN = (int32_t) (Vo / 1); +// +// NotifyCurrent[0] = (uint8_t) (AIN >> 24) & (0xFF); +// NotifyCurrent[1] = (uint8_t) (AIN >> 16) & (0xFF); +// NotifyCurrent[2] = (uint8_t) (AIN >> 8) & (0xFF); +// NotifyCurrent[3] = (uint8_t) (AIN) & (0xFF); +// +// SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); +// SendNotify(); +// +// break; +// } +// +// // AINp is AIN2; AINn is GND +// // AIN2 = 25 * AIN1 = 625 * AIN0 +// // Iin = AIN1 / (625*10^6) +// case 2 :{ +// ADCin = 0xE1; +// ADC_write(ADCin); +// CPUdelay(16000); +// ADC_read(spi_ADC_rxbuf); +// +// SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); +// break; +// } +// +// // AINp is AIN3; AINn is GND +// // AIN3 = (-0.1) * Vin (V) +// // Vo = GNDS - Vin/10 (to GNDA) +// case 3 :{ +// ADCin = 0xF1; +// ADC_write(ADCin); +// CPUdelay(16000); +// ADC_read(spi_ADC_rxbuf); +// AIN = DecodeADCVolt(ADCin); +// +// // return voltage (mV) +// NotifyVolt[0] = (uint8_t) (AIN >> 24) & (0xFF); +// NotifyVolt[1] = (uint8_t) (AIN >> 16) & (0xFF); +// NotifyVolt[2] = (uint8_t) (AIN >> 8) & (0xFF); +// NotifyVolt[3] = (uint8_t) (AIN) & (0xFF); +// +// CPUdelay(16000); +// SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf); +// +// break; +// } +// +// +// default :{ +// break; +// } +// } // CPUdelay(16000); // SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h index 5f8cafcaf..e87afc398 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h @@ -225,8 +225,12 @@ static uint8_t DecodeADCCurrent_level1(){ } // if (ADC_stage1full()){ if ((AIN1[0] >= 0xFE) || (AIN1[0] <= 02)){ + // blue + LED_color(0xE4, 0x00, 0x00, 0x0E); return 0; } else { + // purple + LED_color(0xE4, 0x0E, 0x00, 0x0E); return 1; } } @@ -242,6 +246,8 @@ static uint8_t DecodeADCCurrent_level2(){ if ((AIN2[0] >= 0x3B) || (AIN2[0] <= 01)){ return DecodeADCCurrent_level1(); } else { + // orange? + LED_color(0xE4, 0x0E, 0x0E, 0x00); for(int i=0 ; i= 0x3B) || (AIN3[0] <= 01)){ return DecodeADCCurrent_level2(); } else { + // white + LED_color(0xE4, 0x0E, 0x0E, 0x0E); for(int i=0 ; i> 8) & (0xFF); NotifyVolt[3] = (uint8_t) (AIN) & (0xFF); } + static void IT_Plot() { int32_t AIN; AIN = DecodeADCCurrent(0xC1); @@ -508,102 +517,26 @@ static void DAC_init(){ static void ADC_Test(){ uint8_t ADCin = 0; int32_t AIN = 0; - switch(ins[3]){ - // AINp is AIN0; AINn is GND - // V1 = AIN0 voltage - // V1 / 10^6 = Iin (mA) - case 0 :{ - ADCin = 0xC1; - ADC_write(ADCin); - CPUdelay(16000); - ADC_read(spi_ADC_rxbuf); + ADCin = 0xC1; + ADC_write(ADCin); + CPUdelay(160); + ADC_read(spi_ADC_rxbuf); - float Vo; - int16_t decode = (int16_t)(spi_ADC_rxbuf[0] << 8) | (uint16_t)(spi_ADC_rxbuf[1]); - Vo = decode * (-176.91125719) + 1400190.030591624; - AIN = (int32_t) (Vo / 1); + float Vo; + int16_t decode = (int16_t)(spi_ADC_rxbuf[0] << 8) | (uint16_t)(spi_ADC_rxbuf[1]); + Vo = decode * (-176.91125719) + 1400190.030591624; + AIN = (int32_t) (Vo / 1); - NotifyCurrent[0] = (uint8_t) (AIN >> 24) & (0xFF); - NotifyCurrent[1] = (uint8_t) (AIN >> 16) & (0xFF); - NotifyCurrent[2] = (uint8_t) (AIN >> 8) & (0xFF); - NotifyCurrent[3] = (uint8_t) (AIN) & (0xFF); + NotifyCurrent[0] = (uint8_t) (AIN >> 24) & (0xFF); + NotifyCurrent[1] = (uint8_t) (AIN >> 16) & (0xFF); + NotifyCurrent[2] = (uint8_t) (AIN >> 8) & (0xFF); + NotifyCurrent[3] = (uint8_t) (AIN) & (0xFF); - SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); - SendNotify(); - - // (GNDS - Vin)100 = Vo - GNDS - // Vo = 101 GNDS - 100 Vin - // Vo = - - break; - } - - // AINp is AIN1; AINn is GND - // AIN1 = 25 * AIN0 - // Iin = AIN1 / (25*10^6) - case 1 :{ - ADCin = 0xD1; - ADC_write(ADCin); - CPUdelay(16000); - ADC_read(spi_ADC_rxbuf); - - float Vo; - int16_t decode = (int16_t)(spi_ADC_rxbuf[0] << 8) | (uint16_t)(spi_ADC_rxbuf[1]); - Vo = decode * (-5855081.65485084) + 47350.844772584; - AIN = (int32_t) (Vo / 1); - - NotifyCurrent[0] = (uint8_t) (AIN >> 24) & (0xFF); - NotifyCurrent[1] = (uint8_t) (AIN >> 16) & (0xFF); - NotifyCurrent[2] = (uint8_t) (AIN >> 8) & (0xFF); - NotifyCurrent[3] = (uint8_t) (AIN) & (0xFF); - - SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); - SendNotify(); - - break; - } - - // AINp is AIN2; AINn is GND - // AIN2 = 25 * AIN1 = 625 * AIN0 - // Iin = AIN1 / (625*10^6) - case 2 :{ - ADCin = 0xE1; - ADC_write(ADCin); - CPUdelay(16000); - ADC_read(spi_ADC_rxbuf); - - SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); - break; - } - - // AINp is AIN3; AINn is GND - // AIN3 = (-0.1) * Vin (V) - // Vo = GNDS - Vin/10 (to GNDA) - case 3 :{ - ADCin = 0xF1; - ADC_write(ADCin); - CPUdelay(16000); - ADC_read(spi_ADC_rxbuf); - AIN = DecodeADCVolt(ADCin); - - // return voltage (mV) - NotifyVolt[0] = (uint8_t) (AIN >> 24) & (0xFF); - NotifyVolt[1] = (uint8_t) (AIN >> 16) & (0xFF); - NotifyVolt[2] = (uint8_t) (AIN >> 8) & (0xFF); - NotifyVolt[3] = (uint8_t) (AIN) & (0xFF); - - CPUdelay(16000); - SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf); - - break; - } - - - default :{ - break; - } - } + NotifyImpedance[1] = spi_ADC_rxbuf[0]; + NotifyImpedance[2] = spi_ADC_rxbuf[1]; + SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf); +// SendNotify(); } @@ -663,6 +596,7 @@ static void SimpleBLEPeripheral_performPeriodicTask() { } case ADCTEST: { ADC_Test(); + SendNotify(); break; }