mirror of
https://gitea.ecohim.ru:3000/RS485_Relay/RS485_Relay2_fw.git
synced 2025-08-07 16:20:30 +03:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -78,6 +78,7 @@ static void MX_TIM14_Init(void);
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
@@ -95,7 +96,7 @@ int main(void)
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
HAL_Delay(400);
|
||||
// HAL_Delay(400);
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
@@ -106,6 +107,7 @@ int main(void)
|
||||
MX_TIM1_Init();
|
||||
MX_TIM14_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
HAL_Delay(400);
|
||||
board_init();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
@@ -234,7 +236,7 @@ static void MX_TIM3_Init(void)
|
||||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 240-1;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 255;
|
||||
htim3.Init.Period = 255-1;
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
|
||||
@@ -286,7 +288,7 @@ static void MX_TIM14_Init(void)
|
||||
htim14.Instance = TIM14;
|
||||
htim14.Init.Prescaler = 6-1;
|
||||
htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim14.Init.Period = 255;
|
||||
htim14.Init.Period = 255-1;
|
||||
htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
|
||||
|
Reference in New Issue
Block a user