Tool/software: TI C/C++ Compiler
Can you please tell me whether following initialization for four PWMs are ok or not.
void init_dpwm0(void)
{
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm0Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm0Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm0Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.
Dpwm0Regs.DPWMEV1.all = (PERIOD * 3)/5; //Put event 1 at start of period
Dpwm0Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm0Regs.DPWMEV3.all = (PERIOD)/5;//1/2 of period
Dpwm0Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm0Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period
Dpwm0Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm0Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm0Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;
}
void init_dpwm1(void)
{
Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm1Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm1Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm1Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.
Dpwm1Regs.DPWMEV1.all = (PERIOD*3)/5; //Put event 1 at start of period
Dpwm1Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm1Regs.DPWMEV3.all = (PERIOD)/5;//1/2 of period
Dpwm1Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm1Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period
Dpwm1Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm1Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm1Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;
}
void init_dpwm2(void)
{
Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm2Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm2Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm2Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.
Dpwm2Regs.DPWMEV1.all = (PERIOD * 3)/5; //Put event 1 at start of period
Dpwm2Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm2Regs.DPWMEV3.all = PERIOD/5;//1/2 of period
Dpwm2Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm2Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period
Dpwm2Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm2Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm2Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;
}
void init_dpwm3(void)
{
Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm3Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm3Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm3Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.
Dpwm3Regs.DPWMEV1.all = (PERIOD * 3)/5; //Put event 1 at start of period
Dpwm3Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm3Regs.DPWMEV3.all = (PERIOD)/5;//1/2 of period
Dpwm3Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm3Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period
Dpwm3Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm3Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm3Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;
}