PID-Controller für Stromregelung
This commit is contained in:
parent
af2a74390a
commit
17cdb8ca93
@ -7,29 +7,71 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cinttypes>
|
||||||
#include <stm32g0xx.h>
|
#include <stm32g0xx.h>
|
||||||
#include "STM32G071KBT6.hpp"
|
#include "STM32G071KBT6.hpp"
|
||||||
#include "LED.hpp"
|
#include "LED.hpp"
|
||||||
#include "DAC.hpp"
|
#include "DAC.hpp"
|
||||||
#include "ADC.hpp"
|
#include "ADC.hpp"
|
||||||
#include "serial.hpp"
|
#include "serial.hpp"
|
||||||
|
#include "PID.h"
|
||||||
|
|
||||||
using namespace ElektronischeLast;
|
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;
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
uint32_t current_min;
|
||||||
|
uint32_t current_max;
|
||||||
|
} current_spitze;
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
uint32_t voltage_min;
|
||||||
|
uint32_t voltage_max;
|
||||||
|
} voltage_spitze;
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
serial_init();
|
serial_init();
|
||||||
LED led = LED(500U);
|
LED led = LED(500U);
|
||||||
iDAC dac = iDAC();
|
iDAC dac = iDAC();
|
||||||
iADC adc = iADC();
|
iADC adc = iADC();
|
||||||
|
std::uint32_t last_tick = systick;
|
||||||
|
|
||||||
printf("\r\nElektronische Last\r\n");
|
printf("\r\nElektronische Last\r\n");
|
||||||
printf("- Initialisierung erfolgreich\r\n");
|
printf("- Initialisierung erfolgreich\r\n");
|
||||||
|
|
||||||
|
PIDController_Init(&pid);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
led.blink();
|
led.blink();
|
||||||
dac.write(iDAC::CHANNEL_1, adc.get_current());
|
|
||||||
|
if(last_tick != systick)
|
||||||
|
{
|
||||||
|
last_tick = systick;
|
||||||
|
uint32_t tmp = adc.get_current();
|
||||||
|
if(tmp > current_spitze.current_max) current_spitze.current_max = tmp;
|
||||||
|
if(tmp < current_spitze.current_min) current_spitze.current_min = tmp;
|
||||||
|
tmp = adc.get_voltage();
|
||||||
|
if(tmp > voltage_spitze.voltage_max) voltage_spitze.voltage_max = tmp;
|
||||||
|
if(tmp < voltage_spitze.voltage_min) voltage_spitze.voltage_min = tmp;
|
||||||
|
dac_value = (uint32_t)PIDController_Update(&pid, i_soll, adc.get_current());
|
||||||
|
dac.write(iDAC::CHANNEL_1, dac_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user