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_Vin;
|
||||||
history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
|
history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
|
||||||
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
|
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
|
||||||
|
volatile uint8_t ADCBurstCounter = 0;
|
||||||
void adc_fifo_irq(void) {
|
void adc_fifo_irq(void) {
|
||||||
if (ADC_GetIntStatus(ADC_INT_FIFO_READY) == SET) {
|
if (ADC_GetIntStatus(ADC_INT_FIFO_READY) == SET) {
|
||||||
start_PWM_output(); // Restart the tip PWM
|
|
||||||
// Read out all entries in the fifo
|
// Read out all entries in the fifo
|
||||||
while (ADC_Get_FIFO_Count()) {
|
while (ADC_Get_FIFO_Count()) {
|
||||||
|
ADCBurstCounter++;
|
||||||
volatile uint32_t reading = ADC_Read_FIFO();
|
volatile uint32_t reading = ADC_Read_FIFO();
|
||||||
// As per manual, 26 bit reading; lowest 16 are the ADC
|
// As per manual, 26 bit reading; lowest 16 are the ADC
|
||||||
uint16_t sample = reading & 0xFFFF;
|
uint16_t sample = reading & 0xFFFF;
|
||||||
@@ -47,6 +48,11 @@ void adc_fifo_irq(void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ADCBurstCounter >= 8) {
|
||||||
|
ADCBurstCounter = 0;
|
||||||
|
start_PWM_output();
|
||||||
|
|
||||||
// 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;
|
||||||
@@ -56,6 +62,7 @@ void adc_fifo_irq(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Clear IRQ
|
// Clear IRQ
|
||||||
ADC_IntClr(ADC_INT_ALL);
|
ADC_IntClr(ADC_INT_ALL);
|
||||||
}
|
}
|
||||||
@@ -69,8 +76,6 @@ volatile bool lastPeriodWasFast = false;
|
|||||||
|
|
||||||
void start_PWM_output(void) {
|
void start_PWM_output(void) {
|
||||||
|
|
||||||
TIMER_Enable(TIMER_CH0);
|
|
||||||
|
|
||||||
if (PWMSafetyTimer) {
|
if (PWMSafetyTimer) {
|
||||||
PWMSafetyTimer--;
|
PWMSafetyTimer--;
|
||||||
if (lastPeriodWasFast != fastPWM) {
|
if (lastPeriodWasFast != fastPWM) {
|
||||||
@@ -92,11 +97,12 @@ void start_PWM_output(void) {
|
|||||||
} else {
|
} else {
|
||||||
PWM_Channel_Disable(PWM_Channel);
|
PWM_Channel_Disable(PWM_Channel);
|
||||||
}
|
}
|
||||||
|
TIMER_Enable(TIMER_CH0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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_comp0_callback(void) {
|
void timer0_comp0_callback(void) {
|
||||||
PWM_Channel_Disable(PWM_Channel);
|
TIMER_Disable(TIMER_CH0);
|
||||||
ADC_Start();
|
ADC_Start();
|
||||||
}
|
}
|
||||||
void timer0_comp1_callback(void) { PWM_Channel_Disable(PWM_Channel); } // Trigged at end of output cycle; turn off the tip PWM
|
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