From b13ee19743a7bc7d5829b841fa4e654e16091d55 Mon Sep 17 00:00:00 2001 From: Carsten Keller Date: Sun, 9 Jun 2024 17:57:57 +0200 Subject: [PATCH] =?UTF-8?q?Konsolenbefehl=20um=20L=C3=BCfter=20anzusteuern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/ElektronischeLast.cpp | 21 ++++++++++++++++++++- Source/FanControl.cpp | 15 ++++++++++++--- Source/FanControl.hpp | 2 ++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Source/ElektronischeLast.cpp b/Source/ElektronischeLast.cpp index e3c5ba7..73b5ee6 100644 --- a/Source/ElektronischeLast.cpp +++ b/Source/ElektronischeLast.cpp @@ -22,12 +22,14 @@ using namespace ElektronischeLast; uint16_t set_solltrom (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount); +uint16_t set_dutyCyle (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount); uint16_t ist_werte(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount); static CLI_Command_t commands[] = { { "isoll", "Zielstrom für Last", set_solltrom }, - { "ist", "Zeige Istwerte an [-r für wiederholende Anzeige]", ist_werte } + { "ist", "Zeige Istwerte an [-r für wiederholende Anzeige]", ist_werte }, + { "fan", "Setze Tastverhältnis für Lüfter", set_dutyCyle }, }; static std::uint32_t i_soll = 0U; @@ -125,3 +127,20 @@ uint16_t ist_werte(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t return recall; } + +uint16_t set_dutyCyle (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount) +{ + char buf[40]; + if(u16ArgCount == 1U) + { + uint32_t in = strtoul(acCommands[0], NULL, 10); + snprintf(buf, sizeof(buf), "\r\nNeu: %" PRIu32, in); + FanControl_SetDuty(in); + } + else + { + snprintf(buf, sizeof(buf), "\r\nMissing Argument Dutycycle!"); + } + pfvOutFunction(buf); + return 0; +} diff --git a/Source/FanControl.cpp b/Source/FanControl.cpp index b0d202a..3596d9b 100644 --- a/Source/FanControl.cpp +++ b/Source/FanControl.cpp @@ -10,8 +10,10 @@ #include #include "FanControl.hpp" -static std::uint32_t fan_speed; +#define TIMER_RELOAD_VALUE 2559UL +static std::uint32_t fan_speed; +static std::uint32_t duty; extern "C" void TIM14_IRQHandler(void) { LL_TIM_ClearFlag_UPDATE(TIM14); @@ -19,7 +21,10 @@ extern "C" void TIM14_IRQHandler(void) fan_speed = LL_TIM_GetCounter(TIM2) / 2UL; LL_TIM_SetCounter(TIM2, 0UL); } - +extern "C" void FanControl_SetDuty(uint32_t d) +{ + duty = TIMER_RELOAD_VALUE / 100UL * d; +} namespace ElektronischeLast { FanControl::FanControl(void) @@ -30,7 +35,7 @@ namespace ElektronischeLast LL_TIM_InitTypeDef TIM_InitStruct = { .Prescaler = 0UL, .CounterMode = LL_TIM_COUNTERMODE_UP, - .Autoreload = 2559UL, + .Autoreload = TIMER_RELOAD_VALUE, .ClockDivision = LL_TIM_CLOCKDIVISION_DIV1, }; LL_TIM_Init(TIM3, &TIM_InitStruct); @@ -72,6 +77,7 @@ namespace ElektronischeLast TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV4; LL_TIM_Init(TIM14, &TIM_InitStruct); LL_TIM_DisableARRPreload(TIM14); + LL_TIM_EnableIT_UPDATE(TIM14); /* TIM3 GPIO Configuration * PC6 ------> TIM3_CH1 @@ -93,7 +99,9 @@ namespace ElektronischeLast GPIO_InitStruct.Alternate = LL_GPIO_AF_2; LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + LL_TIM_EnableCounter(TIM2); LL_TIM_EnableCounter(TIM3); + LL_TIM_EnableCounter(TIM14); this->compare_value = 0UL; @@ -103,6 +111,7 @@ namespace ElektronischeLast void FanControl::run(std::uint32_t temp) { + this->compare_value = duty; LL_TIM_OC_SetCompareCH1(TIM3, this->compare_value); } } diff --git a/Source/FanControl.hpp b/Source/FanControl.hpp index af0e7cd..7a21e16 100644 --- a/Source/FanControl.hpp +++ b/Source/FanControl.hpp @@ -10,6 +10,8 @@ #include +extern "C" void FanControl_SetDuty(uint32_t d); + namespace ElektronischeLast { class FanControl