PWM Interface Routines. More...
#include "TIMotorLIB.h"
#include "SFO_V5.h"
#include "IQConstants.h"
#include "Utils.h"
Go to the source code of this file.
Data Structures | |
struct | PWM3phConfiguration |
three phase PWM configuration More... | |
Defines | |
#define | EPWM1_INT_ACK (0x1); |
#define | EPWM2_INT_ACK (0x2); |
#define | EPWM3_INT_ACK (0x4); |
#define | EPWM4_INT_ACK (0x8); |
#define | EPWM5_INT_ACK (0x10); |
#define | EPWM6_INT_ACK (0x20); |
#define | PWM_OUTPUTS_SIZE (12) |
number of pwm outputs | |
Enumerations | |
enum | EPWMX { EPWMA, EPWMB } |
select EPWM device More... | |
enum | PHSEN { MASTERPWM, SLAVEPWM } |
select device as master or slave More... | |
enum | SYNCOSEL { SYNC_IN = 0, SYNC_CTR_ZERO = 1, SYNC_CTR_CMPB = 2, SYNC_DISABLE = 3 } |
select synchronization output mode More... | |
enum | ePWMenum { PWM1 = 0, PWM2 = 1, PWM3 = 2, PWM4 = 3, PWM5 = 4, PWM6 = 5 } |
access to pwm devices individually More... | |
enum | PWMMODE { NORMAL_MODE, HRPWM_MODE } |
select normal mode or high resolution mode More... | |
enum | PWMCARRIER { SAWTOOTH = TB_COUNT_UP, TRIANGLE = TB_COUNT_UPDOWN } |
select carrier signal (sawtooth or triangle) More... | |
enum | PWMMODULATION { SYMMETRICAL = CC_CTR_ZERO, ASYMMETRICAL = CC_CTR_ZERO_PRD } |
select modulation (symmetrical, asymetrical) for triangle pwm carrier More... | |
enum | INTSEL { CTR_ZERO = ET_CTR_ZERO, CTR_PRD = ET_CTR_PRD } |
interrupt generation More... | |
enum | ePWMSOC { SOCNULL = 0, SOCA = 1, SOCB = 2 } |
start of conversion More... | |
enum | SOCTrigger { EvTBeqZERO = 1, EvTBeqPRD = 2, EvTBCNTeqCMPAI = 4, EvTBCNTeqCMPAD = 5, EvTBCNTeqCMPBI = 6, EvTBCNTeqCMPBD = 7 } |
SOC triggers. More... | |
enum | sideEnum { xA = 0, xB = 6 } |
select A or B switch More... | |
enum | SWITCHLOGIC { NEG_LOGIC = 1, POS_LOGIC = 2 } |
select switch logic More... | |
Functions | |
void | BindPWMOutputs (void) |
void | InitPWMPeripheralClocks (void) |
Init clocks on PWM inputs EPWMA/B depending on the configuration stored in pwmConf.epwmX. | |
void | InitPWMAPeripheralClocks (void) |
Init clocks on PWM inputs EPWMA. | |
void | InitPWMBPeripheralClocks (void) |
Init clocks on PWM inputs EPWMB. | |
void | InitEPWMGpio (ePWMenum PWM) |
void | InitTzGpio (void) |
void | InitPWMSide (ePWMenum PWM, sideEnum side, PWMMODULATION modulation, SWITCHLOGIC switchLogic) |
void | InitSinglePWMOutput (void(*interruptFCN)(void), ePWMenum PWM, sideEnum side, Uint16 tpwm_us, PHSEN phSen, SYNCOSEL syncMode, PWMMODE pwmMode, PWMCARRIER pwmCarrier, PWMMODULATION modulation, INTSEL intSel, SWITCHLOGIC switchLogic) |
void | InitComplementaryPWMOutput (void(*interruptFCN)(void), ePWMenum PWM, Uint16 tpwm_us, Uint16 db_us, PHSEN phSen, PWMMODE pwmMode, PWMCARRIER pwmCarrier, PWMMODULATION modulation, INTSEL intSel, SWITCHLOGIC switchLogic) |
void | Init3phPWM (void(*interruptFCN)(void), EPWMX epwmX, Uint16 tpwm_us, Uint16 db_us, PWMCARRIER pwmCarrier, PWMMODULATION modulation, INTSEL intSel, _iq vBus, ePWMSOC soc, SOCTrigger trigger, SWITCHLOGIC switchLogic) |
void | ConfigurePWMLeg (volatile struct EPWM_REGS *pwmPtr, PHSEN master, Uint16 tpwm_us, Uint16 db_us, PWMCARRIER pwmCarrier, PWMMODULATION modulation, unsigned int polSel) |
void | AddEventTrigger (volatile struct EPWM_REGS *pwmPtr, ePWMSOC soc, SOCTrigger trigger) |
static void | SetEnablePWMInput (Uint16 *input) |
static void | UpdateEPWM (ePWMenum PWM, sideEnum side, _iq cmp) |
static void | UpdateEPWMDuty (ePWMenum PWM, sideEnum side, _iq duty) |
static void | UpdateHRPWM (ePWMenum PWM, _iq cmp) |
static void | UpdatePWM3ph (_iq vas, _iq vbs, _iq vcs, char saturate) |
static void | UpdatePWMA3ph (_iq vas, _iq vbs, _iq vcs, char saturate) |
static void | UpdatePWMB3ph (_iq vas, _iq vbs, _iq vcs, char saturate) |
static void | UpdatePWMDuty3ph (_iq vad, _iq vbd, _iq vcd) |
static void | UpdatePWMADuty3ph (_iq vad, _iq vbd, _iq vcd) |
static void | UpdatePWMBDuty3ph (_iq vad, _iq vbd, _iq vcd) |
static void | ForceSingleEPWM (ePWMenum PWM, sideEnum side, Uint16 level) |
Force EPWM values (spru791a.pdf, pp. 100). | |
static void | _ForceSingleEPWM (volatile struct EPWM_REGS *pwmPtr, sideEnum side, Uint16 level) |
static void | ForceEPWM (ePWMenum PWM, sideEnum side, Uint16 level) |
static void | EnablePWM (Uint16 enable) |
static void | EnableEPWMModuleTBCLK (void) |
Enable device clock. | |
static void | EpwmPIEAck (volatile struct EPWM_REGS *epwmRegs) |
static void | EpwmAPIEAck (void) |
static void | EpwmBPIEAck (void) |
Variables | |
struct PWM3phConfiguration | pwmConf |
struct PWM3phConfiguration pwmAConf | pwmBConf |
struct EPWM_REGS * | ePWM [] |
acess pointers to pwm configuration registers | |
volatile Uint16 * | cmpPtr [PWM_OUTPUTS_SIZE] |
fast access to EPWM comparison registers | |
int | MEP_ScaleFactor [PWM_CH] |
int | MEP_SF1 |
int | MEP_SF2 |
int | MEP_SF3 |
int | MEP_SF4 |
int | MEP_SF5 |
int | MEP_SF6 |
PWM Interface Routines.
File Name : Epwm.h Project : TIMotorLIB
TI Doc: SPRU791, SPRUG04 (newer), spraai1
Definition in file Epwm.h.
enum ePWMenum |
enum ePWMSOC |
enum EPWMX |
enum INTSEL |
enum PHSEN |
enum PWMCARRIER |
enum PWMMODE |
enum PWMMODULATION |
enum sideEnum |
enum SOCTrigger |
SOC triggers.
enum SWITCHLOGIC |
enum SYNCOSEL |
static void _ForceSingleEPWM | ( | volatile struct EPWM_REGS * | pwmPtr, | |
sideEnum | side, | |||
Uint16 | level | |||
) | [inline, static] |
void AddEventTrigger | ( | volatile struct EPWM_REGS * | pwmPtr, | |
ePWMSOC | soc, | |||
SOCTrigger | trigger | |||
) |
Selects where the Start of Conversion (SOC) signal is generated
pwmPtr,: | Pointer to EPWM_REGS register for the configuration | |
soc,: | Which sequencer is triggered (SOCNULL/SOCA/SOCB) | |
trigger,: |
|
void ConfigurePWMLeg | ( | volatile struct EPWM_REGS * | pwmPtr, | |
PHSEN | master, | |||
Uint16 | tpwm_us, | |||
Uint16 | db_us, | |||
PWMCARRIER | pwmCarrier, | |||
PWMMODULATION | modulation, | |||
unsigned int | polSel | |||
) |
Configure two switches to work in complementary mode
pwmPtr,: | Pointer to EPWM_REGS register for the configuration of the switches pair | |
master,: | MASTERPWM/SLAVEPWM. Selects if the clocking signal is generated by the configured output or is passed externally. | |
tpwm_us,: | switching period in us | |
db_us,: | dead time value in us | |
pwmCarrier,: | select SAWTOOTH or TRIANGLE carrier | |
modulation,: | SYMMETRICAL/ASYMMETRICAL. If symmetrical, comparison values are updated when the counter reachs 0. If asymmetrical, comparison values are updated both at 0 and period of the counter | |
polSel,: | Polarity selection for dead time generation (DB_ACTIVE_LOC/DB_ACTIVE_HIC) |
static void EnableEPWMModuleTBCLK | ( | void | ) | [inline, static] |
Enable device clock.
static void EnablePWM | ( | Uint16 | enable | ) | [inline, static] |
static void EpwmAPIEAck | ( | void | ) | [inline, static] |
ACK interrupt for EPWMA. This function MUST be called if more interrupts from PIEACK_GROUP3 are wanted
static void EpwmBPIEAck | ( | void | ) | [inline, static] |
ACK interrupt for EPWMB. This function MUST be called if more interrupts from PIEACK_GROUP3 are wanted
static void EpwmPIEAck | ( | volatile struct EPWM_REGS * | epwmRegs | ) | [inline, static] |
void Init3phPWM | ( | void(*)(void) | interruptFCN, | |
EPWMX | epwmX, | |||
Uint16 | tpwm_us, | |||
Uint16 | db_us, | |||
PWMCARRIER | pwmCarrier, | |||
PWMMODULATION | modulation, | |||
INTSEL | intSel, | |||
_iq | vBus, | |||
ePWMSOC | soc, | |||
SOCTrigger | trigger, | |||
SWITCHLOGIC | switchLogic | |||
) |
Intializes a set of EPWM outputs to drive a three phase inverter
interruptFCN,: | pointer to ISR executed when intSel condition is reached. If 0, no function is called | |
epwmX,: | Selection of PWM input to be configured (PWM1...PWM6) | |
tpwm_us,: | switching period in us | |
db_us,: | dead time value in us | |
pwmCarrier,: | select SAWTOOTH or TRIANGLE carrier | |
modulation,: | SYMMETRICAL/ASYMMETRICAL. If symmetrical, comparison values are updated when the counter reachs 0. If asymmetrical, comparison values are updated both at 0 and period of the counter | |
intSel,: | CTR_ZERO/CTR_PRD. Call the ISR when the counter reach 0 or when the counter reach the period. | |
vBus,: | DC bus voltage in V ( |
soc,: | SOCNULL/SOCA/SOCB. Generates a start of converion trigger for none, A or B sequencer respectively | |
trigger,: | trigger of SOC. See AddEventTrigger function. | |
switchLogic,: | POS_LOGIC/NEG_LOGIC. Select logic for the switches |
void InitComplementaryPWMOutput | ( | void(*)(void) | interruptFCN, | |
ePWMenum | PWM, | |||
Uint16 | tpwm_us, | |||
Uint16 | db_us, | |||
PHSEN | phSen, | |||
PWMMODE | pwmMode, | |||
PWMCARRIER | pwmCarrier, | |||
PWMMODULATION | modulation, | |||
INTSEL | intSel, | |||
SWITCHLOGIC | switchLogic | |||
) |
Intializes a given EPWM pair in complementary mode
interruptFCN,: | pointer to ISR executed when intSel condition is reached. If 0, no function is called | |
PWM,: | Selection of PWM input to be configured (PWM1...PWM6) | |
tpwm_us,: | switching period in us | |
db_us,: | dead time value in us | |
phSen,: | select device as master or slave (MASTERPWM/SLAVEPWM) | |
pwmMode,: | normal mode (16 bits) or high resolution ( |
pwmCarrier,: | select SAWTOOTH or TRIANGLE carrier | |
modulation,: | SYMMETRICAL/ASYMMETRICAL. If symmetrical, comparison values are updated when the counter reachs 0. If asymmetrical, comparison values are updated both at 0 and period of the counter | |
intSel,: | CTR_ZERO/CTR_PRD. Call the ISR when the counter reach 0 or when the counter reach the period. | |
switchLogic,: | POS_LOGIC/NEG_LOGIC. Select logic for the switches |
void InitEPWMGpio | ( | ePWMenum | PWM | ) |
Configure needed GPIO ports to be used by EPWM outputs. Affected GPIO inputs are: EPWM1: GPIO0, GPIO1 EPWM2: GPIO2, GPIO3 EPWM3: GPIO4, GPIO5 EPWM4: GPIO6, GPIO7 EPWM5: GPIO8, GPIO9 EPWM6: GPIO10, GPIO11 Actions taken:
PWM | is the pwm input to be used |
void InitPWMAPeripheralClocks | ( | void | ) |
void InitPWMBPeripheralClocks | ( | void | ) |
void InitPWMPeripheralClocks | ( | void | ) |
void InitPWMSide | ( | ePWMenum | PWM, | |
sideEnum | side, | |||
PWMMODULATION | modulation, | |||
SWITCHLOGIC | switchLogic | |||
) |
Intializes a given EPWM side (A/B). This function only can be called after one output for the given EPWM module has been configured. Example: InitSinglePWMOutput(pwmInterrupt, PWM1, xA, TPWMA_US, MASTERPWM, SYNC_DISABLE, NORMAL_MODE, TRIANGLE, SYMMETRICAL, CTR_ZERO, POS_LOGIC); InitPWMSide(PWM1, xB, SYMMETRICAL, POS_LOGIC);
PWM,: | Selection of PWM input to be configured (PWM1...PWM6) | |
sideEnum,: | Selection of A/B switches | |
modulation,: | SYMMETRICAL/ASYMMETRICAL. If symmetrical, comparison | |
switchLogic,: | POS_LOGIC/NEG_LOGIC. Select logic for the drived switch |
void InitSinglePWMOutput | ( | void(*)(void) | interruptFCN, | |
ePWMenum | PWM, | |||
sideEnum | side, | |||
Uint16 | tpwm_us, | |||
PHSEN | phSen, | |||
SYNCOSEL | syncMode, | |||
PWMMODE | pwmMode, | |||
PWMCARRIER | pwmCarrier, | |||
PWMMODULATION | modulation, | |||
INTSEL | intSel, | |||
SWITCHLOGIC | switchLogic | |||
) |
Intializes a given EPWM
interruptFCN,: | pointer to ISR executed when intSel condition is reached. If 0, no function is called | |
PWM,: | Selection of PWM input to be configured (PWM1...PWM6) | |
sideEnum,: | Selection of A/B switches | |
tpwm_us,: | switching period in us | |
pwmMode,: | normal mode (16 bits) or high resolution ( |
PHSEN,: | select device as master or slave (MASTERPWM/SLAVEPWM) | |
syncMode,: | Synchronization mode (see SYNCOSEL) | |
pwmCarrier,: | select SAWTOOTH or TRIANGLE carrier | |
modulation,: | SYMMETRICAL/ASYMMETRICAL. If symmetrical, comparison values are updated when the counter reachs 0. If asymmetrical, comparison values are updated both at 0 and period of the counter | |
intSel,: | CTR_ZERO/CTR_PRD. Call the ISR when the counter reach 0 or when the counter reach the period. | |
switchLogic,: | POS_LOGIC/NEG_LOGIC. Select logic for the drived switch |
void InitTzGpio | ( | void | ) |
Configure needed GPIO ports to be used by EPWM Trip-zone submodule. Affected GPIO inputs are: TZ1: GPIO12 TZ2: GPIO13 TZ3: GPIO14 TZ4: GPIO15 TZ5: GPIO16 TZ6: GPIO17 Actions taken:
static void SetEnablePWMInput | ( | Uint16 * | input | ) | [inline, static] |
static void UpdateHRPWM | ( | ePWMenum | PWM, | |
_iq | cmp | |||
) | [inline, static] |
static void UpdatePWM3ph | ( | _iq | vas, | |
_iq | vbs, | |||
_iq | vcs, | |||
char | saturate | |||
) | [inline, static] |
(pwmConf.cmp1) = (Uint16)(_IQtoF(_IQmpy(vas,pwmConf.OFFSETPWMDIVVBUS))+pwmConf.OFFSETPWM); (pwmConf.cmp2) = (Uint16)(_IQtoF(_IQmpy(vbs,pwmConf.OFFSETPWMDIVVBUS))+pwmConf.OFFSETPWM); (pwmConf.cmp3) = (Uint16)(_IQtoF(_IQmpy(vcs,pwmConf.OFFSETPWMDIVVBUS))+pwmConf.OFFSETPWM);
(pwmConf.cmp1) = (Uint16)(_IQtoF(_IQmpy(vas,pwmConf.OFFSETPWMDIVVBUS))); (pwmConf.cmp2) = (Uint16)(_IQtoF(_IQmpy(vbs,pwmConf.OFFSETPWMDIVVBUS))); (pwmConf.cmp3) = (Uint16)(_IQtoF(_IQmpy(vcs,pwmConf.OFFSETPWMDIVVBUS)));
static void UpdatePWMA3ph | ( | _iq | vas, | |
_iq | vbs, | |||
_iq | vcs, | |||
char | saturate | |||
) | [inline, static] |
Update EPWMA configured for thee phase systems
vas | voltage for phase a | |
vbs | voltage for phase b | |
vcs | voltage for phase c | |
saturate | saturate to Vbus/2 |
(pwmAConf.cmp1) = (Uint16)(_IQtoF(_IQmpy(vas,pwmAConf.OFFSETPWMDIVVBUS))); (pwmAConf.cmp2) = (Uint16)(_IQtoF(_IQmpy(vbs,pwmAConf.OFFSETPWMDIVVBUS))); (pwmAConf.cmp3) = (Uint16)(_IQtoF(_IQmpy(vcs,pwmAConf.OFFSETPWMDIVVBUS)));
static void UpdatePWMADuty3ph | ( | _iq | vad, | |
_iq | vbd, | |||
_iq | vcd | |||
) | [inline, static] |
update EPWMA duty for three phase configuration: cmpX = 2*OFFSETPWM(1 - vXd) vXd = [0,1]
vad | duty for phase a | |
vbd | duty for phase b | |
vcd | duty for phase c |
(pwmAConf.cmp1) = (Uint16)((pwmAConf.OFFSETPWM << 1) - _IQ16toF(_IQ16mpy(_IQtoIQ16(vad),(_IQ16(pwmAConf.OFFSETPWM << 1))))); (pwmAConf.cmp2) = (Uint16)((pwmAConf.OFFSETPWM << 1) - _IQ16toF(_IQ16mpy(_IQtoIQ16(vbd),(_IQ16(pwmAConf.OFFSETPWM << 1))))); (pwmAConf.cmp3) = (Uint16)((pwmAConf.OFFSETPWM << 1) - _IQ16toF(_IQ16mpy(_IQtoIQ16(vcd),(_IQ16(pwmAConf.OFFSETPWM << 1)))));
static void UpdatePWMB3ph | ( | _iq | vas, | |
_iq | vbs, | |||
_iq | vcs, | |||
char | saturate | |||
) | [inline, static] |
Update EPWMB configured for thee phase systems
vas | voltage for phase a | |
vbs | voltage for phase b | |
vcs | voltage for phase c | |
saturate | saturate to Vbus/2 |
(pwmBConf.cmp1) = (Uint16)(_IQtoF(_IQmpy(vas,pwmBConf.OFFSETPWMDIVVBUS))); (pwmBConf.cmp2) = (Uint16)(_IQtoF(_IQmpy(vbs,pwmBConf.OFFSETPWMDIVVBUS))); (pwmBConf.cmp3) = (Uint16)(_IQtoF(_IQmpy(vcs,pwmBConf.OFFSETPWMDIVVBUS)));
static void UpdatePWMBDuty3ph | ( | _iq | vad, | |
_iq | vbd, | |||
_iq | vcd | |||
) | [inline, static] |
update EPWMB duty for three phase configuration: cmpX = 2*OFFSETPWM(1 - vXd) vXd = [0,1]
vad | duty for phase a | |
vbd | duty for phase b | |
vcd | duty for phase c |
static void UpdatePWMDuty3ph | ( | _iq | vad, | |
_iq | vbd, | |||
_iq | vcd | |||
) | [inline, static] |
volatile Uint16* cmpPtr[PWM_OUTPUTS_SIZE] |
struct EPWM_REGS* ePWM[] |
int MEP_ScaleFactor[PWM_CH] |
struct PWM3phConfiguration pwmAConf pwmBConf |
struct PWM3phConfiguration pwmConf |