TIM3 CH1 (PC6) mit 25kHz initialisiert.
Über LL_TIM_OC_SetCompareCH1 kann der Duty-Cycle bestimmt werden von 0 bis 2559 (0 - 100%)
This commit is contained in:
parent
e301ae69c3
commit
063456aaca
61
Source/FanControl.cpp
Normal file
61
Source/FanControl.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
26
Source/FanControl.hpp
Normal file
26
Source/FanControl.hpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* FanControl.hpp
|
||||||
|
*
|
||||||
|
* Created on: 27.07.2023
|
||||||
|
* Author: Carst
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FANCONTROL_HPP_
|
||||||
|
#define FANCONTROL_HPP_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace ElektronischeLast
|
||||||
|
{
|
||||||
|
class FanControl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FanControl(void);
|
||||||
|
~FanControl(void);
|
||||||
|
void run(std::uint32_t temp);
|
||||||
|
private:
|
||||||
|
std::uint32_t compare_value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FANCONTROL_HPP_ */
|
Loading…
x
Reference in New Issue
Block a user