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.

Getting EPWM to generate PWM

Other Parts Discussed in Thread: HALCOGEN

I can't get the EPWM to generate any output.  I can't even get TBCTR to count at all.  I used HalCoGen to generate initialization code with the ETPWM1A and ETPWM1B pins enabled in the PINMUX driver.  I have tried many different things, but nothing works.  Here is my current initialization code:

    pinMuxReg->PINMMR37 |= 0x100; // Enable clocks EPWM1
    pinMuxReg->PINMMR37 &= ~2; // Disable time base
    etpwmREG1->TBPRD = 4000;
    etpwmREG1->CMPA = 2000;
    etpwmREG1->CMPB = 1000;
    etpwmREG1->TBCTL = 0x30;
    etpwmREG1->CMPCTL = 0x00; // Immediate load of CMPA
    etpwmREG1->AQCTLA = 0x24; // Set on CMPA, clear on PRD
    etpwmREG1->AQCTLB = 0x24; // Set on CMPA, clear on PRD
    etpwmREG1->TZCTL = 0xFFF; // Disable all trip zones
    etpwmREG1->TZCLR = 0x3F;  // Clear all trip zones
    etpwmREG1->DBRED = 0;
    etpwmREG1->DBFED = 0;
    etpwmREG1->PCCTL = 0;
    pinMuxReg->PINMMR37 |= 2; // Enable time base

Any ideas on why TBCTR isn't counting?  I see a lot of references to VCLK4 but don't see any programming information or any settings in HalCoGen. 

I have also tried to force the output pins high with the following lines:

    etpwmREG1->AQSFRC = 0x6;
    etpwmREG1->AQCSFRC = 0x2;

I never see anything at the output.  Any ideas on what I'm doing wrong would be helpful.

Thank you,

Jeremy



  • Hi Jeremy,

    Please take a look at this link: http://e2e.ti.com/support/microcontrollers/hercules/f/312/t/255929.aspx

    Yes, there is issue with Halcogen generating VCLK4.  We will fix it in the next Halcogen release.

    Our TRM will be updated in the next release to specify VCLK4 division as well. 

    In the mean time, please follow the recommended programming codes to change VCLK4 in the above link.

    Hope this helps.

  • I updated the code as specified in the other thread.  I still have the same problem.  After running the above initialization code, etpwmREG1->TBCTR always reads as zero, and I'm not getting PWM output.  Can you think of anything else that might be wrong (or I might have forgotten to configure)?

    Thank you.

  • Jeremy,

    can you pls. share your Pinmux instruction to enable ETPWM1A and ETPWM1B?

  • I used HalCoGen to make the pinmux code, which is called before the initialization code I posted above.  Here is what was generated concerning EPWM:


    #define PINMUX_BALL_C1_SHIFT    0U
    #define PINMUX_BALL_E1_SHIFT    16U
    #define PINMUX_BALL_B5_SHIFT    24U
    #define PINMUX_BALL_B3_SHIFT    8U
    #define PINMUX_BALL_H3_SHIFT    16U

    #define PINMUX_BALL_C1_GIOA_2                                   (0x1U <<  PINMUX_BALL_C1_SHIFT)
    #define PINMUX_BALL_E1_GIOA_3                                   (0x1U <<  PINMUX_BALL_E1_SHIFT)
    #define PINMUX_BALL_B5_ETPWM1A                                  (0x4U <<  PINMUX_BALL_B5_SHIFT)
    #define PINMUX_BALL_B3_HET1_22                                  (0x1U <<  PINMUX_BALL_B3_SHIFT)
    #define PINMUX_BALL_H3_ETPWM1B                                  (0x4U <<  PINMUX_BALL_H3_SHIFT)


        pinMuxReg->PINMMR2 = PINMUX_BALL_C1_GIOA_2 | PINMUX_BALL_E1_GIOA_3 | PINMUX_BALL_B5_ETPWM1A;
        pinMuxReg->PINMMR3 = PINMUX_BALL_B3_HET1_22 | PINMUX_BALL_H3_ETPWM1B;


    And HalcoGen added this later on:


        PINMUX_ETPWM1_EQEPERR_ENABLE(EQEPERR12);
        PINMUX_ETPWM2_EQEPERR_ENABLE(EQEPERR12);
        PINMUX_ETPWM3_EQEPERR_ENABLE(EQEPERR12);
        PINMUX_ETPWM4_EQEPERR_ENABLE(EQEPERR12);
        PINMUX_ETPWM5_EQEPERR_ENABLE(EQEPERR12);
        PINMUX_ETPWM6_EQEPERR_ENABLE(EQEPERR12);
        PINMUX_ETPWM7_EQEPERR_ENABLE(EQEPERR12);
        PINMUX_ETPWM_TIME_BASE_SYNC_ENABLE(OFF);
        PINMUX_ETPWM_TBCLK_SYNC_ENABLE(OFF);
        PINMUX_ETPWM_TZ1_ENABLE(ASYNC);
        PINMUX_ETPWM_TZ2_ENABLE(ASYNC);
        PINMUX_ETPWM_TZ3_ENABLE(ASYNC);
        PINMUX_ETPWM_EPWM1SYNCI_ENABLE(ASYNC);

    I also tried calling the HalCoGen created function, ETPWM_init.  I have the same problems whether I run that function, or just my code above.  I have attached all of the HalCoGen created files, just in case you want to take a look at anything else in those files.

    -Jeremy

    Halcogen.zip
  • Hi Henry,

    Let me know if you have any suggestions about getting the PWM to work, or even to get TBCTR to count up.

    Thank you,

    Jeremy

  • Hi Jeremy,

    i am looking into your project.  will get back to you.

  • Hi Henry,

    I just figured this out a short while ago.  Turns out there is a sub-tab in HalcoGen (PINMUX->Special Pin Muxing), and there are two boxes that need to be checked (Enable Time Base Sync and Enable TBCLK sync).  I didn't see that tab when I went through the setup.  Also, I would have expected those options to be in the ETPWM tab.

    -Jeremy

  • Hi Jeremy,

    OK good to know that it works for you now.