From 063456aaca40111b396ca2a79aff34c577d3a605 Mon Sep 17 00:00:00 2001 From: Carsten Keller Date: Sun, 9 Jun 2024 17:57:51 +0200 Subject: [PATCH] =?UTF-8?q?TIM3=20CH1=20(PC6)=20mit=2025kHz=20initialisier?= =?UTF-8?q?t.=20=C3=9Cber=20LL=5FTIM=5FOC=5FSetCompareCH1=20kann=20der=20D?= =?UTF-8?q?uty-Cycle=20bestimmt=20werden=20von=200=20bis=202559=20(0=20-?= =?UTF-8?q?=20100%)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/FanControl.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++ Source/FanControl.hpp | 26 ++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Source/FanControl.cpp create mode 100644 Source/FanControl.hpp diff --git a/Source/FanControl.cpp b/Source/FanControl.cpp new file mode 100644 index 0000000..87b90c2 --- /dev/null +++ b/Source/FanControl.cpp @@ -0,0 +1,61 @@ +/* + * FanControl.cpp + * + * Created on: 27.07.2023 + * Author: Carst + */ + +#include +#include +#include +#include "FanControl.hpp" + +namespace ElektronischeLast +{ + FanControl::FanControl(void) + { + LL_TIM_InitTypeDef TIM_InitStruct = { + .Prescaler = 0UL, + .CounterMode = LL_TIM_COUNTERMODE_UP, + .Autoreload = 2559UL, + .ClockDivision = LL_TIM_CLOCKDIVISION_DIV1, + }; + LL_TIM_Init(TIM3, &TIM_InitStruct); + + LL_TIM_DisableARRPreload(TIM3); + LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH1); + LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = { + .OCMode = LL_TIM_OCMODE_PWM1, + .OCState = LL_TIM_OCSTATE_ENABLE, + .OCNState = LL_TIM_OCSTATE_DISABLE, + .CompareValue = 0UL, + .OCPolarity = LL_TIM_OCPOLARITY_HIGH, + }; + LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); + LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH1); + LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET); + LL_TIM_DisableMasterSlaveMode(TIM3); + + /**TIM3 GPIO Configuration + PC6 ------> TIM3_CH1 + */ + LL_GPIO_InitTypeDef GPIO_InitStruct = { + .Pin = LL_GPIO_PIN_6, + .Mode = LL_GPIO_MODE_ALTERNATE, + .Speed = LL_GPIO_SPEED_FREQ_LOW, + .OutputType = LL_GPIO_OUTPUT_PUSHPULL, + .Pull = LL_GPIO_PULL_NO, + .Alternate = LL_GPIO_AF_1, + }; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + LL_TIM_EnableCounter(TIM3); + + this->compare_value = 0UL; + } + + void FanControl::run(std::uint32_t temp) + { + LL_TIM_OC_SetCompareCH1(TIM3, this->compare_value); + } +} diff --git a/Source/FanControl.hpp b/Source/FanControl.hpp new file mode 100644 index 0000000..af0e7cd --- /dev/null +++ b/Source/FanControl.hpp @@ -0,0 +1,26 @@ +/* + * FanControl.hpp + * + * Created on: 27.07.2023 + * Author: Carst + */ + +#ifndef FANCONTROL_HPP_ +#define FANCONTROL_HPP_ + +#include + +namespace ElektronischeLast +{ + class FanControl + { + public: + FanControl(void); + ~FanControl(void); + void run(std::uint32_t temp); + private: + std::uint32_t compare_value; + }; +} + +#endif /* FANCONTROL_HPP_ */