Skip to content
Snippets Groups Projects
Commit 652a8647 authored by Luiz Fernando Lavado Villa's avatar Luiz Fernando Lavado Villa :speech_balloon: Committed by Ayoub Farah Hassan
Browse files

The HRTIM lacks support for a single phase inverter. This commit provides this functionality.

parent 4130ab02
No related branches found
No related tags found
1 merge request!21The HRTIM lacks support for a single phase inverter. This commit provides this functionality.
......@@ -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()
......
......@@ -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();
......
......@@ -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
......
......@@ -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
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment