From a46760b34f86762c11fc515b39b742e8c4b5d3e8 Mon Sep 17 00:00:00 2001 From: Rene Hopf Date: Mon, 12 Jun 2017 19:04:36 +0200 Subject: [PATCH] hvdc --- stm32f303/Makefile | 1 + stm32f303/src/comps/hvdc.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 stm32f303/src/comps/hvdc.c diff --git a/stm32f303/Makefile b/stm32f303/Makefile index cc9c8ea8..35e7937a 100644 --- a/stm32f303/Makefile +++ b/stm32f303/Makefile @@ -29,6 +29,7 @@ SOURCES += stm32f303/src/version.c SOURCES += stm32f303/src/hal_tbl.c SOURCES += stm32f303/src/comps/hv.c +SOURCES += stm32f303/src/comps/hvdc.c SOURCES += stm32f303/src/comps/io.c SOURCES += stm32f303/src/comps/ls.c SOURCES += stm32f303/src/comps/enc.c diff --git a/stm32f303/src/comps/hvdc.c b/stm32f303/src/comps/hvdc.c new file mode 100644 index 00000000..bbc911fd --- /dev/null +++ b/stm32f303/src/comps/hvdc.c @@ -0,0 +1,38 @@ +#include "commands.h" +#include "hal.h" +#include "math.h" +#include "defines.h" +#include "angle.h" +#include "tim.h" +#include "f3hw.h" + +HAL_COMP(hvdc); + +//dc voltage input +HAL_PIN(uq); +//dclink input +HAL_PIN(udc); + + +static void rt_func(float period, volatile void * ctx_ptr, volatile hal_pin_inst_t * pin_ptr){ + // struct hv_ctx_t * ctx = (struct hv_ctx_t *)ctx_ptr; + struct hvdc_pin_ctx_t * pins = (struct hvdc_pin_ctx_t *)pin_ptr; + float udc = MAX(PIN(udc), 1.0); + int32_t dcpwm = PIN(uq)/2.0/udc * 4800; + PWM_U = CLAMP(2400 + dcpwm , 50, 4750); + PWM_V = CLAMP(2400 - dcpwm , 50, 4750); +} + +hal_comp_t hvdc_comp_struct = { + .name = "hvdc", + .nrt = 0, + .rt = rt_func, + .frt = 0, + .nrt_init = 0, + .rt_start = 0, + .frt_start = 0, + .rt_stop = 0, + .frt_stop = 0, + .ctx_size = 0, + .pin_count = sizeof(struct hvdc_pin_ctx_t) / sizeof(struct hal_pin_inst_t), +};