Compare commits
3 Commits
3dfe59482e
...
45c0625864
Author | SHA1 | Date | |
---|---|---|---|
45c0625864 | |||
03e1ccf97e | |||
0fd738f37e |
@ -39,27 +39,28 @@ static float IN_SECTION(.ccm.bss) filter_alpha;
|
||||
|
||||
/**
|
||||
* @brief Filtered PT1000 resistance value.
|
||||
* @note This value is not yet calibrated. Use @ref adc_pt1000_get_current_resistance to get this value with calibration.
|
||||
* @note This value is not yet calibrated.
|
||||
* Use @ref adc_pt1000_get_current_resistance to get this value with calibration.
|
||||
*/
|
||||
static volatile float IN_SECTION(.ccm.bss) pt1000_res_raw_lf;
|
||||
|
||||
static volatile int * volatile streaming_flag_ptr = NULL;
|
||||
static volatile int * volatile streaming_flag_ptr;
|
||||
static uint32_t IN_SECTION(.ccm.bss) filter_startup_cnt;
|
||||
static volatile float IN_SECTION(.ccm.bss) adc_pt1000_raw_reading_hf;
|
||||
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
|
||||
static volatile uint32_t IN_SECTION(.ccm.bss) adc_watchdog_counter = 0UL;
|
||||
static volatile uint32_t IN_SECTION(.ccm.bss) adc_watchdog_counter;
|
||||
|
||||
volatile float * volatile stream_buffer = NULL;
|
||||
volatile float * volatile stream_buffer;
|
||||
volatile uint32_t stream_count;
|
||||
volatile uint32_t stream_pos;
|
||||
|
||||
static inline void adc_pt1000_stop_sample_frequency_timer()
|
||||
static inline void adc_pt1000_stop_sample_frequency_timer(void)
|
||||
{
|
||||
TIM2->CR1 &= ~TIM_CR1_CEN;
|
||||
rcc_manager_disable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_TIM2EN));
|
||||
}
|
||||
|
||||
static inline void adc_pt1000_setup_sample_frequency_timer()
|
||||
static inline void adc_pt1000_setup_sample_frequency_timer(void)
|
||||
{
|
||||
rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_TIM2EN));
|
||||
|
||||
@ -77,7 +78,7 @@ static inline void adc_pt1000_setup_sample_frequency_timer()
|
||||
|
||||
}
|
||||
|
||||
static inline void adc_pt1000_disable_adc()
|
||||
static inline void adc_pt1000_disable_adc(void)
|
||||
{
|
||||
ADC_PT1000_PERIPH->CR2 &= ~ADC_CR2_ADON;
|
||||
DMA2_Stream0->CR = 0;
|
||||
@ -99,7 +100,7 @@ static inline void adc_pt1000_disable_adc()
|
||||
* After that, the moving average filter is fed with the values.
|
||||
*
|
||||
*/
|
||||
static inline void adc_pt1000_enable_dma_stream()
|
||||
static inline void adc_pt1000_enable_dma_stream(void)
|
||||
{
|
||||
/* Enable peripheral clock for DMA2 */
|
||||
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(RCC_AHB1ENR_DMA2EN));
|
||||
@ -124,7 +125,7 @@ static inline void adc_pt1000_enable_dma_stream()
|
||||
DMA_SxCR_CIRC | DMA_SxCR_TCIE | DMA_SxCR_TEIE | DMA_SxCR_EN | ((ADC_PT1000_CHANNEL & 0x7)<<25);
|
||||
}
|
||||
|
||||
static inline void adc_pt1000_disable_dma_stream()
|
||||
static inline void adc_pt1000_disable_dma_stream(void)
|
||||
{
|
||||
/* Disable the stream */
|
||||
DMA2_Stream0->CR = 0;
|
||||
@ -136,7 +137,7 @@ static inline void adc_pt1000_disable_dma_stream()
|
||||
NVIC_DisableIRQ(DMA2_Stream0_IRQn);
|
||||
}
|
||||
|
||||
void adc_pt1000_setup_meas()
|
||||
void adc_pt1000_setup_meas(void)
|
||||
{
|
||||
rcc_manager_enable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(RCC_APB2ENR_ADC3EN));
|
||||
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ADC_PT1000_PORT_RCC_MASK));
|
||||
@ -163,7 +164,8 @@ void adc_pt1000_setup_meas()
|
||||
ADC_PT1000_PERIPH->SQR3 = (ADC_PT1000_CHANNEL<<0);
|
||||
|
||||
ADC_PT1000_PERIPH->CR1 = ADC_CR1_OVRIE | ADC_CR1_AWDEN | ADC_CR1_AWDIE;
|
||||
ADC_PT1000_PERIPH->CR2 = ADC_CR2_EXTEN_0 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
ADC_PT1000_PERIPH->CR2 = ADC_CR2_EXTEN_0 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 |
|
||||
ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
|
||||
adc_pt1000_set_moving_average_filter_param(ADC_PT1000_FILTER_WEIGHT);
|
||||
adc_pt1000_set_resistance_calibration(0, 0, false);
|
||||
@ -176,6 +178,10 @@ void adc_pt1000_setup_meas()
|
||||
adc_pt1000_setup_sample_frequency_timer();
|
||||
|
||||
safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_OFF, MEAS_ADC_SAFETY_FLAG_KEY);
|
||||
|
||||
streaming_flag_ptr = NULL;
|
||||
adc_watchdog_counter = 0UL;
|
||||
stream_buffer = NULL;
|
||||
}
|
||||
|
||||
void adc_pt1000_set_moving_average_filter_param(float alpha)
|
||||
@ -191,12 +197,11 @@ void adc_pt1000_set_resistance_calibration(float offset, float sensitivity_devia
|
||||
pt1000_sens_dev = sensitivity_deviation;
|
||||
calibration_active = active;
|
||||
|
||||
if (!calibration_active) {
|
||||
if (!calibration_active)
|
||||
safety_controller_report_error_with_key(ERR_FLAG_UNCAL, MEAS_ADC_SAFETY_FLAG_KEY);
|
||||
} else {
|
||||
else
|
||||
safety_controller_ack_flag_with_key(ERR_FLAG_UNCAL, MEAS_ADC_SAFETY_FLAG_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
void adc_pt1000_get_resistance_calibration(float *offset, float *sensitivity_deviation, bool *active)
|
||||
{
|
||||
@ -280,7 +285,7 @@ void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, fl
|
||||
resistance_dest[i] = ADC_TO_RES(raw_source[i]);
|
||||
}
|
||||
|
||||
void adc_pt1000_disable()
|
||||
void adc_pt1000_disable(void)
|
||||
{
|
||||
adc_pt1000_disable_adc();
|
||||
adc_pt1000_stop_sample_frequency_timer();
|
||||
@ -300,16 +305,15 @@ static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_p
|
||||
{
|
||||
if (filter_startup_cnt > 0) {
|
||||
filter_startup_cnt--;
|
||||
if (filter_startup_cnt == 0) {
|
||||
if (filter_startup_cnt == 0)
|
||||
safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
pt1000_res_raw_lf = (1.0f-filter_alpha) * pt1000_res_raw_lf + filter_alpha * ADC_TO_RES(adc_prefiltered_value);
|
||||
safety_controller_report_timing(ERR_TIMING_MEAS_ADC);
|
||||
}
|
||||
|
||||
static inline __attribute__((optimize("O3"))) float adc_pt1000_dma_avg_pre_filter()
|
||||
static inline __attribute__((optimize("O3"))) float adc_pt1000_dma_avg_pre_filter(void)
|
||||
{
|
||||
unsigned int i;
|
||||
uint32_t sum = 0;
|
||||
@ -371,7 +375,7 @@ static void append_stream_buffer(float val)
|
||||
|
||||
}
|
||||
|
||||
void DMA2_Stream0_IRQHandler()
|
||||
void DMA2_Stream0_IRQHandler(void)
|
||||
{
|
||||
uint32_t lisr;
|
||||
float adc_val;
|
||||
@ -394,8 +398,7 @@ void DMA2_Stream0_IRQHandler()
|
||||
adc_pt1000_filter(adc_val);
|
||||
}
|
||||
|
||||
if (lisr & DMA_LISR_TEIF0) {
|
||||
if (lisr & DMA_LISR_TEIF0)
|
||||
adc_pt1000_disable();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* C++ library init */
|
||||
# if defined(__cplusplus)
|
||||
extern "C" {
|
||||
@ -280,9 +282,22 @@ extern unsigned int __ld_ebss;
|
||||
extern unsigned int __ld_sheap;
|
||||
extern unsigned int __ld_eheap;
|
||||
|
||||
#ifdef CPACR
|
||||
#undef CPACR
|
||||
#endif
|
||||
|
||||
#define CPACR (*((volatile uint32_t *)0xE000ED88))
|
||||
|
||||
void Reset_Handler(void) {
|
||||
/* Stack is already initialized by hardware */
|
||||
|
||||
/* The first thing we do here, is to initialize the FPU
|
||||
* When this code is compiled optimized with hardfpu abi,
|
||||
* GCC tends to generate FPU instructions for data copying
|
||||
*/
|
||||
CPACR |= (0xF << 20);
|
||||
|
||||
|
||||
/* Copy .data section */
|
||||
__init_section(&__ld_load_data, &__ld_sdata, &__ld_edata);
|
||||
/* Fill bss with zero */
|
||||
|
@ -47,7 +47,7 @@ static void digio_setup_pin_int(uint8_t bit_no, uint8_t in_out, uint8_t alt_func
|
||||
|
||||
}
|
||||
|
||||
void digio_setup_default_all()
|
||||
void digio_setup_default_all(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
@ -90,7 +90,7 @@ int digio_get(uint8_t num)
|
||||
|
||||
static const uint8_t led_pins[] = {LED_PINS};
|
||||
|
||||
void led_setup()
|
||||
void led_setup(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
@ -132,7 +132,7 @@ static void loudspeaker_freq_timer_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void loudspeaker_setup()
|
||||
void loudspeaker_setup(void)
|
||||
{
|
||||
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(LOUDSPEAKER_RCC_MASK));
|
||||
|
||||
@ -179,7 +179,7 @@ void loudspeaker_set(uint16_t val)
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t loudspeaker_get()
|
||||
uint16_t loudspeaker_get(void)
|
||||
{
|
||||
return loudspeaker_val;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@
|
||||
* The filter weight \f$\alpha\f$ is configured for @ref ADC_PT1000_FILTER_WEIGHT
|
||||
*
|
||||
*/
|
||||
void adc_pt1000_setup_meas();
|
||||
void adc_pt1000_setup_meas(void);
|
||||
|
||||
/**
|
||||
* @brief Set moving average filter parameters
|
||||
@ -180,6 +180,6 @@ void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, fl
|
||||
/**
|
||||
* @brief Disable the PT1000 measurement
|
||||
*/
|
||||
void adc_pt1000_disable();
|
||||
void adc_pt1000_disable(void);
|
||||
|
||||
#endif // __ADCMEAS_H__
|
||||
|
@ -41,7 +41,7 @@ void oven_pid_init(struct pid_controller *controller_to_copy);
|
||||
|
||||
void oven_pid_handle(float target_temp);
|
||||
|
||||
void oven_pid_stop();
|
||||
void oven_pid_stop(void);
|
||||
|
||||
void oven_driver_apply_power_level(void);
|
||||
|
||||
|
@ -28,11 +28,11 @@
|
||||
#include <reflow-controller/safety/safety-controller.h>
|
||||
|
||||
static struct pid_controller IN_SECTION(.ccm.bss) oven_pid;
|
||||
static bool oven_pid_running = false;
|
||||
static bool oven_pid_aborted = false;
|
||||
static uint8_t IN_SECTION(.ccm.bss) oven_driver_power_level = 0U;
|
||||
static bool oven_pid_running;
|
||||
static bool oven_pid_aborted;
|
||||
static uint8_t IN_SECTION(.ccm.bss) oven_driver_power_level;
|
||||
|
||||
void oven_driver_init()
|
||||
void oven_driver_init(void)
|
||||
{
|
||||
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(OVEN_CONTROLLER_PORT_RCC_MASK));
|
||||
rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(OVEN_CONTROLLER_TIM_RCC_MASK));
|
||||
@ -50,6 +50,12 @@ void oven_driver_init()
|
||||
OVEN_CONTROLLER_PWM_TIMER->PSC = 42000U - 1U;
|
||||
|
||||
OVEN_CONTROLLER_PWM_TIMER->CR1 = TIM_CR1_CMS | TIM_CR1_CEN;
|
||||
|
||||
/* Explicitly init global variables */
|
||||
oven_pid_aborted = false;
|
||||
oven_pid_running = false;
|
||||
|
||||
oven_driver_set_power(0U);
|
||||
}
|
||||
|
||||
void oven_driver_set_power(uint8_t power)
|
||||
@ -65,7 +71,7 @@ void oven_driver_apply_power_level(void)
|
||||
OVEN_CONTROLLER_PWM_TIMER->CCR3 = oven_driver_power_level * 10;
|
||||
}
|
||||
|
||||
void oven_driver_disable()
|
||||
void oven_driver_disable(void)
|
||||
{
|
||||
OVEN_CONTROLLER_PWM_TIMER->CR1 = 0UL;
|
||||
OVEN_CONTROLLER_PWM_TIMER->CR2 = 0UL;
|
||||
@ -105,9 +111,10 @@ void oven_pid_handle(float target_temp)
|
||||
}
|
||||
}
|
||||
|
||||
void oven_pid_stop()
|
||||
void oven_pid_stop(void)
|
||||
{
|
||||
oven_pid_running = false;
|
||||
oven_driver_set_power(0U);
|
||||
safety_controller_enable_timing_mon(ERR_TIMING_PID, false);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,8 @@
|
||||
#include <reflow-controller/pid-controller.h>
|
||||
#include <string.h>
|
||||
|
||||
void pid_init(struct pid_controller *pid, float k_deriv, float k_int, float k_p, float output_sat_min, float output_sat_max, float integral_max, float sample_period)
|
||||
void pid_init(struct pid_controller *pid, float k_deriv, float k_int, float k_p, float output_sat_min,
|
||||
float output_sat_max, float integral_max, float sample_period)
|
||||
{
|
||||
if (!pid)
|
||||
return;
|
||||
@ -61,12 +62,11 @@ static void calculate_integral(struct pid_controller *pid, float deviation)
|
||||
pid->integral = pid->integral + pid->k_int_t * (deviation + pid->last_in);
|
||||
|
||||
/* Saturate integral term to spoecified maximum */
|
||||
if (pid->integral > pid->integral_max) {
|
||||
if (pid->integral > pid->integral_max)
|
||||
pid->integral = pid->integral_max;
|
||||
} else if (pid->integral < -pid->integral_max){
|
||||
else if (pid->integral < -pid->integral_max)
|
||||
pid->integral = -pid->integral_max;
|
||||
}
|
||||
}
|
||||
|
||||
float pid_sample(struct pid_controller *pid, float deviation)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user