Bar Logo 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 "pwrctrl.h"
12#include "pwm_hs/pwm.h"
13#include "pwrctrl_typedef.h"
14#include "../driver/mcc_extension/drv_mcc_extension_pwm.h"
15
26{
27 // The PWM Period bits [2:0] needs to be mask when using cascaded PWM setup
28 // (please refer to Section 4.1.3.3 in High Resolution PWM FRM)
29 uint16_t PeriodMask = 0x7;
30 uint16_t PrimarySecondaryPhase;
31 uint16_t PrimaryPhaseDelay;
32
33
34
35 // Mask the calculated frequency bits [2:0] to make the cascaded/synchronous
36 // PWM scheme reliable (please refer to Section 4.1.3.3 in High Resolution PWM FRM)
37 pcInstance->Pwm.ControlPeriod = pcInstance->Pwm.ControlPeriod & ~(PeriodMask);
38
39 // Calculate Duty Cycle for 50%
40 pcInstance->Pwm.ControlDutyCycle = (pcInstance->Pwm.ControlPeriod >> 1);
41
42 // Maximum Clamping for control phase
43 if(pcInstance->Pwm.ControlPhase > pcInstance->Pwm.ControlDutyCycle)
44 {
45 pcInstance->Pwm.ControlPhase = pcInstance->Pwm.ControlDutyCycle;
46 }
47
48
50 {
51
52 PrimarySecondaryPhase = (pcInstance->Pwm.ControlPhase >> 1);
53
54
55 PrimaryPhaseDelay = (pcInstance->Pwm.ControlPhase >> 1);// (pcInstance->Pwm.ControlDutyCycle - PrimarySecondaryPhase) + pcInstance->Pwm.ControlPhase;
56
57 }
58 else
60 {
61
62 PrimarySecondaryPhase = pcInstance->Pwm.ControlDutyCycle - (pcInstance->Pwm.ControlPhase >> 1);
63
64 PrimaryPhaseDelay = 3*(pcInstance->Pwm.ControlPhase >> 1);//(pcInstance->Pwm.ControlDutyCycle - PrimarySecondaryPhase) + pcInstance->Pwm.ControlPhase;
65
66 }
67 else
68 {
69 PrimarySecondaryPhase = 0;
70 PrimaryPhaseDelay =0;
71 }
72
73 // Set the PWM trigger with the calculated PWM phases
74 PWM_TriggerCCompareValueSet(PWM_PRI_1, PrimarySecondaryPhase);
75 PWM_TriggerCCompareValueSet(PWM_SEC_1, PrimaryPhaseDelay);
76 PWM_TriggerCCompareValueSet(PWM_PRI_2, PrimarySecondaryPhase);
77
78 // Set the PWM Duty Cycle at 50% with the given Frequency
83
84 // Set the PWM Frequency
89
90 // Set the PWM Low DeadTime
95
96 // Set the PWM High DeadTime
101
102 // Set the Update bit of the last PWM in the cascaded approach to broadcast
103 // it to the other PWMs
105
106}
107
108
118{
119 // Turn-On PWM outputs by disabling the output override
120 // on each high and low PWM output
125
130
131 // Set update request of the last PWM in the cascade
132 // to update all PWM registers
134
135}
136
137
138
148{
149 // Turn-Off PWM outputs by enabling the output override
150 // on each high and low PWM output
155
160
161 // Set update request of the last PWM in the cascade
162 // to update all pwm registers
164
165}
166
167
168
177void PwrCtrl_PWM_DAB_DirectionSpecificSwapCfg(PWR_CTRL_CHARGE_STATE_t direction)
178{
179 // Turn-Off PWM outputs by enabling the output override
180 // on each high and low PWM output
182
183 PWM_Disable();
184
185 if(direction == PWR_CTRL_CHARGING)
186 {
187// forward / charger mode
192 }
193 if(direction == PWR_CTRL_DISCHARGING)
194 {
195// reverse / discharger mode
200 }
201
202 PWM_Enable();
203 // Set update request of the last PWM in the cascade
204 // to update all pwm registers
206
207}
208
This is the generated driver header file for the PWM driver.
@ PWM_SEC_1
@ PWM_PRI_1
@ PWM_SEC_2
@ PWM_PRI_2
static void PWM_Swap_PWMxL_and_PWMxH(uint16_t pwmIndex, bool swapPWMH_PWML)
Enable/Disable the PWM instance output swap bit.
POWER_CONTROL_t dab
Global data object for a DAB Converter.
Definition pwrctrl.c:28
void PwrCtrl_PWM_DAB_DirectionSpecificSwapCfg(PWR_CTRL_CHARGE_STATE_t direction)
Forward/Reverse Direction related swap pattern on PWM output.
void PwrCtrl_PWM_Update(POWER_CONTROL_t *pcInstance)
PWM distribution for DAB converter.
Definition pwrctrl_pwm.c:25
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
void PwrCtrl_PWM_Enable(void)
Enable the PWM output.
@ PWR_CTRL_CHARGING
power converter is in charging mode
@ PWR_CTRL_DISCHARGING
power converter is in discharging mode
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
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
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
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
static void PWM_Disable(void)
This inline function will disable all the generators of PWM module.
Definition pwm.h:426
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
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
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
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
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
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
static void PWM_Enable(void)
This inline function will enable all the generators of PWM module.
Definition pwm.h:412
uint16_t ControlPeriod
Control period value from control loop.
uint16_t DeadTimeHigh
Deadtime High settings for PWM.
uint16_t ControlDutyCycle
Control Duty Cycle calculation based on Control Period.
uint16_t DeadTimeLow
Deadtime High settings for PWM.
uint16_t ControlPhase
Control phase value from control loop.
Power control API structure.
SWITCH_NODE_t Pwm
Switch node settings.
PWR_CTRL_CHARGE_STATE_t PowerDirection
defines if the power converter is in charging or discharging mode