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_ */