Skip to content
Snippets Groups Projects
Commit 88f6767b authored by Luiz-Fernando Lavado-Villa's avatar Luiz-Fernando Lavado-Villa
Browse files

Added code for creating the H-bridge function

parent c303ead8
No related branches found
No related tags found
No related merge requests found
......@@ -92,6 +92,7 @@ float32_t Kw_2 = 0.000143;
static float32_t pwm_duty_cycle = 0.1; // PWM initialization duty cycle value
static float32_t pwm_duty_cycle_2 = 0.1; // PWM initialization duty cycle value
static uint16_t pwm_pulse_width;
static uint16_t pwm_reverse_pulse_width;
static uint16_t pwm_period, pwm_phase_shift, pwm_low_pulse_width, pwm_high_pulse_width;
/////
......@@ -362,6 +363,46 @@ void opalib_pid_voltage_pwm_update(float32_t duty_cycle)
}
}
/**
* This function transfer the calculated PWM value to the
* HRTIM peripheral and make sure it is between saturation
* bounds
*/
void opalib_pid_voltage_hbridge_pwm_update(float32_t duty_cycle)
{
pwm_duty_cycle = duty_cycle;
// TESTING PWM VALUE TO AVOID OVERFLOW AND PWM UPDATE//
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);
}
}
/**
* This function transfer the calculated PWM value of leg_1 to the
* HRTIM peripheral and make sure it is between saturation
......
......@@ -158,6 +158,15 @@ float32_t opalib_pid_voltage_pid_2_calculation(float32_t voltage_reference, floa
void opalib_pid_voltage_pwm_update(float32_t duty_cycle);
/**
* @brief This function transfer the calculated PWM value to the
* HRTIM peripheral and make sure it is between saturation
* bounds with a complementary approach to the duty cycles.
*
* @param[in] duty_cycle floating point duty cycle comprised between 0 and 1.
*/
void opalib_pid_voltage_hbridge_pwm_update(float32_t duty_cycle);
/**
* @brief This function transfer the calculated PWM value of leg_1 to the
* HRTIM peripheral and make sure it is between saturation
......
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