Change timing scheduler to only run main timer once ADC is done
This commit is contained in:
@@ -17,6 +17,7 @@ extern "C" {
|
|||||||
#include "bl702_pwm.h"
|
#include "bl702_pwm.h"
|
||||||
#include "bl702_timer.h"
|
#include "bl702_timer.h"
|
||||||
}
|
}
|
||||||
|
void start_PWM_output(void);
|
||||||
|
|
||||||
#define ADC_Filter_Smooth 4
|
#define ADC_Filter_Smooth 4
|
||||||
history<uint16_t, ADC_Filter_Smooth> ADC_Vin;
|
history<uint16_t, ADC_Filter_Smooth> ADC_Vin;
|
||||||
@@ -24,6 +25,7 @@ history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
|
|||||||
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
|
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
|
||||||
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()) {
|
||||||
volatile uint32_t reading = ADC_Read_FIFO();
|
volatile uint32_t reading = ADC_Read_FIFO();
|
||||||
@@ -45,7 +47,6 @@ void adc_fifo_irq(void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
@@ -66,12 +67,10 @@ volatile uint16_t PWMSafetyTimer = 0;
|
|||||||
volatile uint8_t pendingPWM = 0;
|
volatile uint8_t pendingPWM = 0;
|
||||||
volatile bool lastPeriodWasFast = false;
|
volatile bool lastPeriodWasFast = false;
|
||||||
|
|
||||||
// Timer 0 is used to co-ordinate the ADC and the output PWM
|
void start_PWM_output(void) {
|
||||||
void timer0_comp0_callback(void) { ADC_Start(); }
|
|
||||||
void timer0_comp1_callback(void) { PWM_Channel_Disable(PWM_Channel); }
|
TIMER_Enable(TIMER_CH0);
|
||||||
void timer0_comp2_callback(void) {
|
|
||||||
|
|
||||||
// This occurs at timer rollover, so if we want to turn on the output PWM; we do so
|
|
||||||
if (PWMSafetyTimer) {
|
if (PWMSafetyTimer) {
|
||||||
PWMSafetyTimer--;
|
PWMSafetyTimer--;
|
||||||
if (lastPeriodWasFast != fastPWM) {
|
if (lastPeriodWasFast != fastPWM) {
|
||||||
@@ -95,6 +94,10 @@ void timer0_comp2_callback(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timer 0 is used to co-ordinate the ADC and the output PWM
|
||||||
|
void timer0_comp0_callback(void) { ADC_Start(); }
|
||||||
|
void timer0_comp1_callback(void) { PWM_Channel_Disable(PWM_Channel); } // Trigged at end of output cycle; turn off the tip PWM
|
||||||
|
|
||||||
void switchToFastPWM(void) {
|
void switchToFastPWM(void) {
|
||||||
fastPWM = true;
|
fastPWM = true;
|
||||||
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
|
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
|
||||||
|
|||||||
@@ -141,30 +141,26 @@ void setup_timer_scheduler() {
|
|||||||
TIMER_CFG_Type cfg = {
|
TIMER_CFG_Type cfg = {
|
||||||
TIMER_CH0, // Channel
|
TIMER_CH0, // Channel
|
||||||
TIMER_CLKSRC_32K, // Clock source
|
TIMER_CLKSRC_32K, // Clock source
|
||||||
TIMER_PRELOAD_TRIG_COMP2, // Trigger
|
TIMER_PRELOAD_TRIG_COMP0, // Trigger; reset after trigger 0
|
||||||
TIMER_COUNT_PRELOAD, // Counter mode
|
TIMER_COUNT_PRELOAD, // Counter mode
|
||||||
22, // Clock div
|
22, // Clock div
|
||||||
(uint16_t)(powerPWM + holdoffTicks), // CH0 compare (adc)
|
(uint16_t)(powerPWM + holdoffTicks), // CH0 compare (adc)
|
||||||
0, // CH1 compare (pwm out)
|
0, // CH1 compare (pwm out)
|
||||||
(uint16_t)(powerPWM + tempMeasureTicks + holdoffTicks), // CH2 comapre (total period)
|
0, // CH2 compare not used
|
||||||
0, // Preload
|
0, // Preload
|
||||||
};
|
};
|
||||||
TIMER_Init(&cfg);
|
TIMER_Init(&cfg);
|
||||||
|
|
||||||
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_0, timer0_comp0_callback);
|
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_0, timer0_comp0_callback);
|
||||||
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_1, timer0_comp1_callback);
|
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_1, timer0_comp1_callback);
|
||||||
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_2, timer0_comp2_callback);
|
|
||||||
|
|
||||||
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_0);
|
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_0);
|
||||||
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_1);
|
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_1);
|
||||||
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_2);
|
|
||||||
|
|
||||||
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_0, UNMASK);
|
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_0, UNMASK);
|
||||||
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_1, UNMASK);
|
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_1, UNMASK);
|
||||||
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_2, UNMASK);
|
|
||||||
CPU_Interrupt_Enable(TIMER_CH0_IRQn);
|
CPU_Interrupt_Enable(TIMER_CH0_IRQn);
|
||||||
TIMER_Enable(TIMER_CH0);
|
TIMER_Enable(TIMER_CH0);
|
||||||
// switchToSlowPWM();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupFUSBIRQ() {
|
void setupFUSBIRQ() {
|
||||||
|
|||||||
Reference in New Issue
Block a user