This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/UCD3138064EVM-166: UCD3138064EVM-166

Part Number: UCD3138064EVM-166

Tool/software: TI C/C++ Compiler

I want to generate PWM signal in PWM pin 2A and 3A depending on the sensing signal in ADC05. The program required is such that when sensed signal in pin ADC05>1 then PIN 2A generate high frequency signal and PIN 3A should be high. Similarly, when ADC05<=1 then PIN 3A generate high frequency signal and PIN 2A should be high. I am not able to generate expected signal and including my program below, please help me to solve the problem.

void init_dpwm2(void)
{
Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable everything
Dpwm2Regs.DPWMCTRL0.bit.CLA_EN = 1;
Dpwm2Regs.DPWMCTRL1.bit.GPIO_A_EN = 1; //turn off DPWM2A for now
Dpwm2Regs.DPWMCTRL1.bit.GPIO_B_EN = 1; //turn off DPWM2B for now
// Enable CBC and Blanking windows
Dpwm2Regs.DPWMCTRL0.bit.MULTI_MODE_CLA_A_OFF = 1; // Enable cycle by cycle current limit.
Dpwm2Regs.DPWMCTRL0.bit.BLANK_A_EN = 1; // Enable blanking
Dpwm2Regs.DPWMBLKABEG.all = 0x0000;
Dpwm2Regs.DPWMBLKAEND.all = 0x0500;
Dpwm2Regs.DPWMFLTCTRL.bit.A_MAX_COUNT = 2;
Dpwm2Regs.DPWMFLTCTRL.bit.ALL_FAULT_EN = 1; //enable this for OVP
Dpwm2Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable sample trigger1
Dpwm2Regs.DPWMCTRL0.bit.PWM_MODE = 2; //triangular mode
Dpwm2Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN = 1; //slave mode
Dpwm2Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update right away

Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 1;

}

void init_dpwm3(void)
{
Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable everything
Dpwm3Regs.DPWMCTRL0.bit.CLA_EN = 1;
Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_EN = 1; //turn off DPWM2A for now
Dpwm3Regs.DPWMCTRL1.bit.GPIO_B_EN = 1; //turn off DPWM2B for now
// Enable CBC and Blanking windows
Dpwm3Regs.DPWMCTRL0.bit.MULTI_MODE_CLA_A_OFF = 1; // Enable cycle by cycle current limit.
Dpwm3Regs.DPWMCTRL0.bit.BLANK_A_EN = 1; // Enable blanking
Dpwm3Regs.DPWMBLKABEG.all = 0x0000;
Dpwm3Regs.DPWMBLKAEND.all = 0x0500;
Dpwm3Regs.DPWMFLTCTRL.bit.A_MAX_COUNT = 2;
Dpwm3Regs.DPWMFLTCTRL.bit.ALL_FAULT_EN = 1; //enable this for OVP
Dpwm3Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable sample trigger1
Dpwm3Regs.DPWMCTRL0.bit.PWM_MODE = 2; //triangular mode
Dpwm3Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN = 1; //slave mode
Dpwm3Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update right away

Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 1;

}

void standard_interrupt(void)
{


poll_adc();
rectify_vac();
Ic = 0.0;
AdcRegs.ADCCTRL.bit.SW_START=0;

Ic = AdcRegs.ADCAVGRESULT[5].all;
AdcRegs.ADCCTRL.bit.SW_START = 1; //RESTART
LoopMuxRegs.FILTERMUX.bit.FILTER1_FE_SEL = 0; //use EADC2 to drive filter 1

Dpwm2Regs.DPWMCTRL1.bit.GPIO_A_EN = 1;
Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_EN = 1;
LoopMuxRegs.FILTERMUX.bit.FILTER1_FE_SEL = 0; //use EADC2 to drive filter 1

if(Ic<0.987)
{
Dpwm2Regs.DPWMCTRL1.bit.GPIO_A_EN = 0; //now turn on neutral PWM
Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_VAL = 1; //and then drive line always high
}
else
{
Dpwm2Regs.DPWMCTRL1.bit.GPIO_A_VAL = 1; //line drive low
Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_EN = 0; //now disable neutral PWM
}

}

  • Also, I think the sensed parameter "Ic" does not read correctly. Is it initialization problem or something else. Please help.
  • Hi, Moumita,

    Please try the below code: 

    if(Ic<0.987)
    {
    Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_EN = 0; //now turn on neutral PWM

    Dpwm2Regs.DPWMCTRL1.bit.GPIO_A_EN =1;
    Dpwm2Regs.DPWMCTRL1.bit.GPIO_A_VAL = 1; //and then drive line always high
    }
    else if (Ic>1)
    {

    Dpwm2Regs.DPWMCTRL1.bit.GPIO_A_EN =0;
    Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_VAL = 1; //line drive low
    Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_EN = 1; //now disable neutral PWM
    }

    Please let me know if it works.

    Thanks,
    Sean

  • Thank you for your kind reply, but it is not working. It seems Ic is set to one fixed value . Therefore, PWM 2A operating in high frequency mode and PWM 3A is ON.
  • The value of Ic is not updating.
  • You can look at the function poll_adc(), and make sure ADC is re-triggered and the results are updated.
  • Thank you for your kind reply. I am giving below my poll_adc function, please let me know whether this is ok or not. Thank you.

    void poll_adc(void)
    {
    if(AdcRegs.ADCSTAT.bit.ADC_INT==1)//If the conversion is not complete
    {
    Ic= AdcRegs.ADCRESULT[5].bit.RESULT;
     Ic = AdcRegs.ADCAVGRESULT[5].bit.RESULT;
    }
    AdcRegs.ADCCTRL.bit.SW_START = 1; //RESTART
    AdcRegs.ADCCTRL.bit.SW_START = 0;

    }

  • Whether your above routine works or not depends also on:

    1) How often you call this function

    2) How the ADC sequence initialization look like.

    If you call this function from your standard interrupt that is called every 20 micro seconds or so, then you do not even need the if(AdcRegs.ADCSTAT.bit.ADC_INT==1) condition.

    But it seems like you read from the raw result register and then it is overwritten by the average result. That looks odd.

    Also you should be aware that average result changes slowely and have bad results at powerup.

    Send us the the ADC_poll init routine.

    Regards,

  • Thanks a lot for your reply. I am sending you the code as belo:

    void init_ADC_polled(void)
    {
    // MiscAnalogRegs.TEMPSENCTRL.bit.TEMP_SENSE_DIS = 0;
    AdcRegs.ADCCTRL.bit.SAMPLING_SEL = 6;

    AdcRegs.ADCCTRL.bit.MAX_CONV = 8; //Set up to measure 9 different items

    AdcRegs.ADCCTRL.bit.SINGLE_SWEEP = 1; //Use single sweep mode

    AdcRegs.ADCSEQSEL0.bit.SEQ0 = 3; //VO_SENSE
    AdcRegs.ADCSEQSEL0.bit.SEQ1 = 13; //IO_SENSE
    AdcRegs.ADCSEQSEL0.bit.SEQ2 = 12; //TEMP
    AdcRegs.ADCSEQSEL0.bit.SEQ3 = 6; //VIN_MON
    AdcRegs.ADCSEQSEL1.bit.SEQ4 = 2; //ISHARE
    AdcRegs.ADCSEQSEL1.bit.SEQ5 = 5; //VO OVP
    AdcRegs.ADCSEQSEL1.bit.SEQ6 = 4; //IPS0
    AdcRegs.ADCSEQSEL1.bit.SEQ7 = 0; //ADDRESS
    AdcRegs.ADCSEQSEL2.bit.SEQ8 = 15; //DEVICE TEMP

    AdcRegs.ADCAVGCTRL.bit.AVG0_EN = 1; //Enable averaging
    AdcRegs.ADCAVGCTRL.bit.AVG1_EN = 1; //Enable averaging
    AdcRegs.ADCAVGCTRL.bit.AVG2_EN = 1; //Enable averaging
    AdcRegs.ADCAVGCTRL.bit.AVG3_EN = 1; //Enable averaging
    AdcRegs.ADCAVGCTRL.bit.AVG4_EN = 1; //Enable averaging
    AdcRegs.ADCAVGCTRL.bit.AVG5_EN = 1; //Enable averaging

    AdcRegs.ADCAVGCTRL.bit.AVG0_CONFIG = 0;//0-4x average, 1-8x average, 2-16x average, 3-32x average
    AdcRegs.ADCAVGCTRL.bit.AVG1_CONFIG = 3;//0-4x average, 1-8x average, 2-16x average, 3-32x average
    AdcRegs.ADCAVGCTRL.bit.AVG2_CONFIG = 3;//0-4x average, 1-8x average, 2-16x average, 3-32x average
    AdcRegs.ADCAVGCTRL.bit.AVG3_CONFIG = 3;//0-4x average, 1-8x average, 2-16x average, 3-32x average
    AdcRegs.ADCAVGCTRL.bit.AVG4_CONFIG = 3;//0-4x average, 1-8x average, 2-16x average, 3-32x average
    AdcRegs.ADCAVGCTRL.bit.AVG5_CONFIG = 3;//0-4x average, 1-8x average, 2-16x average, 3-32x average;

    AdcRegs.ADCCTRL.bit.ADC_EN = 1; //Enable ADC

    AdcRegs.ADCCTRL.bit.SW_START = 1; //Send start bit high
    AdcRegs.ADCCTRL.bit.SW_START = 0; //Send start bit low
    }
  • The code is good.
    Is the ADC enabled? Is the adc interrupt is enabled? Also, make sure the sequence is configured properlyin init_adc12.c.
  • Is the signal that you are interested in connecyed to AD05?
    That is VO OVP according to your comments
  • Hi Moumita. Any comments? Is the issue still pending?
  • Yes this signal is connected to AD05. However, it is not for VO OVP, this comment is wrong in the program.
  • 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;

    }