diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt b/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt index 6565eb7ec7f21aac7875fe4b496e14355be0e931..e9dd0bee4b80c3224a6b6f85b42c3c605362e329 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 ae5ec6b22bc2adce7ab4833c485bfa636aa09cb3..148061448d0710140f5ef3362331c79d837781e7 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 7bf85ba8773dfafefaf42de4c3c298d2699e8a75..1beb3187c1cd04d4af77474572494a27b61e05d0 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 54377d64014ab84d01c9fe6bf733d338e93c6b1a..f7006e037cee78bd4517606fbf2f11330c09a75f 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 81e056114156d4e7918a7e4e8846dffa33a40821..42d50e79954ebfa2cdaa4b1de58506699d4b5af7 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 f8e0b08a63f59d296f51429208e24a545ed80c34..49a68fa70fbaf5dc6bd4f55217c0efffd40be238 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 0000000000000000000000000000000000000000..bd13668fbb4c2bdb4052963350caf392116b09b6 --- /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 0000000000000000000000000000000000000000..609919e7bd776029f72b818c515d2be13edd77f4 --- /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_