diff --git a/source/Core/BSP/Pinecilv2/IRQ.cpp b/source/Core/BSP/Pinecilv2/IRQ.cpp index e57433c2..d9d32406 100644 --- a/source/Core/BSP/Pinecilv2/IRQ.cpp +++ b/source/Core/BSP/Pinecilv2/IRQ.cpp @@ -33,7 +33,6 @@ void read_adc_fifo(void) { if (pending_readings != 8) { MSG((char *)"Discarding out of sync adc %d\r\n", pending_readings); } else { - MSG((char *)"FIFO Count %d\r\n", pending_readings); while (pending_readings) { pending_readings--; uint32_t raw_reading = ADC_Read_FIFO(); @@ -45,11 +44,6 @@ void read_adc_fifo(void) { ADC_Temp.update(parsed.value << 2); break; case TIP_TEMP_ADC_CHANNEL: { - int32_t avg = ADC_Tip.average(); - int32_t delta = (int32_t)parsed.value - (avg >> 2); - if (delta > 4000) { - MSG((char *)"ADC Chan %d -> %d -> %d\r\n", pending_readings, parsed.value, delta); - } ADC_Tip.update(parsed.value << 2); } break; case VIN_ADC_CHANNEL: @@ -60,7 +54,6 @@ void read_adc_fifo(void) { } } } - ADC_FIFO_Clear(); // unblock the PID controller thread if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; @@ -88,6 +81,7 @@ void timer0_comp0_callback(void) { // Timer 0 is used to co-ordinate the ADC and the output PWM void timer0_comp1_callback(void) { + ADC_FIFO_Clear(); ADC_Start(); TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_1); } diff --git a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/inc/bl702_adc.h b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/inc/bl702_adc.h index a40286f5..b14eb472 100644 --- a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/inc/bl702_adc.h +++ b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/inc/bl702_adc.h @@ -271,7 +271,7 @@ typedef struct { typedef struct { int8_t posChan; /*!< Positive channel */ int8_t negChan; /*!< Negative channel */ - uint16_t value; /*!< ADC value */ + uint32_t value; /*!< ADC value */ // float volt; /*!< ADC voltage result */ } ADC_Result_Type; diff --git a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_adc.c b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_adc.c index ff60d644..304a3ca5 100644 --- a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_adc.c +++ b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_adc.c @@ -535,6 +535,10 @@ void ADC_Parse_Result(uint32_t *orgVal, uint32_t len, ADC_Result_Type *result) { } else if ((dataType == ADC_DATA_WIDTH_16_WITH_128_AVERAGE) || (dataType == ADC_DATA_WIDTH_16_WITH_256_AVERAGE)) { result[i].value = (unsigned int)((orgVal[i] & 0xffff) / coe); } + // Saturate at 16 bits + if (result[i].value > 0xFFFF) { + result[i].value = 0xFFFF; + } } } else { for (i = 0; i < len; i++) { @@ -555,6 +559,10 @@ void ADC_Parse_Result(uint32_t *orgVal, uint32_t len, ADC_Result_Type *result) { } else if ((dataType == ADC_DATA_WIDTH_16_WITH_128_AVERAGE) || (dataType == ADC_DATA_WIDTH_16_WITH_256_AVERAGE)) { result[i].value = (unsigned int)((orgVal[i] & 0xffff) / coe); } + // Saturate at 16 bits + if (result[i].value > 0xFFFF) { + result[i].value = 0xFFFF; + } } } } diff --git a/source/Core/BSP/Pinecilv2/configuration.h b/source/Core/BSP/Pinecilv2/configuration.h index 55f21146..e00839be 100644 --- a/source/Core/BSP/Pinecilv2/configuration.h +++ b/source/Core/BSP/Pinecilv2/configuration.h @@ -114,7 +114,7 @@ #define ANIMATION_LOOP 1 // 0: off 1: on #define ANIMATION_SPEED settingOffSpeed_t::MEDIUM -#define OP_AMP_Rf_Pinecil 680 * 1000 // 700 Kilo-ohms -> From schematic, R1 +#define OP_AMP_Rf_Pinecil 680 * 1000 // 680 Kilo-ohms -> From schematic, R1 #define OP_AMP_Rin_Pinecil 2370 // 2.37 Kilo-ohms -> From schematic, R2 #define OP_AMP_GAIN_STAGE_PINECIL (1 + (OP_AMP_Rf_Pinecil / OP_AMP_Rin_Pinecil))