Tool/software: TI C/C++ Compiler
Can anyone please help me to generate pulses in pins DPWM0B and DPWM1B using sensed parameter value. I am including my program below please help me to find out problem in this.
// Initialization
void init_dpwm0(void)
{
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm0Regs.DPWMCTRL0.bit.CLA_EN = 0; //default is 1 - use cla
Dpwm0Regs.DPWMCTRL0.bit.PWM_MODE = 3; //normal mode
Dpwm0Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.
Dpwm0Regs.DPWMEV1.all = 0; // Place EV1 at 132 nS, just out of event update window
Dpwm0Regs.DPWMEV2.all = PERIOD/2; // Does not really matter if you do not use B output
Dpwm0Regs.DPWMEV3.all = PERIOD/2 ; // Does not really matter if you do not use B output
Dpwm0Regs.DPWMEV4.all = PERIOD; // Does not really matter if you do not use B output
Dpwm0Regs.DPWMSAMPTRIG1.all = (PERIOD*3)/4; //500 nS before the end 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.MSYNC_SLAVE_EN =0; // DPWm0 is master
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
}
void init_dpwm1(void)
{
Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm1Regs.DPWMCTRL0.bit.CLA_EN = 0; //default is 1 - use cla
Dpwm1Regs.DPWMCTRL0.bit.PWM_MODE = 3; //normal mode
Dpwm1Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.
Dpwm1Regs.DPWMEV1.all = 0; // Place EV1 at 132 nS, just out of event update window
Dpwm1Regs.DPWMEV2.all = PERIOD/2; // Does not really matter if you do not use B output
Dpwm1Regs.DPWMEV3.all = PERIOD/2; // Does not really matter if you do not use B output
Dpwm1Regs.DPWMEV4.all = PERIOD; // Does not really matter if you do not use B output
Dpwm1Regs.DPWMSAMPTRIG1.all = (PERIOD*3)/4; //500 nS before the end of period
Dpwm1Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
Dpwm1Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN =0; // DPWm1 is slave
LoopMuxRegs.DPWMMUX.bit.DPWM1_SYNC_SEL =0;//DPWm1 is a slave, sync with DPWM0
Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
}
// Conditions
void poll_adc(void)
{
if(AdcRegs.ADCSTAT.bit.ADC_INT==1)//If the conversion is not complete
{
Ic= AdcRegs.ADCRESULT[3].all;
AdcRegs.ADCCTRL.bit.SW_START = 1; //RESTART
}
}
void rectify_vac(void)
{
t1=Ic;
t2 = (1.2/2.5)*0xfff;
t4 = (0.95/2.5)*0xfff;
t3=(0.1/2.5)*0xfff;
Dpwm0Regs.DPWMCTRL1.bit.GPIO_B_EN = 1;
Dpwm1Regs.DPWMCTRL1.bit.GPIO_B_EN = 1;
Dpwm0Regs.DPWMCTRL1.bit.GPIO_B_VAL = 0;
Dpwm1Regs.DPWMCTRL1.bit.GPIO_B_VAL = 0;
if(t4>=t1>=t2)
{
if(t1>=t2)
{
Dpwm0Regs.DPWMCTRL1.bit.GPIO_B_EN = 0; //now turn on neutral PWM
Dpwm1Regs.DPWMCTRL1.bit.GPIO_B_VAL = 1; //and then drive line always high
}
else
{
Dpwm1Regs.DPWMCTRL1.bit.GPIO_B_EN =0;
Dpwm0Regs.DPWMCTRL1.bit.GPIO_B_VAL = 1; //line drive low
}
}
else
{
Dpwm0Regs.DPWMCTRL1.bit.GPIO_B_EN = 0;
Dpwm1Regs.DPWMCTRL1.bit.GPIO_B_EN = 0;
Dpwm0Regs.DPWMCTRL1.bit.GPIO_B_VAL = 0;
Dpwm1Regs.DPWMCTRL1.bit.GPIO_B_VAL = 0;
}
}