Über LL_TIM_OC_SetCompareCH1 kann der Duty-Cycle bestimmt werden von 0 bis 2559 (0 - 100%)
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
/*
|
|
* FanControl.cpp
|
|
*
|
|
* Created on: 27.07.2023
|
|
* Author: Carst
|
|
*/
|
|
|
|
#include <stm32g0xx_ll_bus.h>
|
|
#include <stm32g0xx_ll_gpio.h>
|
|
#include <stm32g0xx_ll_tim.h>
|
|
#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);
|
|
}
|
|
}
|