Lüftersteuerung ist abhängig von der Temperatur und muss nicht mehr manuell gesetzt werden
This commit is contained in:
parent
bbabeae752
commit
19b2a3f088
@ -11,6 +11,7 @@
|
|||||||
#include "FanControl.hpp"
|
#include "FanControl.hpp"
|
||||||
|
|
||||||
#define TIMER_RELOAD_VALUE 2559UL
|
#define TIMER_RELOAD_VALUE 2559UL
|
||||||
|
#define DUTY_TO_TIM_VALUE(x) TIMER_RELOAD_VALUE * (x) / 100U
|
||||||
|
|
||||||
static std::uint32_t fan_speed;
|
static std::uint32_t fan_speed;
|
||||||
static std::uint32_t duty;
|
static std::uint32_t duty;
|
||||||
@ -23,10 +24,19 @@ extern "C" void TIM14_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
extern "C" void FanControl_SetDuty(uint32_t d)
|
extern "C" void FanControl_SetDuty(uint32_t d)
|
||||||
{
|
{
|
||||||
duty = TIMER_RELOAD_VALUE * d / 100UL ;
|
duty = DUTY_TO_TIM_VALUE(d);
|
||||||
}
|
}
|
||||||
namespace ElektronischeLast
|
namespace ElektronischeLast
|
||||||
{
|
{
|
||||||
|
static const std::uint16_t stuetzpunkte [5][2] =
|
||||||
|
{
|
||||||
|
{ 25U, DUTY_TO_TIM_VALUE(0U) },
|
||||||
|
{ 40U, DUTY_TO_TIM_VALUE(30U) },
|
||||||
|
{ 50U, DUTY_TO_TIM_VALUE(50U) },
|
||||||
|
{ 65U, DUTY_TO_TIM_VALUE(75U) },
|
||||||
|
{ 80U, DUTY_TO_TIM_VALUE(100U) }
|
||||||
|
};
|
||||||
|
|
||||||
FanControl::FanControl(void)
|
FanControl::FanControl(void)
|
||||||
{
|
{
|
||||||
/* TIM3 PWM-Output
|
/* TIM3 PWM-Output
|
||||||
@ -105,7 +115,8 @@ namespace ElektronischeLast
|
|||||||
LL_TIM_EnableCounter(TIM3);
|
LL_TIM_EnableCounter(TIM3);
|
||||||
LL_TIM_EnableCounter(TIM14);
|
LL_TIM_EnableCounter(TIM14);
|
||||||
|
|
||||||
this->compare_value = 0UL;
|
this->last_compare = 0UL;
|
||||||
|
this->last_temp = 0UL;
|
||||||
|
|
||||||
NVIC_SetPriority(TIM14_IRQn, 0);
|
NVIC_SetPriority(TIM14_IRQn, 0);
|
||||||
NVIC_EnableIRQ(TIM14_IRQn);
|
NVIC_EnableIRQ(TIM14_IRQn);
|
||||||
@ -113,8 +124,38 @@ namespace ElektronischeLast
|
|||||||
|
|
||||||
void FanControl::run(std::uint32_t temp)
|
void FanControl::run(std::uint32_t temp)
|
||||||
{
|
{
|
||||||
this->compare_value = duty;
|
if(duty != 0U)
|
||||||
LL_TIM_OC_SetCompareCH1(TIM3, this->compare_value);
|
{
|
||||||
|
LL_TIM_OC_SetCompareCH1(TIM3, duty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(this->last_temp != temp)
|
||||||
|
{
|
||||||
|
std::uint16_t cv = this->get_compare_value(temp);
|
||||||
|
if(this->last_compare != cv)
|
||||||
|
{
|
||||||
|
cv = (this->last_compare + cv) / 2U;
|
||||||
|
LL_TIM_OC_SetCompareCH1(TIM3, cv);
|
||||||
|
this->last_compare = cv;
|
||||||
|
}
|
||||||
|
this->last_temp = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint16_t FanControl::get_compare_value(std::uint16_t temp)
|
||||||
|
{
|
||||||
|
std::uint16_t cv = TIMER_RELOAD_VALUE;
|
||||||
|
for(std::uint32_t i = 0UL; i < sizeof(stuetzpunkte) / sizeof(stuetzpunkte[0]); i++)
|
||||||
|
{
|
||||||
|
if(temp < stuetzpunkte[i][0])
|
||||||
|
{
|
||||||
|
cv = stuetzpunkte[i][1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +22,9 @@ namespace ElektronischeLast
|
|||||||
void run(std::uint32_t temp);
|
void run(std::uint32_t temp);
|
||||||
std::uint32_t get_speed(void);
|
std::uint32_t get_speed(void);
|
||||||
private:
|
private:
|
||||||
std::uint32_t compare_value;
|
std::uint32_t last_compare;
|
||||||
|
std::uint32_t last_temp;
|
||||||
|
std::uint16_t get_compare_value(std::uint16_t temp);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user