diff --git a/src/owntech.ini b/src/owntech.ini index 2ccf8005e8e6ac6e696a3c4beba28373ce64eb3d..be363f0523c68215a358ec7e485e1391ab664be7 100644 --- a/src/owntech.ini +++ b/src/owntech.ini @@ -10,6 +10,7 @@ [env] lib_deps= -# quick_start=https://gitlab.laas.fr/owntech/power-api/opalib-quick-start.git -# pid_voltage=https://gitlab.laas.fr/owntech/power-api/opalib-pid.git -# pid_current=https://gitlab.laas.fr/owntech/power-api/opalib-pid-current-mode.git + peripherals = https://gitlab.laas.fr/owntech/power-api/opalib-peripherals.git + control_pid = https://gitlab.laas.fr/owntech/power-api/opalib-control-pid.git + power_conversion = https://gitlab.laas.fr/owntech/power-api/opalib-power-conversion.git + data_conversion = https://gitlab.laas.fr/owntech/power-api/opalib-data-conversion.git diff --git a/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/hrtim.h b/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/hrtim.h index 49a8317326e5010130f406321458d2a0817fafbf..73d144ad137c70e7a535ed254651e7d54b453d5f 100644 --- a/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/hrtim.h +++ b/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/hrtim.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 LAAS-CNRS + * Copyright (c) 2021-2022 LAAS-CNRS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -19,6 +19,7 @@ /** * @author Clément Foucher <clement.foucher@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ #ifndef HRTIM_H_ @@ -78,7 +79,12 @@ void hrtim_pwm_set(hrtim_t dev, hrtim_tu_t tu, uint16_t value, uint16_t shift); void hrtim_init_current(); -void hrtim_init_voltage(); +void hrtim_init_voltage_buck(); +void hrtim_init_voltage_boost(); +void hrtim_init_voltage_leg1_buck_leg2_boost(); +void hrtim_init_voltage_leg1_boost_leg2_buck(); + + #ifdef __cplusplus } diff --git a/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/leg.h b/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/leg.h index 05b19b9631da588beaf84f9981a797eea4c9e6db..efa480e7f0c4b790e0c7862f28bc4c6911bfaa5b 100644 --- a/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/leg.h +++ b/zephyr/modules/owntech_hrtim_driver/zephyr/public_include/leg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 LAAS-CNRS + * Copyright (c) 2020-2022 LAAS-CNRS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -23,12 +23,12 @@ * @ingroup owntech_modules * @brief OwnTech PWM management layer by inverter leg * - * @{ * @file * @brief PWM management layer by inverter leg interface definitions - * @date 2020 + * @date 2022 * @author Hugues Larrive <hugues.larrive@laas.fr> * @author Antoine Boche <antoine.boche@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ #ifndef LEG_H_ @@ -61,11 +61,12 @@ typedef struct { /** * @brief Initializes all the configured devices with the chosen switch convention * - * @param[in] upper_switch_convention Choice of the switch convention + * @param[in] leg1_upper_switch_convention Choice of the switch convention for leg 1 + * @param[in] leg2_upper_switch_convention Choice of the switch convention for leg 2 * * @return HRTIM period */ -uint16_t leg_init(bool upper_switch_convention); +uint16_t leg_init(bool leg1_upper_switch_convention, bool leg2_upper_switch_convention); /** * @brief Set the PWM pulse width for a given leg device @@ -83,6 +84,13 @@ void leg_set(hrtim_tu_t timing_unit, uint16_t pulse_width, uint16_t phase_shift) */ void leg_stop(hrtim_tu_t timing_unit); +/** + * @brief Start the leg (its 2 outputs goes low) + * + * @param[in] timing_unit timing_unit from TIMA to TIMF + */ +void leg_start(hrtim_tu_t timing_unit); + /** * @brief period getter * diff --git a/zephyr/modules/owntech_hrtim_driver/zephyr/src/hrtim_common.c b/zephyr/modules/owntech_hrtim_driver/zephyr/src/hrtim_common.c index b7561bf79a4911e7638c1a0f0973facc1213eba3..f89a66465e5914d504c9106aae20b7594f2f03d6 100644 --- a/zephyr/modules/owntech_hrtim_driver/zephyr/src/hrtim_common.c +++ b/zephyr/modules/owntech_hrtim_driver/zephyr/src/hrtim_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 LAAS-CNRS + * Copyright (c) 2021-2022 LAAS-CNRS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -19,6 +19,7 @@ /** * @author Clément Foucher <clement.foucher@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ #include "voltage_mode/hrtim_voltage_mode.h" @@ -33,9 +34,30 @@ void hrtim_init_current() hrtim_cm_enable(); } -void hrtim_init_voltage() +void hrtim_init_voltage_buck() { - leg_init(true); + leg_init(true,true); + hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3); + hrtim_cmp_set(0, TIMA, CMP3xR, 1); +} + +void hrtim_init_voltage_boost() +{ + leg_init(false,false); + hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3); + hrtim_cmp_set(0, TIMA, CMP3xR, 1); +} + +void hrtim_init_voltage_leg1_buck_leg2_boost() +{ + leg_init(true,false); + hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3); + hrtim_cmp_set(0, TIMA, CMP3xR, 1); +} + +void hrtim_init_voltage_leg1_boost_leg2_buck() +{ + leg_init(false,true); hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3); hrtim_cmp_set(0, TIMA, CMP3xR, 1); } diff --git a/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.c b/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.c index 7c1fddcf3232cdc8b734506e9c55050846ea4d33..e59163ce4b329d5127b54bab50068b137ed6d1bf 100644 --- a/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.c +++ b/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 LAAS-CNRS + * Copyright (c) 2020-2022 LAAS-CNRS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -27,6 +27,7 @@ * @author Hugues Larrive <hugues.larrive@laas.fr> * @author Clément Foucher <clement.foucher@laas.fr> * @author Antoine Boche <antoine.boche@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ #include <stm32_ll_rcc.h> @@ -130,7 +131,7 @@ static inline uint32_t _period_ckpsc(hrtim_t hrtim, uint32_t freq, return frequency; } -uint16_t hrtim_init(hrtim_t hrtim, uint32_t *freq, uint16_t dt, uint8_t upper_switch_convention) +uint16_t hrtim_init(hrtim_t hrtim, uint32_t *freq, uint16_t dt, uint8_t leg1_upper_switch_convention, uint8_t leg2_upper_switch_convention) { /* Master timer initialization */ uint16_t period = hrtim_init_master(hrtim, freq); @@ -147,7 +148,8 @@ uint16_t hrtim_init(hrtim_t hrtim, uint32_t *freq, uint16_t dt, uint8_t upper_sw hrtim_cnt_en(hrtim, (1 << (HRTIM_MCR_TACEN_Pos + tu))); /* Setup outputs */ - hrtim_cmpl_pwm_out(hrtim, tu, upper_switch_convention); + hrtim_cmpl_pwm_out1(hrtim, tu, leg1_upper_switch_convention); + hrtim_cmpl_pwm_out2(hrtim, tu, leg2_upper_switch_convention); /* Reset on master timer period event */ hrtim_rst_evt_en(hrtim, tu, RST_MSTPER); @@ -366,6 +368,40 @@ void hrtim_cmpl_pwm_out(hrtim_t hrtim, hrtim_tu_t tu, bool upper_switch_conventi } } +void hrtim_cmpl_pwm_out1(hrtim_t hrtim, hrtim_tu_t tu, bool leg1_upper_switch_convention) +{ + // Configuration for the upper switch convention + if (leg1_upper_switch_convention == true) + { + dev(hrtim)->sTimerxRegs[tu].SETx1R = PER; + dev(hrtim)->sTimerxRegs[tu].RSTx1R = CMP1; + } + + // Configuration for the lower switch convention + else if (leg1_upper_switch_convention == false) + { + dev(hrtim)->sTimerxRegs[tu].SETx1R = CMP1; + dev(hrtim)->sTimerxRegs[tu].RSTx1R = PER; + } +} + +void hrtim_cmpl_pwm_out2(hrtim_t hrtim, hrtim_tu_t tu, bool leg2_upper_switch_convention) +{ + // Configuration for the upper switch convention + if (leg2_upper_switch_convention == true) + { + dev(hrtim)->sTimerxRegs[tu].SETx2R = CMP1; + dev(hrtim)->sTimerxRegs[tu].RSTx2R = PER; + } + + // Configuration for the lower switch convention + else if (leg2_upper_switch_convention == false) + { + dev(hrtim)->sTimerxRegs[tu].SETx2R = PER; + dev(hrtim)->sTimerxRegs[tu].RSTx2R = CMP1; + } +} + void hrtim_period_set(hrtim_t hrtim, hrtim_tu_t tu, uint16_t value) { if (tu == MSTR) { diff --git a/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.h b/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.h index d45e92a0ceb85842e0c3cb05edfc75ddb2b48089..65fbbe73b329e5ca500dc5d39e70874462742653 100644 --- a/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.h +++ b/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/hrtim_voltage_mode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 LAAS-CNRS + * Copyright (c) 2020-2022 LAAS-CNRS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -28,6 +28,7 @@ * @author Hugues Larrive <hugues.larrive@laas.fr> * @author Clément Foucher <clement.foucher@laas.fr> * @author Antoine Boche <antoine.boche@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ #ifndef HRTIM_VOLTAGE_MODE_H_ @@ -331,16 +332,16 @@ typedef enum { * @brief Initialize an HRTIM device and all these timing units for * complementary pwm outputs with a dead time. * - * @param[in] dev HRTIM device to initialize - * @param[inout] freq HRTIM frequency in Hz - * @param[in] dt Desired dead time in ns - * @param[in] switch_convention Choice of the switch convention + * @param[in] dev HRTIM device to initialize + * @param[inout] freq HRTIM frequency in Hz + * @param[in] dt Desired dead time in ns + * @param[in] leg1_upper_switch_convention Choice of the switch convention for leg 1 + * @param[in] leg2_upper_switch_convention Choice of the switch convention for leg 2 * * @return actual HRTIM resolution on success * @return 0 on error */ -uint16_t hrtim_init(hrtim_t dev, uint32_t *freq, uint16_t dt, uint8_t switch_convention); - +uint16_t hrtim_init(hrtim_t dev, uint32_t *freq, uint16_t dt, uint8_t leg1_upper_switch_convention, uint8_t leg2_upper_switch_convention); /** * @brief Initialize an HRTIM device master timer * diff --git a/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/owntech_leg_driver.cpp b/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/owntech_leg_driver.cpp index e5e18d2c3e4a9b229c18aaa79a9d7d9f92eff131..0650a00a8738ddfa999d1af44b180e6286f35345 100644 --- a/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/owntech_leg_driver.cpp +++ b/zephyr/modules/owntech_hrtim_driver/zephyr/src/voltage_mode/owntech_leg_driver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 LAAS-CNRS + * Copyright (c) 2020-2022 LAAS-CNRS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -21,9 +21,10 @@ /** * @file * @brief PWM management layer by inverter leg - * @date 2020 + * @date 2022 * @author Hugues Larrive <hugues.larrive@laas.fr> * @author Antoine Boche <antoine.boche@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ #include "leg.h" @@ -41,7 +42,7 @@ static leg_conf_t leg_conf[6]; /* a copy of leg_config with index * on the power converter to a frequency of 200kHz * Must be initialized in first position */ -uint16_t leg_init(bool upper_switch_convention) +uint16_t leg_init(bool leg1_upper_switch_convention, bool leg2_upper_switch_convention) { uint32_t freq = LEG_FREQ; @@ -51,7 +52,7 @@ uint16_t leg_init(bool upper_switch_convention) leg_conf[leg_config[i].timing_unit] = leg_config[i]; } - period = hrtim_init(0, &freq, LEG_DEFAULT_DT,upper_switch_convention); + period = hrtim_init(0, &freq, LEG_DEFAULT_DT,leg1_upper_switch_convention,leg2_upper_switch_convention); dead_time = (period*LEG_DEFAULT_DT*leg_get_freq())/1000000; min_pw = (period * 0.1) + dead_time; max_pw = (period * 0.9) + dead_time; @@ -83,10 +84,14 @@ void leg_set(hrtim_tu_t timing_unit, uint16_t pulse_width, uint16_t phase_shift) void leg_stop(hrtim_tu_t timing_unit) { - hrtim_pwm_set( leg_conf[timing_unit].hrtim, - leg_conf[timing_unit].timing_unit, - 0, - 0); + hrtim_out_dis(leg_conf[timing_unit].hrtim, leg_conf[timing_unit].timing_unit, OUT1); + hrtim_out_dis(leg_conf[timing_unit].hrtim, leg_conf[timing_unit].timing_unit, OUT2); +} + +void leg_start(hrtim_tu_t timing_unit) +{ + hrtim_out_en(leg_conf[timing_unit].hrtim, leg_conf[timing_unit].timing_unit, OUT1); + hrtim_out_en(leg_conf[timing_unit].hrtim, leg_conf[timing_unit].timing_unit, OUT2); } uint16_t leg_period(void)