From 181f4575348153db66e5d38519d59ef9d53d6a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 6 Mar 2023 00:57:40 +0100 Subject: [PATCH] heater without pwm --- BluepillTrouba.ioc | 25 ++++------- Core/Inc/tim.h | 3 -- Core/Src/app_heater.c | 16 +++---- Core/Src/gpio.c | 10 +++++ Core/Src/main.c | 1 - Core/Src/tim.c | 97 +------------------------------------------ Makefile | 2 +- 7 files changed, 27 insertions(+), 127 deletions(-) diff --git a/BluepillTrouba.ioc b/BluepillTrouba.ioc index 2280727..d087fba 100644 --- a/BluepillTrouba.ioc +++ b/BluepillTrouba.ioc @@ -42,8 +42,7 @@ Mcu.CPN=STM32F103CBT6 Mcu.Family=STM32F1 Mcu.IP0=ADC1 Mcu.IP1=DMA -Mcu.IP10=TIM4 -Mcu.IP11=USART1 +Mcu.IP10=USART1 Mcu.IP2=FREERTOS Mcu.IP3=IWDG Mcu.IP4=NVIC @@ -51,8 +50,8 @@ Mcu.IP5=RCC Mcu.IP6=SPI1 Mcu.IP7=SYS Mcu.IP8=TIM2 -Mcu.IP9=TIM3 -Mcu.IPNb=12 +Mcu.IP9=TIM4 +Mcu.IPNb=11 Mcu.Name=STM32F103C(8-B)Tx Mcu.Package=LQFP48 Mcu.Pin0=PC13-TAMPER-RTC @@ -73,7 +72,6 @@ Mcu.Pin21=VP_FREERTOS_VS_CMSIS_V2 Mcu.Pin22=VP_IWDG_VS_IWDG Mcu.Pin23=VP_SYS_VS_tim1 Mcu.Pin24=VP_TIM2_VS_ClockSourceINT -Mcu.Pin25=VP_TIM3_VS_ClockSourceINT Mcu.Pin3=PA0-WKUP Mcu.Pin4=PA1 Mcu.Pin5=PA5 @@ -81,7 +79,7 @@ Mcu.Pin6=PA6 Mcu.Pin7=PA7 Mcu.Pin8=PB0 Mcu.Pin9=PB1 -Mcu.PinsNb=26 +Mcu.PinsNb=25 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F103CBTx @@ -129,10 +127,10 @@ PA5.GPIOParameters=GPIO_Label PA5.GPIO_Label=OLED_SCLK PA5.Mode=TX_Only_Simplex_Unidirect_Master PA5.Signal=SPI1_SCK -PA6.GPIOParameters=GPIO_Speed,GPIO_Label +PA6.GPIOParameters=GPIO_Label PA6.GPIO_Label=HEATER -PA6.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA6.Signal=S_TIM3_CH1 +PA6.Locked=true +PA6.Signal=GPIO_Output PA7.GPIOParameters=GPIO_Label PA7.GPIO_Label=OLED_MOSI PA7.Mode=TX_Only_Simplex_Unidirect_Master @@ -231,8 +229,6 @@ SH.ADCx_IN1.0=ADC1_IN1,IN1 SH.ADCx_IN1.ConfNb=1 SH.S_TIM2_CH1_ETR.0=TIM2_CH1,PWM Generation1 CH1 SH.S_TIM2_CH1_ETR.ConfNb=1 -SH.S_TIM3_CH1.0=TIM3_CH1,PWM Generation1 CH1 -SH.S_TIM3_CH1.ConfNb=1 SH.S_TIM4_CH1.0=TIM4_CH1,Encoder_Interface SH.S_TIM4_CH1.ConfNb=1 SH.S_TIM4_CH2.0=TIM4_CH2,Encoder_Interface @@ -246,11 +242,6 @@ SPI1.VirtualType=VM_MASTER TIM2.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 TIM2.IPParameters=Channel-PWM Generation1 CH1,Prescaler TIM2.Prescaler=2 -TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 -TIM3.IPParameters=Channel-PWM Generation1 CH1,Prescaler,Pulse-PWM Generation1 CH1,Period -TIM3.Period=65535 -TIM3.Prescaler=2 -TIM3.Pulse-PWM\ Generation1\ CH1=0 TIM4.IC2Filter=15 TIM4.IPParameters=IC2Filter,Prescaler TIM4.Prescaler=0 @@ -269,6 +260,4 @@ VP_SYS_VS_tim1.Mode=TIM1 VP_SYS_VS_tim1.Signal=SYS_VS_tim1 VP_TIM2_VS_ClockSourceINT.Mode=Internal VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -VP_TIM3_VS_ClockSourceINT.Mode=Internal -VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT board=custom diff --git a/Core/Inc/tim.h b/Core/Inc/tim.h index 9f1cdf9..280ba03 100644 --- a/Core/Inc/tim.h +++ b/Core/Inc/tim.h @@ -34,8 +34,6 @@ extern "C" { extern TIM_HandleTypeDef htim2; -extern TIM_HandleTypeDef htim3; - extern TIM_HandleTypeDef htim4; /* USER CODE BEGIN Private defines */ @@ -43,7 +41,6 @@ extern TIM_HandleTypeDef htim4; /* USER CODE END Private defines */ void MX_TIM2_Init(void); -void MX_TIM3_Init(void); void MX_TIM4_Init(void); void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); diff --git a/Core/Src/app_heater.c b/Core/Src/app_heater.c index 77e1f9d..c6ce038 100644 --- a/Core/Src/app_heater.c +++ b/Core/Src/app_heater.c @@ -8,18 +8,18 @@ void app_heater_init() { - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - TIM3->ARR = 25714; +// HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); +// TIM3->ARR = 25714; } void app_heater_set(bool active) { - if (active) { - TIM3->CCR1 = TIM3->ARR / 2; // testing - 50% - } else { - TIM3->CCR1 = 0; - } +// if (active) { +// TIM3->CCR1 = TIM3->ARR / 2; // testing - 50% +// } else { +// TIM3->CCR1 = 0; +// } - //HAL_GPIO_WritePin(HEATER_GPIO_Port, HEATER_Pin, active); + HAL_GPIO_WritePin(HEATER_GPIO_Port, HEATER_Pin, active); } diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index c20a16c..051092a 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -53,6 +53,9 @@ void MX_GPIO_Init(void) /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(HEATER_GPIO_Port, HEATER_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin, GPIO_PIN_RESET); @@ -63,6 +66,13 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pin : PtPin */ + GPIO_InitStruct.Pin = HEATER_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(HEATER_GPIO_Port, &GPIO_InitStruct); + /*Configure GPIO pins : PBPin PBPin PBPin */ GPIO_InitStruct.Pin = OLED_CS_Pin|OLED_DC_Pin|OLED_RST_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; diff --git a/Core/Src/main.c b/Core/Src/main.c index 458a762..8b9119f 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -104,7 +104,6 @@ int main(void) MX_DMA_Init(); MX_TIM4_Init(); MX_TIM2_Init(); - MX_TIM3_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ diff --git a/Core/Src/tim.c b/Core/Src/tim.c index 8c6ca91..54d2995 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -25,7 +25,6 @@ /* USER CODE END 0 */ TIM_HandleTypeDef htim2; -TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim4; /* TIM2 init function */ @@ -81,60 +80,6 @@ void MX_TIM2_Init(void) /* USER CODE END TIM2_Init 2 */ HAL_TIM_MspPostInit(&htim2); -} -/* TIM3 init function */ -void MX_TIM3_Init(void) -{ - - /* USER CODE BEGIN TIM3_Init 0 */ - - /* USER CODE END TIM3_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_OC_InitTypeDef sConfigOC = {0}; - - /* USER CODE BEGIN TIM3_Init 1 */ - - /* USER CODE END TIM3_Init 1 */ - htim3.Instance = TIM3; - htim3.Init.Prescaler = 2; - htim3.Init.CounterMode = TIM_COUNTERMODE_UP; - htim3.Init.Period = 65535; - htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim3) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - if (HAL_TIM_PWM_Init(&htim3) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 0; - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; - if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM3_Init 2 */ - - /* USER CODE END TIM3_Init 2 */ - HAL_TIM_MspPostInit(&htim3); - } /* TIM4 init function */ void MX_TIM4_Init(void) @@ -195,17 +140,6 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) /* USER CODE END TIM2_MspInit 1 */ } - else if(tim_baseHandle->Instance==TIM3) - { - /* USER CODE BEGIN TIM3_MspInit 0 */ - - /* USER CODE END TIM3_MspInit 0 */ - /* TIM3 clock enable */ - __HAL_RCC_TIM3_CLK_ENABLE(); - /* USER CODE BEGIN TIM3_MspInit 1 */ - - /* USER CODE END TIM3_MspInit 1 */ - } } void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* tim_encoderHandle) @@ -247,6 +181,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) /* USER CODE BEGIN TIM2_MspPostInit 0 */ /* USER CODE END TIM2_MspPostInit 0 */ + __HAL_RCC_GPIOA_CLK_ENABLE(); /**TIM2 GPIO Configuration PA15 ------> TIM2_CH1 @@ -262,25 +197,6 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) /* USER CODE END TIM2_MspPostInit 1 */ } - else if(timHandle->Instance==TIM3) - { - /* USER CODE BEGIN TIM3_MspPostInit 0 */ - - /* USER CODE END TIM3_MspPostInit 0 */ - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**TIM3 GPIO Configuration - PA6 ------> TIM3_CH1 - */ - GPIO_InitStruct.Pin = HEATER_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(HEATER_GPIO_Port, &GPIO_InitStruct); - - /* USER CODE BEGIN TIM3_MspPostInit 1 */ - - /* USER CODE END TIM3_MspPostInit 1 */ - } } @@ -298,17 +214,6 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) /* USER CODE END TIM2_MspDeInit 1 */ } - else if(tim_baseHandle->Instance==TIM3) - { - /* USER CODE BEGIN TIM3_MspDeInit 0 */ - - /* USER CODE END TIM3_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM3_CLK_DISABLE(); - /* USER CODE BEGIN TIM3_MspDeInit 1 */ - - /* USER CODE END TIM3_MspDeInit 1 */ - } } void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* tim_encoderHandle) diff --git a/Makefile b/Makefile index 37abef8..2d86b15 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Mon Mar 06 00:33:47 CET 2023] +# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Mon Mar 06 00:56:47 CET 2023] ########################################################################################################################## # ------------------------------------------------