decode ADC data
This commit is contained in:
+10
-2
@@ -927,6 +927,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
case 0 :{
|
||||
ADCin = 0xC1;
|
||||
ADC_write(ADCin);
|
||||
ADC_read(ADCin);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -936,6 +937,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
case 1 :{
|
||||
ADCin = 0xD1;
|
||||
ADC_write(ADCin);
|
||||
ADC_read(ADCin);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -945,6 +947,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
case 2 :{
|
||||
ADCin = 0xE1;
|
||||
ADC_write(ADCin);
|
||||
ADC_read(ADCin);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -967,12 +970,16 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default :{
|
||||
break;
|
||||
}
|
||||
}
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, NotifyVolt);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 4, spi_ADC_rxbuf);
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, 4, spi_ADC_rxbuf);
|
||||
|
||||
/*
|
||||
bool neg = 0;
|
||||
if(AIN < 0){
|
||||
AIN = (-1)*AIN;
|
||||
@@ -986,8 +993,9 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
if(neg){
|
||||
NotifyVolt[0] = NotifyVolt[0] | 0xF0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, 4, NotifyVolt);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
+23
-5
@@ -184,7 +184,12 @@ static void ADC_read(uint8_t ADCin){
|
||||
|
||||
static uint8_t DecodeADCCurrent_level1(){
|
||||
ADC_read(0xC1);
|
||||
return 1;
|
||||
|
||||
if (spi_ADC_rxbuf_overflow()){
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t DecodeADCCurrent_level2(){
|
||||
@@ -211,18 +216,31 @@ static int32_t DecodeADCCurrent(uint8_t ADCin){
|
||||
uint8_t stage = DecodeADCCurrent_level3();
|
||||
int32_t Iin = 0;
|
||||
|
||||
float LSBuV = getLSB(ADCin);
|
||||
float Vo;
|
||||
int16_t decode = (int16_t)(spi_ADC_rxbuf[0] << 8) | (uint16_t)(spi_ADC_rxbuf[1]);
|
||||
|
||||
switch(stage){
|
||||
case 1:
|
||||
Iin = DecodeADC(0xD1) / 10e6; // mA
|
||||
Vo = 101*1500000 - 100 * decode*LSBuV / 10e6;
|
||||
Vo = Vo * 1000;
|
||||
// Iin = DecodeADC(0xD1) / 10e6; // mA
|
||||
break;
|
||||
case 2:
|
||||
Iin = DecodeADC(0xE1) / (25*10e6); // mA
|
||||
Vo = 101*1500000 - 100 * decode*LSBuV / 10e6;
|
||||
Vo = Vo * 1000;
|
||||
// Iin = DecodeADC(0xE1) / (25*10e6); // mA
|
||||
break;
|
||||
case 3:
|
||||
Iin = DecodeADC(0xF1) / (625*10e6); // mA
|
||||
Vo = 101*1500000 - 100 * decode*LSBuV / 10e6;
|
||||
Vo = Vo * 1000;
|
||||
// Iin = DecodeADC(0xF1) / (625*10e6); // mA
|
||||
break;
|
||||
case 0;
|
||||
Iin = 0xFFFFFFFF;
|
||||
break;
|
||||
default:
|
||||
Iin = DecodeADC(0xD1) / 10e6; // mA
|
||||
// Iin = DecodeADC(0xD1) / 10e6; // mA
|
||||
break;
|
||||
}
|
||||
return Iin;
|
||||
|
||||
Reference in New Issue
Block a user