CLI hinzugefügt und Kommando um soll-strom zu ändern

This commit is contained in:
2024-06-09 17:57:55 +02:00
parent 70d500bc67
commit 52a0a9295c
8 changed files with 160 additions and 332 deletions

View File

@@ -7,6 +7,7 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cinttypes>
#include <stm32g0xx.h>
#include "STM32G071KBT6.hpp"
@@ -16,9 +17,17 @@
#include "serial.hpp"
#include "PID.h"
#include "FanControl.hpp"
#include "CLI.h"
using namespace ElektronischeLast;
uint16_t set_solltrom (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount);
static CLI_Command_t commands[] =
{
{ "isoll", "Zielstrom für Last", set_solltrom }
};
static std::uint32_t i_soll = 0U;
static PIDController pid =
{
@@ -35,9 +44,9 @@ static uint32_t dac_value;
int main (void)
{
__enable_irq();
serial_init();
CLI_Init(commands, sizeof(commands)/sizeof(commands[0]));
LED led = LED(500U);
iDAC dac = iDAC();
iADC adc = iADC();
@@ -60,6 +69,26 @@ int main (void)
dac.write(iDAC::CHANNEL_1, dac_value);
fan.run(adc.get_temperature());
serial_cyclic();
}
}
}
/**
* @brief Callback Function for Command Line
* @param [in] pfvOutFunction Function to Print Data to Output
* @param [in] acCommands array with char pointers to the different arguments
* @param [in] u16ArgCount number of Arguments
* @return 0 = don't recall, 1 = call again
*/
uint16_t set_solltrom (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount)
{
char buf[40];
uint32_t in = strtoul(acCommands[0], NULL, 10);
uint32_t cur = i_soll;
snprintf(buf, sizeof(buf), "Aktueller Soll-Strom: %" PRIu32 ", Neu: %" PRIu32, cur, in);
pfvOutFunction(buf);
i_soll = in;
return 0;
}

View File

@@ -10,10 +10,23 @@
#include <stm32g0xx_ll_tim.h>
#include "FanControl.hpp"
static std::uint32_t fan_speed;
extern "C" void TIM14_IRQHandler(void)
{
LL_TIM_ClearFlag_UPDATE(TIM14);
fan_speed = LL_TIM_GetCounter(TIM2) / 2UL;
LL_TIM_SetCounter(TIM2, 0UL);
}
namespace ElektronischeLast
{
FanControl::FanControl(void)
{
/* TIM3 PWM-Output
* 25kHz (Vorgabe Intel). Geschwindigkeit wird über Tastverhältnis geregelt.
*/
LL_TIM_InitTypeDef TIM_InitStruct = {
.Prescaler = 0UL,
.CounterMode = LL_TIM_COUNTERMODE_UP,
@@ -36,9 +49,33 @@ namespace ElektronischeLast
LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM3);
/**TIM3 GPIO Configuration
PC6 ------> TIM3_CH1
*/
/* TIM2 Input Capture zur Messung der Geschwindigkeit.
*/
TIM_InitStruct.Prescaler = 0;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 0;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM2, &TIM_InitStruct);
LL_TIM_DisableARRPreload(TIM2);
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM2);
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_DIRECTTI);
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1);
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1);
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_RISING);
/* TIM14 1s ISR */
TIM_InitStruct.Prescaler = 15999;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 999;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV4;
LL_TIM_Init(TIM14, &TIM_InitStruct);
LL_TIM_DisableARRPreload(TIM14);
/* TIM3 GPIO Configuration
* PC6 ------> TIM3_CH1
*/
LL_GPIO_InitTypeDef GPIO_InitStruct = {
.Pin = LL_GPIO_PIN_6,
.Mode = LL_GPIO_MODE_ALTERNATE,
@@ -48,10 +85,20 @@ namespace ElektronischeLast
.Alternate = LL_GPIO_AF_1,
};
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*T IM2 GPIO Configuration
* PA15 ------> TIM2_CH1
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_2;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
LL_TIM_EnableCounter(TIM3);
this->compare_value = 0UL;
NVIC_SetPriority(TIM14_IRQn, 0);
NVIC_EnableIRQ(TIM14_IRQn);
}
void FanControl::run(std::uint32_t temp)

View File

@@ -170,7 +170,7 @@ extern "C" void TIM2_IRQHandler(void){} /* TIM2
extern "C" void TIM3_IRQHandler(void){} /* TIM3 */
extern "C" void TIM6_DAC_LPTIM1_IRQHandler(void){} /* TIM6, DAC and LPTIM1 */
extern "C" void TIM7_LPTIM2_IRQHandler(void){} /* TIM7 and LPTIM2 */
extern "C" void TIM14_IRQHandler(void){} /* TIM14 */
extern "C" void TIM15_IRQHandler(void){} /* TIM15 */
extern "C" void TIM16_IRQHandler(void){} /* TIM16 */
extern "C" void TIM17_IRQHandler(void){} /* TIM17 */
@@ -247,8 +247,10 @@ extern "C" void SystemInit(void)
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPUART1);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DAC1);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM14);
}

View File

@@ -6,10 +6,14 @@
*/
#include <cstdint>
#include <cstdio>
#include <sys/stat.h>
#include <CLI.h>
#include <stm32g0xx_ll_gpio.h>
#include "stm32g0xx_ll_lpuart.h"
static char new_char = '\0';
extern "C" int _write(int file, char *ptr, int len)
{
(void)file;
@@ -73,7 +77,7 @@ extern "C" void USART3_4_LPUART1_IRQHandler(void)
{
if(LL_LPUART_IsActiveFlag_RXNE_RXFNE(LPUART1))
{
new_char = LL_LPUART_ReceiveData8(LPUART1);
}
}
@@ -114,6 +118,7 @@ extern "C" void serial_init(void)
LL_LPUART_EnableFIFO(LPUART1);
LL_LPUART_Enable(LPUART1);
LL_LPUART_EnableIT_RXNE_RXFNE(LPUART1);
/* LPUART1 interrupt Init */
NVIC_SetPriority(USART3_4_LPUART1_IRQn, 2);
@@ -123,4 +128,13 @@ extern "C" void serial_init(void)
while((!(LL_LPUART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_LPUART_IsActiveFlag_REACK(LPUART1))))
{
}
setbuf(stdout, NULL);
}
extern "C" void serial_cyclic(void)
{
char c = new_char;
new_char = '\0';
CLI_CylicFunction(c);
}

View File

@@ -9,5 +9,6 @@
#define SERIAL_HPP_
extern "C" void serial_init(void);
extern "C" void serial_cyclic(void);
#endif /* SERIAL_HPP_ */