Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
opalib_pid_voltage
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jean Alinei
opalib_pid_voltage
Commits
88f6767b
Commit
88f6767b
authored
3 years ago
by
Luiz-Fernando Lavado-Villa
Browse files
Options
Downloads
Patches
Plain Diff
Added code for creating the H-bridge function
parent
c303ead8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/opalib_pid_voltage.c
+41
-0
41 additions, 0 deletions
src/opalib_pid_voltage.c
src/opalib_pid_voltage.h
+9
-0
9 additions, 0 deletions
src/opalib_pid_voltage.h
with
50 additions
and
0 deletions
src/opalib_pid_voltage.c
+
41
−
0
View file @
88f6767b
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/opalib_pid_voltage.h
+
9
−
0
View file @
88f6767b
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment