66 lines
1.2 KiB
C++
66 lines
1.2 KiB
C++
/*
|
|
* ElektronischeLast.cpp
|
|
*
|
|
* Created on: Jun 23, 2023
|
|
* Author: Carst
|
|
*/
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cinttypes>
|
|
#include <stm32g0xx.h>
|
|
#include "STM32G071KBT6.hpp"
|
|
#include "LED.hpp"
|
|
#include "DAC.hpp"
|
|
#include "ADC.hpp"
|
|
#include "serial.hpp"
|
|
#include "PID.h"
|
|
#include "FanControl.hpp"
|
|
|
|
using namespace ElektronischeLast;
|
|
|
|
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();
|
|
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());
|
|
}
|
|
}
|
|
}
|