mirror of
https://gitea.ecohim.ru:3000/RS485_Relay/RS485_Relay2_fw.git
synced 2025-08-05 23:56:37 +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:
@@ -6,7 +6,7 @@
|
|||||||
#ifndef BOARD_LOGIC_H_
|
#ifndef BOARD_LOGIC_H_
|
||||||
#define BOARD_LOGIC_H_
|
#define BOARD_LOGIC_H_
|
||||||
|
|
||||||
#define MODBUS_FIRMWARE_VERSION ( /*major*/ 11 + /*minor*/ 1 * 0x100)
|
#define MODBUS_FIRMWARE_VERSION ( /*major*/ 11 + /*minor*/ 2 * 0x100)
|
||||||
#define MODBUS_BOARD_TYPE (8) //Relay Module board ID
|
#define MODBUS_BOARD_TYPE (8) //Relay Module board ID
|
||||||
|
|
||||||
#define REL_MAIN_BIT (1u<<0)
|
#define REL_MAIN_BIT (1u<<0)
|
||||||
|
@@ -36,8 +36,8 @@ uint16_t status = 0;
|
|||||||
uint16_t motor1_pwm = 0;
|
uint16_t motor1_pwm = 0;
|
||||||
uint16_t motor2_pwm = 0;
|
uint16_t motor2_pwm = 0;
|
||||||
uint16_t lights_pwm = 0;
|
uint16_t lights_pwm = 0;
|
||||||
uint16_t lights_pwm_target = 0;
|
volatile uint16_t lights_pwm_target = 0;
|
||||||
int16_t lights_pwm_delta = 0;
|
volatile int16_t lights_pwm_delta = 0;
|
||||||
uint16_t led_time_act = 0;
|
uint16_t led_time_act = 0;
|
||||||
|
|
||||||
void estop_reset(void) {
|
void estop_reset(void) {
|
||||||
@@ -88,11 +88,11 @@ void set_pwm(uint8_t unit, uint16_t duty) {
|
|||||||
|
|
||||||
duty = clamp_duty(duty);
|
duty = clamp_duty(duty);
|
||||||
if (duty == 0)
|
if (duty == 0)
|
||||||
HAL_TIM_PWM_Stop(tim, channel);
|
HAL_TIM_PWM_Stop_IT(tim, channel);
|
||||||
else {
|
else {
|
||||||
HAL_TIM_PWM_Start(tim, channel);
|
HAL_TIM_PWM_Start_IT(tim, channel);
|
||||||
__HAL_TIM_SetCompare(tim, channel, duty);
|
__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()
|
void loop_iterate()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -259,22 +276,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||||
// check if the interrupt comes from TIM1
|
// check if the interrupt comes from TIM1
|
||||||
if(htim->Instance == TIM1) {
|
if(htim->Instance == TIM1) {
|
||||||
static uint32_t count_ms = 0;
|
|
||||||
|
|
||||||
update_service_indication();
|
update_service_indication();
|
||||||
|
|
||||||
// Check if we should change lights pwm for smooth transition
|
update_light();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -78,6 +78,7 @@ static void MX_TIM14_Init(void);
|
|||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
@@ -95,7 +96,7 @@ int main(void)
|
|||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
/* USER CODE BEGIN SysInit */
|
||||||
HAL_Delay(400);
|
// HAL_Delay(400);
|
||||||
/* USER CODE END SysInit */
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
@@ -106,6 +107,7 @@ int main(void)
|
|||||||
MX_TIM1_Init();
|
MX_TIM1_Init();
|
||||||
MX_TIM14_Init();
|
MX_TIM14_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
HAL_Delay(400);
|
||||||
board_init();
|
board_init();
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
@@ -234,7 +236,7 @@ static void MX_TIM3_Init(void)
|
|||||||
htim3.Instance = TIM3;
|
htim3.Instance = TIM3;
|
||||||
htim3.Init.Prescaler = 240-1;
|
htim3.Init.Prescaler = 240-1;
|
||||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim3.Init.Period = 255;
|
htim3.Init.Period = 255-1;
|
||||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
|
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
|
||||||
@@ -286,7 +288,7 @@ static void MX_TIM14_Init(void)
|
|||||||
htim14.Instance = TIM14;
|
htim14.Instance = TIM14;
|
||||||
htim14.Init.Prescaler = 6-1;
|
htim14.Init.Prescaler = 6-1;
|
||||||
htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim14.Init.Period = 255;
|
htim14.Init.Period = 255-1;
|
||||||
htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
|
if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
|
||||||
|
@@ -78,5 +78,6 @@
|
|||||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
<listEntry value="4"/>
|
<listEntry value="4"/>
|
||||||
</listAttribute>
|
</listAttribute>
|
||||||
|
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><memoryBlockExpressionList context="reserved-for-future-use"/>"/>
|
||||||
<stringAttribute key="process_factory_id" value="com.st.stm32cube.ide.mcu.debug.launch.HardwareDebugProcessFactory"/>
|
<stringAttribute key="process_factory_id" value="com.st.stm32cube.ide.mcu.debug.launch.HardwareDebugProcessFactory"/>
|
||||||
</launchConfiguration>
|
</launchConfiguration>
|
||||||
|
@@ -66,8 +66,8 @@ Mcu.PinsNb=23
|
|||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32F030K6Tx
|
Mcu.UserName=STM32F030K6Tx
|
||||||
MxCube.Version=6.10.0
|
MxCube.Version=6.11.1
|
||||||
MxDb.Version=DB.6.0.100
|
MxDb.Version=DB.6.0.111
|
||||||
NVIC.DMA1_Channel2_3_IRQn=true\:2\:0\:true\:false\:true\:false\:true\:true
|
NVIC.DMA1_Channel2_3_IRQn=true\:2\:0\:true\:false\:true\:false\:true\:true
|
||||||
NVIC.EXTI0_1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.EXTI0_1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.EXTI4_15_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.EXTI4_15_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
@@ -137,8 +137,9 @@ PB1.GPIOParameters=GPIO_Label
|
|||||||
PB1.GPIO_Label=LED_ACT
|
PB1.GPIO_Label=LED_ACT
|
||||||
PB1.Locked=true
|
PB1.Locked=true
|
||||||
PB1.Signal=GPIO_Output
|
PB1.Signal=GPIO_Output
|
||||||
PB3.GPIOParameters=GPIO_Label
|
PB3.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||||
PB3.GPIO_Label=RL_MAIN
|
PB3.GPIO_Label=RL_MAIN
|
||||||
|
PB3.GPIO_PuPd=GPIO_NOPULL
|
||||||
PB3.Locked=true
|
PB3.Locked=true
|
||||||
PB3.Signal=GPIO_Output
|
PB3.Signal=GPIO_Output
|
||||||
PB4.Locked=true
|
PB4.Locked=true
|
||||||
@@ -158,7 +159,7 @@ ProjectManager.CustomerFirmwarePackage=
|
|||||||
ProjectManager.DefaultFWLocation=true
|
ProjectManager.DefaultFWLocation=true
|
||||||
ProjectManager.DeletePrevious=true
|
ProjectManager.DeletePrevious=true
|
||||||
ProjectManager.DeviceId=STM32F030K6Tx
|
ProjectManager.DeviceId=STM32F030K6Tx
|
||||||
ProjectManager.FirmwarePackage=STM32Cube FW_F0 V1.11.4
|
ProjectManager.FirmwarePackage=STM32Cube FW_F0 V1.11.5
|
||||||
ProjectManager.FreePins=false
|
ProjectManager.FreePins=false
|
||||||
ProjectManager.HalAssertFull=false
|
ProjectManager.HalAssertFull=false
|
||||||
ProjectManager.HeapSize=0x200
|
ProjectManager.HeapSize=0x200
|
||||||
@@ -215,12 +216,12 @@ TIM1.Prescaler=480-1
|
|||||||
TIM14.Channel=TIM_CHANNEL_1
|
TIM14.Channel=TIM_CHANNEL_1
|
||||||
TIM14.IPParameters=Channel,Prescaler,Period,OCMode_PWM
|
TIM14.IPParameters=Channel,Prescaler,Period,OCMode_PWM
|
||||||
TIM14.OCMode_PWM=TIM_OCMODE_PWM1
|
TIM14.OCMode_PWM=TIM_OCMODE_PWM1
|
||||||
TIM14.Period=255
|
TIM14.Period=255-1
|
||||||
TIM14.Prescaler=6-1
|
TIM14.Prescaler=6-1
|
||||||
TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||||
TIM3.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
TIM3.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||||
TIM3.IPParameters=Channel-PWM Generation1 CH1,Prescaler,Period,Channel-PWM Generation2 CH2
|
TIM3.IPParameters=Channel-PWM Generation1 CH1,Prescaler,Period,Channel-PWM Generation2 CH2
|
||||||
TIM3.Period=255
|
TIM3.Period=255-1
|
||||||
TIM3.Prescaler=240-1
|
TIM3.Prescaler=240-1
|
||||||
USART1.BaudRate=9600
|
USART1.BaudRate=9600
|
||||||
USART1.IPParameters=VirtualMode-Asynchronous,BaudRate
|
USART1.IPParameters=VirtualMode-Asynchronous,BaudRate
|
||||||
|
Reference in New Issue
Block a user