v11.2 changes:

- moved 400ms boot delay to a point AFTER peripherals init
- fixed TIM3 and TIM14 periods
- mvoed light updates to separate function and fixed cuty cylce clamp during dimming process
This commit is contained in:
Anton Mukhin
2024-06-21 15:22:50 +03:00
parent ed9ba49c9c
commit 900f6d7d85
5 changed files with 37 additions and 29 deletions

View File

@@ -36,8 +36,8 @@ uint16_t status = 0;
uint16_t motor1_pwm = 0;
uint16_t motor2_pwm = 0;
uint16_t lights_pwm = 0;
uint16_t lights_pwm_target = 0;
int16_t lights_pwm_delta = 0;
volatile uint16_t lights_pwm_target = 0;
volatile int16_t lights_pwm_delta = 0;
uint16_t led_time_act = 0;
void estop_reset(void) {
@@ -88,11 +88,11 @@ void set_pwm(uint8_t unit, uint16_t duty) {
duty = clamp_duty(duty);
if (duty == 0)
HAL_TIM_PWM_Stop(tim, channel);
HAL_TIM_PWM_Stop_IT(tim, channel);
else {
HAL_TIM_PWM_Start(tim, channel);
HAL_TIM_PWM_Start_IT(tim, channel);
__HAL_TIM_SetCompare(tim, channel, duty);
HAL_Delay(5);
//HAL_Delay(1);
}
}
@@ -107,6 +107,23 @@ void set_light(uint16_t duty) {
}
}
void update_light(void) {
static uint32_t count_ms = 0;
// Check if we should change lights pwm for smooth transition
if (lights_pwm != lights_pwm_target) {
// Change pwm only every 20ms (PWM_LIGHTS_STEP)
if(++count_ms == PWM_LIGHTS_STEP) {
count_ms = 0;
lights_pwm = clamp_duty(lights_pwm + lights_pwm_delta);
// Set lights pwm to target if the difference is less than the delta
if (abs(lights_pwm_target - lights_pwm) < abs(lights_pwm_delta))
lights_pwm = lights_pwm_target;
set_pwm(3, lights_pwm);
}
}
}
void loop_iterate()
{
@@ -259,22 +276,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
// check if the interrupt comes from TIM1
if(htim->Instance == TIM1) {
static uint32_t count_ms = 0;
update_service_indication();
// Check if we should change lights pwm for smooth transition
if (lights_pwm != lights_pwm_target) {
// Change pwm only every 20ms (PWM_LIGHTS_STEP)
if(++count_ms == PWM_LIGHTS_STEP) {
count_ms = 0;
lights_pwm += lights_pwm_delta;
// Set lights pwm to target if the difference is less than the delta
if (abs(lights_pwm_target - lights_pwm) < abs(lights_pwm_delta))
lights_pwm = lights_pwm_target;
set_pwm(3, lights_pwm);
}
}
update_light();
}
}