mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Prevent ADC rollover
This commit is contained in:
@@ -33,7 +33,6 @@ void read_adc_fifo(void) {
|
|||||||
if (pending_readings != 8) {
|
if (pending_readings != 8) {
|
||||||
MSG((char *)"Discarding out of sync adc %d\r\n", pending_readings);
|
MSG((char *)"Discarding out of sync adc %d\r\n", pending_readings);
|
||||||
} else {
|
} else {
|
||||||
MSG((char *)"FIFO Count %d\r\n", pending_readings);
|
|
||||||
while (pending_readings) {
|
while (pending_readings) {
|
||||||
pending_readings--;
|
pending_readings--;
|
||||||
uint32_t raw_reading = ADC_Read_FIFO();
|
uint32_t raw_reading = ADC_Read_FIFO();
|
||||||
@@ -45,11 +44,6 @@ void read_adc_fifo(void) {
|
|||||||
ADC_Temp.update(parsed.value << 2);
|
ADC_Temp.update(parsed.value << 2);
|
||||||
break;
|
break;
|
||||||
case TIP_TEMP_ADC_CHANNEL: {
|
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);
|
ADC_Tip.update(parsed.value << 2);
|
||||||
} break;
|
} break;
|
||||||
case VIN_ADC_CHANNEL:
|
case VIN_ADC_CHANNEL:
|
||||||
@@ -60,7 +54,6 @@ void read_adc_fifo(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ADC_FIFO_Clear();
|
|
||||||
// unblock the PID controller thread
|
// unblock the PID controller thread
|
||||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
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
|
// Timer 0 is used to co-ordinate the ADC and the output PWM
|
||||||
void timer0_comp1_callback(void) {
|
void timer0_comp1_callback(void) {
|
||||||
|
ADC_FIFO_Clear();
|
||||||
ADC_Start();
|
ADC_Start();
|
||||||
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_1);
|
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t posChan; /*!< Positive channel */
|
int8_t posChan; /*!< Positive channel */
|
||||||
int8_t negChan; /*!< Negative channel */
|
int8_t negChan; /*!< Negative channel */
|
||||||
uint16_t value; /*!< ADC value */
|
uint32_t value; /*!< ADC value */
|
||||||
// float volt; /*!< ADC voltage result */
|
// float volt; /*!< ADC voltage result */
|
||||||
} ADC_Result_Type;
|
} ADC_Result_Type;
|
||||||
|
|
||||||
|
|||||||
@@ -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)) {
|
} 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);
|
result[i].value = (unsigned int)((orgVal[i] & 0xffff) / coe);
|
||||||
}
|
}
|
||||||
|
// Saturate at 16 bits
|
||||||
|
if (result[i].value > 0xFFFF) {
|
||||||
|
result[i].value = 0xFFFF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < len; i++) {
|
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)) {
|
} 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);
|
result[i].value = (unsigned int)((orgVal[i] & 0xffff) / coe);
|
||||||
}
|
}
|
||||||
|
// Saturate at 16 bits
|
||||||
|
if (result[i].value > 0xFFFF) {
|
||||||
|
result[i].value = 0xFFFF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@
|
|||||||
#define ANIMATION_LOOP 1 // 0: off 1: on
|
#define ANIMATION_LOOP 1 // 0: off 1: on
|
||||||
#define ANIMATION_SPEED settingOffSpeed_t::MEDIUM
|
#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_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))
|
#define OP_AMP_GAIN_STAGE_PINECIL (1 + (OP_AMP_Rf_Pinecil / OP_AMP_Rin_Pinecil))
|
||||||
|
|||||||
Reference in New Issue
Block a user