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 8cf63fce75cb2845aabe42abdd927df3bd80dd99..d322ec956649c7790c789d4e1f429d4899b5bd22 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp @@ -60,7 +60,7 @@ HardwareConfiguration hwConfig; */ void HardwareConfiguration::setBoardVersion(hardware_version_t hardware_version) { - if (hardware_version == v_1_1_2 || hardware_version == SPIN) + if (hardware_version == O2_v_1_1_2 || hardware_version == SPIN_v_0_9) { uart_lpuart1_swap_rx_tx(); } @@ -148,12 +148,14 @@ void HardwareConfiguration::initInterleavedBoostModeCenterAligned() void HardwareConfiguration::initFullBridgeBuckMode() { - hrtim_init_interleaved_buck_mode(); + hrtim_init_full_bridge_buck_mode(); } -void HardwareConfiguration::initFullBridgeBuckModeCenterAligned() +void HardwareConfiguration::initFullBridgeBuckModeCenterAligned(inverter_modulation_t inverter_modulation_type) { - hrtim_init_interleaved_buck_mode_center_aligned(); + bool bipolar_mode; + if (inverter_modulation_type == bipolar) bipolar_mode = true; else bipolar_mode = false; + hrtim_init_full_bridge_buck_mode_center_aligned(bipolar_mode); } void HardwareConfiguration::initFullBridgeBoostMode() @@ -166,20 +168,20 @@ void HardwareConfiguration::initFullBridgeBoostModeCenterAligned() hrtim_init_interleaved_boost_mode_center_aligned(); } -void HardwareConfiguration::initIndependentMode(hardware_conversion_t leg1_conversion_type, hardware_conversion_t leg2_conversion_type) +void HardwareConfiguration::initIndependentMode(leg_operation_t leg1_operation_type, leg_operation_t leg2_operation_type) { bool leg1_mode, leg2_mode; - if (leg1_conversion_type == buck) leg1_mode = true; else leg1_mode = false; - if (leg2_conversion_type == buck) leg2_mode = true; else leg2_mode = false; + if (leg1_operation_type == buck) leg1_mode = true; else leg1_mode = false; + if (leg2_operation_type == buck) leg2_mode = true; else leg2_mode = false; hrtim_init_independent_mode(leg1_mode, leg2_mode); } -void HardwareConfiguration::initIndependentModeCenterAligned(hardware_conversion_t leg1_conversion_type, hardware_conversion_t leg2_conversion_type) +void HardwareConfiguration::initIndependentModeCenterAligned(leg_operation_t leg1_operation_type, leg_operation_t leg2_operation_type) { bool leg1_mode, leg2_mode; - if (leg1_conversion_type == buck) leg1_mode = true; else leg1_mode = false; - if (leg2_conversion_type == buck) leg2_mode = true; else leg2_mode = false; + if (leg1_operation_type == buck) leg1_mode = true; else leg1_mode = false; + if (leg2_operation_type == buck) leg2_mode = true; else leg2_mode = false; hrtim_init_independent_mode_center_aligned(leg1_mode, leg2_mode); } @@ -189,9 +191,9 @@ void HardwareConfiguration::setInterleavedDutyCycle(float32_t duty_cycle) hrtim_interleaved_pwm_update(duty_cycle); } -void HardwareConfiguration::setFullBridgeDutyCycle(float32_t duty_cycle) +void HardwareConfiguration::setFullBridgeBuckDutyCycle(float32_t duty_cycle) { - hrtim_hbridge_pwm_update(duty_cycle); + hrtim_full_bridge_buck_pwm_update(duty_cycle); } void HardwareConfiguration::setLeg1DutyCycle(float32_t duty_cycle) @@ -229,9 +231,9 @@ void HardwareConfiguration::setInterleavedOn() hrtim_start_interleaved(); } -void HardwareConfiguration::setFullBridgeOn() +void HardwareConfiguration::setFullBridgeBuckOn() { - hrtim_start_interleaved(); + hrtim_start_full_bridge_buck(); } void HardwareConfiguration::setLeg1On() @@ -249,9 +251,9 @@ void HardwareConfiguration::setInterleavedOff() hrtim_stop_interleaved(); } -void HardwareConfiguration::setFullBridgeOff() +void HardwareConfiguration::setFullBridgeBuckOff() { - hrtim_stop_interleaved(); + hrtim_stop_full_bridge_buck(); } void HardwareConfiguration::setLeg1Off() 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 1bff9c0fc316906df67d94c828a29d2515b09dd6..2180d4fe49d1206fa50b05343bd464c29882bb88 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h @@ -45,19 +45,27 @@ */ typedef enum { - v_0_0, // No power converter attached, the software is running on Nucleo G474RE - v_0_9, - v_1_1_2, - SPIN + nucleo_G474RE, + O2_v_0_9, + O2_v_1_1_2, + SPIN_v_0_9 } hardware_version_t; -/** Switch leg opeation type. +/** Switch leg operation type. */ typedef enum { - buck, // No power converter attached, the software is running on Nucleo G474RE - boost -} hardware_conversion_t; + buck, + boost +} leg_operation_t; + +/** Inverter leg operation type. + */ +typedef enum +{ + unipolar, + bipolar +} inverter_modulation_t; ///// @@ -92,14 +100,14 @@ public: static void initInterleavedBoostMode(); static void initInterleavedBoostModeCenterAligned(); static void initFullBridgeBuckMode(); - static void initFullBridgeBuckModeCenterAligned(); + static void initFullBridgeBuckModeCenterAligned(inverter_modulation_t inverter_modulation_type); static void initFullBridgeBoostMode(); static void initFullBridgeBoostModeCenterAligned(); - static void initIndependentMode(hardware_conversion_t leg1_conversion_type, hardware_conversion_t leg2_conversion_type); - static void initIndependentModeCenterAligned(hardware_conversion_t leg1_conversion_type, hardware_conversion_t leg2_conversion_type); + static void initIndependentMode(leg_operation_t leg1_operation_type, leg_operation_t leg2_operation_type); + static void initIndependentModeCenterAligned(leg_operation_t leg1_operation_type, leg_operation_t leg2_operation_type); static void setInterleavedDutyCycle(float32_t duty_cycle); - static void setFullBridgeDutyCycle(float32_t duty_cycle); + static void setFullBridgeBuckDutyCycle(float32_t duty_cycle); static void setLeg1DutyCycle(float32_t duty_cycle); static void setLeg2DutyCycle(float32_t duty_cycle); @@ -112,12 +120,12 @@ public: static void setInterleavedOn(); - static void setFullBridgeOn(); + static void setFullBridgeBuckOn(); static void setLeg1On(); static void setLeg2On(); static void setInterleavedOff(); - static void setFullBridgeOff(); + static void setFullBridgeBuckOff(); static void setLeg1Off(); static void setLeg2Off(); 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 685782b9855422ea40d330395a911fe2750d46a6..0d9de1973f78a3d08fcb116b497d1a6400008a2a 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.cpp @@ -48,7 +48,7 @@ static uint16_t pwm_phase_shift_leg1; static uint16_t pwm_phase_shift_leg2; static uint16_t pwm_low_pulse_width; static uint16_t pwm_high_pulse_width; - +static bool full_bridge_bipolar_mode; /** * This function initializes both legs in buck mode @@ -151,6 +151,42 @@ void hrtim_init_independent_mode_center_aligned(bool leg1_buck_mode, bool leg2_b pwm_high_pulse_width = pwm_period * HIGH_DUTY; } +/** + * This function initializes both legs in full-bridge mode + */ +void hrtim_init_full_bridge_buck_mode() +{ + hrtim_init_voltage_buck(); + full_bridge_bipolar_mode = false; //left-aligned inverter is always on unipolar mode + + pwm_period = leg_period(); + pwm_low_pulse_width = pwm_period * LOW_DUTY; + pwm_high_pulse_width = pwm_period * HIGH_DUTY; + + pwm_phase_shift = pwm_period / 2; + +} + +/** + * This function initializes both legs in full-bridge mode + */ +void hrtim_init_full_bridge_buck_mode_center_aligned(bool bipolar_mode) +{ + hrtim_init_voltage_buck_center_aligned(); + full_bridge_bipolar_mode = bipolar_mode; + + pwm_period = leg_period(); + pwm_low_pulse_width = pwm_period * LOW_DUTY; + pwm_high_pulse_width = pwm_period * HIGH_DUTY; + + if (bipolar_mode){ + pwm_phase_shift = 0; + }else{ + pwm_phase_shift = pwm_period; + } + +} + /** * This function transfer the calculated PWM value to the @@ -186,7 +222,7 @@ void hrtim_interleaved_pwm_update(float32_t pwm_duty_cycle) leg_set(TIMB, pwm_pulse_width, pwm_phase_shift); } - hrtim_update_adc_trig_interleaved( (pwm_pulse_width>>1) + (pwm_pulse_width>>2)); + hrtim_update_adc_trig_interleaved( (pwm_pulse_width>>1) + (pwm_pulse_width>>2)); //works only on left aligned as center aligned does not use the same comparators } /** @@ -195,36 +231,63 @@ void hrtim_interleaved_pwm_update(float32_t pwm_duty_cycle) * bounds */ -void hrtim_hbridge_pwm_update(float32_t pwm_duty_cycle) +void hrtim_full_bridge_buck_pwm_update(float32_t pwm_duty_cycle) { uint16_t pwm_pulse_width; uint16_t pwm_reverse_pulse_width; // TESTING PWM VALUE TO AVOID OVERFLOW AND PWM UPDATE// - if (pwm_duty_cycle > HIGH_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE. + if(full_bridge_bipolar_mode) { - pwm_duty_cycle = HIGH_DUTY; - pwm_pulse_width = pwm_high_pulse_width; - pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; - leg_set(TIMA, pwm_pulse_width, 0); - leg_set(TIMB, pwm_reverse_pulse_width, pwm_period*pwm_duty_cycle); - } - - else if (pwm_duty_cycle < LOW_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE. - { - pwm_duty_cycle = LOW_DUTY; - pwm_pulse_width = pwm_low_pulse_width; - pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; - leg_set(TIMA, pwm_pulse_width, 0); - leg_set(TIMB, pwm_reverse_pulse_width, pwm_period*pwm_duty_cycle); + if (pwm_duty_cycle > HIGH_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE. + { + pwm_duty_cycle = HIGH_DUTY; + pwm_pulse_width = pwm_high_pulse_width; + pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; + leg_set(TIMA, pwm_pulse_width, 0); + leg_set(TIMB, pwm_reverse_pulse_width, pwm_period*pwm_duty_cycle); + } + else if (pwm_duty_cycle < LOW_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE. + { + pwm_duty_cycle = LOW_DUTY; + pwm_pulse_width = pwm_low_pulse_width; + pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; + leg_set(TIMA, pwm_pulse_width, 0); + leg_set(TIMB, pwm_reverse_pulse_width, pwm_period*pwm_duty_cycle); + } + else + { + pwm_pulse_width = (pwm_duty_cycle * pwm_period); + pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; + leg_set(TIMA, pwm_pulse_width, 0); + leg_set(TIMB, pwm_reverse_pulse_width, pwm_period*pwm_duty_cycle); + } } - else { - pwm_pulse_width = (pwm_duty_cycle * pwm_period); - pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; - leg_set(TIMA, pwm_pulse_width, 0); - leg_set(TIMB, pwm_reverse_pulse_width, pwm_period*pwm_duty_cycle); + if (pwm_duty_cycle > HIGH_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE. + { + pwm_duty_cycle = HIGH_DUTY; + pwm_pulse_width = pwm_high_pulse_width; + pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; + leg_set(TIMA, pwm_pulse_width, 0); + leg_set(TIMB, pwm_reverse_pulse_width, pwm_phase_shift); + } + else if (pwm_duty_cycle < LOW_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE. + { + pwm_duty_cycle = LOW_DUTY; + pwm_pulse_width = pwm_low_pulse_width; + pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; + leg_set(TIMA, pwm_pulse_width, 0); + leg_set(TIMB, pwm_reverse_pulse_width, pwm_phase_shift); + } + else + { + pwm_pulse_width = (pwm_duty_cycle * pwm_period); + pwm_reverse_pulse_width = (1-pwm_duty_cycle) * pwm_period; + leg_set(TIMA, pwm_pulse_width, 0); + leg_set(TIMB, pwm_reverse_pulse_width, pwm_phase_shift); + } } } @@ -334,16 +397,27 @@ void hrtim_leg2_phase_shift_update_center_aligned(float32_t phase_shift) */ void hrtim_stop_interleaved() { - leg_stop(TIMA); - leg_stop(TIMB); + leg_stop(TIMA); + leg_stop(TIMB); } +/** + * This stops the converter by putting both timing + * units outputs low + */ +void hrtim_stop_full_bridge_buck() +{ + leg_stop(TIMA); + leg_stop(TIMB); +} + + /** * This stops only leg 1 */ void hrtim_stop_leg1() { - leg_stop(TIMA); + leg_stop(TIMA); } /** @@ -351,7 +425,7 @@ void hrtim_stop_leg1() */ void hrtim_stop_leg2() { - leg_stop(TIMB); + leg_stop(TIMB); } /** * This stops the converter by putting both timing @@ -362,6 +436,17 @@ void hrtim_start_interleaved() leg_start(TIMA); leg_start(TIMB); } + +/** + * This stops the converter by putting both timing + * units outputs low + */ +void hrtim_start_full_bridge_buck() +{ + leg_start(TIMA); + leg_start(TIMB); +} + /** * This stops the converter by putting both timing * units outputs low 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 02df682462a57f2655c5697df4c519166502d575..88805c2fb6dc300001c374f1d42d54919ab14921 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.h +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hrtim_configuration.h @@ -49,6 +49,19 @@ void hrtim_init_interleaved_buck_mode_center_aligned(); */ void hrtim_init_interleaved_boost_mode(); +/** + * @brief This function initializes the converter in full bridge mode + * with the input on the high side and the output on the low side with the HRTIM on left aligned + */ +void hrtim_init_full_bridge_buck_mode(); + +/** + * @brief This function initializes the converter in full bridge mode + * with the input on the high side and the output on the low side with the HRTIM as center aligned + */ +void hrtim_init_full_bridge_buck_mode_center_aligned(bool bipolar_mode); + + /** * @brief This function initializes the converter in interleaved boost mode * with the input on the low side and the output on the high side. The counting mode @@ -86,7 +99,7 @@ void hrtim_interleaved_pwm_update(float32_t duty_cycle); * * @param[in] duty_cycle floating point duty cycle comprised between 0 and 1. */ -void hrtim_hbridge_pwm_update(float32_t duty_cycle); +void hrtim_full_bridge_buck_pwm_update(float32_t duty_cycle); /** * @brief This function transfer the calculated PWM value of leg_1 to the @@ -129,6 +142,7 @@ void hrtim_leg2_phase_shift_update(float32_t phase_shift); */ void hrtim_leg1_phase_shift_update_center_aligned(float32_t phase_shift); + /** * @brief This function updates the phase shift between the leg 1 and the master hrtim for the center aligned * @@ -137,14 +151,17 @@ void hrtim_leg1_phase_shift_update_center_aligned(float32_t phase_shift); void hrtim_leg2_phase_shift_update_center_aligned(float32_t phase_shift); - - /** * @brief This function stops the converter by putting both timing * units outputs low */ void hrtim_stop_interleaved(); +/** + * @brief This function stops the inverter + */ +void hrtim_stop_full_bridge_buck(); + /** * @brief This function stops only leg 1 */ @@ -160,6 +177,11 @@ void hrtim_stop_leg2(); */ void hrtim_start_interleaved(); +/** + * @brief This function starts the inverter + */ +void hrtim_start_full_bridge_buck(); + /** * @brief This function starts only leg 1 */