|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
pwrctrl_pwm.c
Go to the documentation of this file.
1
9#include <xc.h>
10#include <stdbool.h>
11#include "pwm_hs/pwm.h"
12#include "pwrctrl_typedef.h"
13
14
24 void PwrCtrl_PWM_Update(POWER_CONTROL_t* pcInstance)
25{
26 // The PWM Period bits [2:0] needs to be mask when using cascaded PWM setup
27 // (please refer to Section 4.1.3.3 in High Resolution PWM FRM)
28 uint16_t PeriodMask = 0x7;
29
30 // Mask the calculated frequency bits [2:0] to make the cascaded/synchronous
31 // PWM scheme reliable (please refer to Section 4.1.3.3 in High Resolution PWM FRM)
32 pcInstance->Pwm.ControlPeriod = pcInstance->Pwm.ControlPeriod & ~(PeriodMask);
33
34 // Calculate Duty Cycle for 50%
35 pcInstance->Pwm.ControlDutyCycle = (pcInstance->Pwm.ControlPeriod >> 1);
36
37 // Maximum Clamping for control phase
38 if(pcInstance->Pwm.ControlPhase > pcInstance->Pwm.ControlPeriod){
39 pcInstance->Pwm.ControlPhase = pcInstance->Pwm.ControlPeriod;
40 }
41
42 // Calculate primary to secondary phase as half of the control phase
43 uint16_t PrimarySecondaryPhase = (pcInstance->Pwm.ControlPhase >> 1);
44
45 // Compensate the added Dead-time
46 PrimarySecondaryPhase += pcInstance->Pwm.DeadTimeLow >> 1;
47
48 // Calculate the Bridge Delay ((Frequency / 2) - Primary to Secondary Phase + Control Phase)
49 // Note that in the cascaded PWM, the reference phase of the client PWM, is its trigger source
50 uint16_t PrimaryPhaseDelay = (pcInstance->Pwm.ControlDutyCycle - PrimarySecondaryPhase) +
51 pcInstance->Pwm.ControlPhase;
52
53 // Set the PWM trigger with the calculated PWM phases
54 PWM_TriggerCCompareValueSet(PWM_PRI_1, PrimarySecondaryPhase);
55 PWM_TriggerCCompareValueSet(PWM_SEC_1, PrimaryPhaseDelay);
56 PWM_TriggerCCompareValueSet(PWM_PRI_2, PrimarySecondaryPhase);
57
58 // Set the PWM Duty Cycle at 50% with the given Frequency
59 PWM_DutyCycleSet(PWM_PRI_1, pcInstance->Pwm.ControlDutyCycle);
60 PWM_DutyCycleSet(PWM_SEC_1, pcInstance->Pwm.ControlDutyCycle);
61 PWM_DutyCycleSet(PWM_PRI_2, pcInstance->Pwm.ControlDutyCycle);
62 PWM_DutyCycleSet(PWM_SEC_2, pcInstance->Pwm.ControlDutyCycle);
63
64 // Set the PWM Frequency
65 PWM_PeriodSet(PWM_PRI_1, pcInstance->Pwm.ControlPeriod);
66 PWM_PeriodSet(PWM_SEC_1, pcInstance->Pwm.ControlPeriod);
67 PWM_PeriodSet(PWM_PRI_2, pcInstance->Pwm.ControlPeriod);
68 PWM_PeriodSet(PWM_SEC_2, pcInstance->Pwm.ControlPeriod);
69
70 // Set the PWM Low DeadTime
71 PWM_DeadTimeLowSet(PWM_PRI_1, pcInstance->Pwm.DeadTimeLow);
72 PWM_DeadTimeLowSet(PWM_SEC_1, pcInstance->Pwm.DeadTimeLow);
73 PWM_DeadTimeLowSet(PWM_PRI_2, pcInstance->Pwm.DeadTimeLow);
74 PWM_DeadTimeLowSet(PWM_SEC_2, pcInstance->Pwm.DeadTimeLow);
75
76 // Set the PWM High DeadTime
77 PWM_DeadTimeHighSet(PWM_PRI_1, pcInstance->Pwm.DeadTimeHigh);
78 PWM_DeadTimeHighSet(PWM_SEC_1, pcInstance->Pwm.DeadTimeHigh);
79 PWM_DeadTimeHighSet(PWM_PRI_2, pcInstance->Pwm.DeadTimeHigh);
80 PWM_DeadTimeHighSet(PWM_SEC_2, pcInstance->Pwm.DeadTimeHigh);
81
82 // Set the Update bit of the last PWM in the cascaded approach to broadcast
83 // it to the other PWMs
84 PWM_SoftwareUpdateRequest(PWM_SEC_2);
85
86}
87
88
97 void PwrCtrl_PWM_Enable(void)
98{
99 // Turn-On PWM outputs by disabling the output override
100 // on each high and low PWM output
101 PWM_OverrideHighDisable(PWM_PRI_1);
102 PWM_OverrideHighDisable(PWM_SEC_1);
103 PWM_OverrideHighDisable(PWM_PRI_2);
104 PWM_OverrideHighDisable(PWM_SEC_2);
105
106 PWM_OverrideLowDisable(PWM_PRI_1);
107 PWM_OverrideLowDisable(PWM_SEC_1);
108 PWM_OverrideLowDisable(PWM_PRI_2);
109 PWM_OverrideLowDisable(PWM_SEC_2);
110
111 // Set update request of the last PWM in the cascade
112 // to update all PWM registers
113 PWM_SoftwareUpdateRequest(PWM_SEC_2);
114
115}
116
117
118
127 void PwrCtrl_PWM_Disable(void)
128{
129 // Turn-Off PWM outputs by enabling the output override
130 // on each high and low PWM output
131 PWM_OverrideHighEnable(PWM_PRI_1);
132 PWM_OverrideHighEnable(PWM_SEC_1);
133 PWM_OverrideHighEnable(PWM_PRI_2);
134 PWM_OverrideHighEnable(PWM_SEC_2);
135
136 PWM_OverrideLowEnable(PWM_PRI_1);
137 PWM_OverrideLowEnable(PWM_SEC_1);
138 PWM_OverrideLowEnable(PWM_PRI_2);
139 PWM_OverrideLowEnable(PWM_SEC_2);
140
141 // Set update request of the last PWM in the cascade
142 // to update all pwm registers
143 PWM_SoftwareUpdateRequest(PWM_SEC_2);
144
145}
pwm.h
This is the generated driver header file for the PWM driver.
PWM_SEC_1
@ PWM_SEC_1
Definition pwm_hs_types.h:56
PWM_PRI_1
@ PWM_PRI_1
Definition pwm_hs_types.h:55
PWM_SEC_2
@ PWM_SEC_2
Definition pwm_hs_types.h:58
PWM_PRI_2
@ PWM_PRI_2
Definition pwm_hs_types.h:57
PwrCtrl_PWM_Update
void PwrCtrl_PWM_Update(POWER_CONTROL_t *pcInstance)
PWM distribution for DAB converter.
Definition pwrctrl_pwm.c:24
PwrCtrl_PWM_Disable
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
Definition pwrctrl_pwm.c:127
PwrCtrl_PWM_Enable
void PwrCtrl_PWM_Enable(void)
Enable the PWM output.
Definition pwrctrl_pwm.c:97
PWM_DeadTimeLowSet
static void PWM_DeadTimeLowSet(enum PWM_GENERATOR genNum, uint16_t deadtimeLow)
This inline function updates PWM Deadtime low register with the requested value for a specific PWM ge...
Definition pwm.h:793
PWM_OverrideLowEnable
static void PWM_OverrideLowEnable(enum PWM_GENERATOR genNum)
This inline function enables PWM override on PWML output for specific PWM generator selected by the a...
Definition pwm.h:714
PWM_DutyCycleSet
static void PWM_DutyCycleSet(enum PWM_GENERATOR genNum, uint16_t dutyCycle)
This inline function sets the PWM generator specific duty cycle register.
Definition pwm.h:500
PWM_OverrideHighEnable
static void PWM_OverrideHighEnable(enum PWM_GENERATOR genNum)
This inline function enables PWM override on PWMH output for specific PWM generator selected by the a...
Definition pwm.h:688
PWM_SoftwareUpdateRequest
static void PWM_SoftwareUpdateRequest(enum PWM_GENERATOR genNum)
This inline function requests to update the data registers for specific PWM generator selected by the...
Definition pwm.h:1239
PWM_OverrideHighDisable
static void PWM_OverrideHighDisable(enum PWM_GENERATOR genNum)
This inline function disables PWM override on PWMH output for specific PWM generator selected by the ...
Definition pwm.h:740
PWM_OverrideLowDisable
static void PWM_OverrideLowDisable(enum PWM_GENERATOR genNum)
This inline function disables PWM override on PWML output for specific PWM generator selected by the ...
Definition pwm.h:766
PWM_TriggerCCompareValueSet
static void PWM_TriggerCCompareValueSet(enum PWM_GENERATOR genNum, uint16_t trigC)
This inline function sets the Trigger C compare value in count for a specific PWM generator selected ...
Definition pwm.h:1350
PWM_PeriodSet
static void PWM_PeriodSet(enum PWM_GENERATOR genNum, uint16_t period)
This inline function sets the period value in count for the PWM generator specific Time Base.
Definition pwm.h:474
PWM_DeadTimeHighSet
static void PWM_DeadTimeHighSet(enum PWM_GENERATOR genNum, uint16_t deadtimeHigh)
This inline function updates PWM Deadtime high register with the requested value for a specific PWM g...
Definition pwm.h:820
SWITCH_NODE_s::ControlPeriod
uint16_t ControlPeriod
Control period value from control loop.
Definition pwrctrl_typedef.h:37
SWITCH_NODE_s::DeadTimeHigh
uint16_t DeadTimeHigh
Deadtime High settings for PWM.
Definition pwrctrl_typedef.h:42
SWITCH_NODE_s::ControlDutyCycle
uint16_t ControlDutyCycle
Control Duty Cycle calculation based on Control Period.
Definition pwrctrl_typedef.h:38
SWITCH_NODE_s::DeadTimeLow
uint16_t DeadTimeLow
Deadtime High settings for PWM.
Definition pwrctrl_typedef.h:43
SWITCH_NODE_s::ControlPhase
uint16_t ControlPhase
Control phase value from control loop.
Definition pwrctrl_typedef.h:39
POWER_CONTROL_s
Power control API structure.
Definition pwrctrl_typedef.h:167
POWER_CONTROL_s::Pwm
SWITCH_NODE_t Pwm
Switch node settings.
Definition pwrctrl_typedef.h:171