From ed7c45df1075d1c971faad3cf0baed6a17a92378 Mon Sep 17 00:00:00 2001 From: Luiz Fernando Lavado Villa <lflavado@laas.fr> Date: Tue, 4 Oct 2022 13:33:20 +0000 Subject: [PATCH] Updates the hardware configuration to allow using the gpio api to drive the... Updates the hardware configuration to allow using the gpio api to drive the power drivers for high side mosfets. On the gpio side, the user now seamlessly activates the high side when activating the legs. On the adc side, the user can now set the point of measurement with a float from the main.cpp for better control of the measurement moment. --- .../zephyr/CMakeLists.txt | 1 + .../zephyr/Kconfig | 1 + .../public_api/HardwareConfiguration.cpp | 11 +- .../zephyr/public_api/HardwareConfiguration.h | 2 +- .../zephyr/src/hrtim_configuration.cpp | 6 +- .../zephyr/src/hrtim_configuration.h | 2 +- .../zephyr/src/power_driver_configuration.cpp | 102 ++++++++++++++++++ .../zephyr/src/power_driver_configuration.h | 39 +++++++ 8 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.cpp create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.h diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt b/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt index 6565eb7..e9dd0be 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt @@ -15,6 +15,7 @@ if(CONFIG_OWNTECH_HARDWARE_CONFIGURATION) src/hrtim_configuration.cpp src/uart_configuration.cpp src/adc_configuration.cpp + src/power_driver_configuration.cpp public_api/HardwareConfiguration.cpp ) endif() diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig b/zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig index ae5ec6b..1480614 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig @@ -6,3 +6,4 @@ config OWNTECH_HARDWARE_CONFIGURATION depends on OWNTECH_HRTIM_DRIVER depends on OWNTECH_NGND_DRIVER depends on OWNTECH_TIMER_DRIVER + depends on OWNTECH_GPIO_API diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp index 7bf85ba..1beb318 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp @@ -34,6 +34,7 @@ #include "../src/hrtim_configuration.h" #include "../src/uart_configuration.h" #include "../src/adc_configuration.h" +#include "../src/power_driver_configuration.h" // Current class header #include "HardwareConfiguration.h" @@ -290,45 +291,53 @@ void HardwareConfiguration::setLeg2PhaseShiftCenterAligned(float32_t phase_shift void HardwareConfiguration::setInterleavedOn() { + power_driver_interleaved_on(); hrtim_start_interleaved(); } void HardwareConfiguration::setFullBridgeBuckOn() { + power_driver_interleaved_on(); hrtim_start_full_bridge_buck(); } void HardwareConfiguration::setLeg1On() { + power_driver_leg1_on(); hrtim_start_leg1(); } void HardwareConfiguration::setLeg2On() { + power_driver_leg2_on(); hrtim_start_leg2(); } void HardwareConfiguration::setInterleavedOff() { + power_driver_interleaved_off(); hrtim_stop_interleaved(); } void HardwareConfiguration::setFullBridgeBuckOff() { + power_driver_interleaved_off(); hrtim_stop_full_bridge_buck(); } void HardwareConfiguration::setLeg1Off() { + power_driver_leg1_off(); hrtim_stop_leg1(); } void HardwareConfiguration::setLeg2Off() { + power_driver_leg2_off(); hrtim_stop_leg2(); } -void HardwareConfiguration::setHrtimAdcTrigInterleaved(uint16_t new_trig) +void HardwareConfiguration::setHrtimAdcTrigInterleaved(float32_t new_trig) { set_adc_trig_interleaved(new_trig); } diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h index 54377d6..f7006e0 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h @@ -131,7 +131,7 @@ public: static void setLeg1Off(); static void setLeg2Off(); - static void setHrtimAdcTrigInterleaved(uint16_t new_trig); + static void setHrtimAdcTrigInterleaved(float32_t new_trig); // Extra UART static void extraUartInit(); diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.cpp index 81e0561..42d50e7 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.cpp @@ -247,7 +247,6 @@ void hrtim_interleaved_pwm_update(float32_t pwm_duty_cycle) leg_set(leg2_tu, pwm_pulse_width, pwm_phase_shift); } - hrtim_update_adc_trig_interleaved( (pwm_pulse_width>>1) + (pwm_pulse_width>>2), leg1_tu, leg2_tu); //works only on left aligned as center aligned does not use the same comparators } /** @@ -497,9 +496,10 @@ void hrtim_start_leg2() leg_start(leg2_tu); } -void set_adc_trig_interleaved(uint16_t new_trig) +void set_adc_trig_interleaved(float32_t new_trig) { - hrtim_update_adc_trig_interleaved(new_trig, leg1_tu, leg2_tu); + uint16_t new_trig_int = new_trig * pwm_period; + hrtim_update_adc_trig_interleaved(new_trig_int, leg1_tu, leg2_tu); } diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.h index f8e0b08..49a68fa 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.h +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.h @@ -209,7 +209,7 @@ void hrtim_start_leg2(); * * @param[in] new_trig defines the triggering moment */ -void set_adc_trig_interleaved(uint16_t new_trig); +void set_adc_trig_interleaved(float32_t new_trig); /** * @brief This function sets the dead time of the leg 1 diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.cpp new file mode 100644 index 0000000..bd13668 --- /dev/null +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 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 + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: LGLPV2.1 + */ + +/** + * @date 2022 + * @author Clément Foucher <clement.foucher@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> + */ + + +// Zephyr +#include "zephyr.h" +#include "GpioApi.h" + +static bool init = false; + + +void power_driver_config_init() +{ + gpio.configurePin(PC12,OUTPUT); //configures the pin of leg 1 mosfet high + gpio.configurePin(PC13,OUTPUT); //configures the pin of leg 2 mosfet high + init = true; +} + +void power_driver_leg1_on() +{ + if (init == false) + { + power_driver_config_init(); //calls the config automatically during the first execution + } + + gpio.setPin(PC12); +} + +void power_driver_leg2_on() +{ + if (init == false) + { + power_driver_config_init(); //calls the config automatically during the first execution + } + + gpio.setPin(PC13); +} + +void power_driver_leg1_off() +{ + if (init == false) + { + power_driver_config_init(); //calls the config automatically during the first execution + } + + gpio.resetPin(PC12); +} + +void power_driver_leg2_off() +{ + if (init == false) + { + power_driver_config_init(); //calls the config automatically during the first execution + } + + gpio.resetPin(PC12); +} + +void power_driver_interleaved_on() +{ + if (init == false) + { + power_driver_config_init(); //calls the config automatically during the first execution + } + + gpio.setPin(PC12); + gpio.setPin(PC13); +} + +void power_driver_interleaved_off() +{ + if (init == false) + { + power_driver_config_init(); //calls the config automatically during the first execution + } + + gpio.resetPin(PC12); + gpio.resetPin(PC13); +} + diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.h new file mode 100644 index 0000000..609919e --- /dev/null +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/power_driver_configuration.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: LGLPV2.1 + */ + +/** + * @date 2022 + * @author Clément Foucher <clement.foucher@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> + */ + + +#ifndef POWER_DRIVER_CONFIGURATION_H_ +#define POWER_DRIVER_CONFIGURATION_H_ + + +void power_driver_leg1_on(); +void power_driver_leg1_off(); +void power_driver_leg2_on(); +void power_driver_leg2_off(); +void power_driver_interleaved_on(); +void power_driver_interleaved_off(); + + +#endif // POWER_DRIVER_CONFIGURATION_H_ -- GitLab