/* * ElektronischeLast.cpp * * Created on: Jun 23, 2023 * Author: Carst */ #include #include #include #include #include #include "STM32G071KBT6.hpp" #include "LED.hpp" #include "DAC.hpp" #include "ADC.hpp" #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 = { .Kp = 0.75f, .Ki = 10.0f, .Kd = 0.0f, .limMin = 0.0f, .limMax = 4095.0f, .limMinInt = 0.0f, .limMaxInt = 2048.0f, .T = 0.001f, }; 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(); FanControl fan = FanControl(); std::uint32_t last_tick = systick; printf("\r\nElektronische Last\r\n"); printf("- Initialisierung erfolgreich\r\n"); PIDController_Init(&pid); while(1) { led.blink(); if(last_tick != systick) { last_tick = systick; dac_value = (uint32_t)PIDController_Update(&pid, i_soll, adc.get_current()); 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; }