mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Wait for full ADC Burst
This commit is contained in:
@@ -23,11 +23,12 @@ void start_PWM_output(void);
|
||||
history<uint16_t, ADC_Filter_Smooth> ADC_Vin;
|
||||
history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
|
||||
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
|
||||
volatile uint8_t ADCBurstCounter = 0;
|
||||
void adc_fifo_irq(void) {
|
||||
if (ADC_GetIntStatus(ADC_INT_FIFO_READY) == SET) {
|
||||
start_PWM_output(); // Restart the tip PWM
|
||||
// Read out all entries in the fifo
|
||||
while (ADC_Get_FIFO_Count()) {
|
||||
ADCBurstCounter++;
|
||||
volatile uint32_t reading = ADC_Read_FIFO();
|
||||
// As per manual, 26 bit reading; lowest 16 are the ADC
|
||||
uint16_t sample = reading & 0xFFFF;
|
||||
@@ -47,12 +48,18 @@ void adc_fifo_irq(void) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// unblock the PID controller thread
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
if (pidTaskNotification) {
|
||||
vTaskNotifyGiveFromISR(pidTaskNotification, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
|
||||
if (ADCBurstCounter >= 8) {
|
||||
ADCBurstCounter = 0;
|
||||
start_PWM_output();
|
||||
|
||||
// unblock the PID controller thread
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
if (pidTaskNotification) {
|
||||
vTaskNotifyGiveFromISR(pidTaskNotification, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,8 +76,6 @@ volatile bool lastPeriodWasFast = false;
|
||||
|
||||
void start_PWM_output(void) {
|
||||
|
||||
TIMER_Enable(TIMER_CH0);
|
||||
|
||||
if (PWMSafetyTimer) {
|
||||
PWMSafetyTimer--;
|
||||
if (lastPeriodWasFast != fastPWM) {
|
||||
@@ -92,11 +97,12 @@ void start_PWM_output(void) {
|
||||
} else {
|
||||
PWM_Channel_Disable(PWM_Channel);
|
||||
}
|
||||
TIMER_Enable(TIMER_CH0);
|
||||
}
|
||||
|
||||
// Timer 0 is used to co-ordinate the ADC and the output PWM
|
||||
void timer0_comp0_callback(void) {
|
||||
PWM_Channel_Disable(PWM_Channel);
|
||||
TIMER_Disable(TIMER_CH0);
|
||||
ADC_Start();
|
||||
}
|
||||
void timer0_comp1_callback(void) { PWM_Channel_Disable(PWM_Channel); } // Trigged at end of output cycle; turn off the tip PWM
|
||||
|
||||
Reference in New Issue
Block a user