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.

RTOS: PWM generation in ICEv2

Other Parts Discussed in Thread: AM3359

Tool/software: TI-RTOS

Hi,

I am using AM3359 ICE v2.1A + SDK - ti-RTOS + PRU-ICSS-EtherCAT_Slave_01.00.05.00. and example ethercat application.

I need to use the PWMSS module.

I found three example codes in the SDK

/ti/pdk_am335x_1_0_8/packages/ti/csl/example/epwm

/ti/pdk_am335x_1_0_8/packages/ti/starterware/examples/epwm

/ti/pdk_am335x_1_0_8/packages/ti/board/diag/pwm

1. What is the difference between these examples?

2. Which example should I port to my AM3359 ICE? 

  • Hi DIJO,

    1. The CSL epwm example "sets a particular duty cycle in PWMSS1 output A (EHRPWM1A) which can be verified through external pin probing".
    The Starterware epwm example demonstrates the use of EPWM (APIs) to rotate the haptics motor.
    The diag epwm example validats the CSL functional layer APIs for EPWM module - "This tests demonstrate the usage of PWM CSL FL APIs by
    configuring the PWM module to generate a pulse of 1KHz with different duty cycle - 25, 50 and 75%."

    2. Depends on your application, you may start with diag epwm example first and then evolve with more feature if needed.

    Regards,
    Garrett
  • Hi,

    Thanks for the fast reply. I tried the diag epwm example and was able to successfully generate a 1 KHz PWM.
    I need to control a servo motor, so I was trying to generate a 50 Hz PWM with the example. However it was seen that any thing below 500Hz was not possible with the example.

    Is there any additional clock configuration required for generating a lower freq PWM?
  • DIJO,

    The PWM diag is tested on the boards listed here processors.wiki.ti.com/.../Processor_SDK_RTOS_DIAG . Did you port it to AM3359 ICE or use the .out file built for evmAM335x? Which pin were you measuring on the ICE board? And do you modify the #define PWM_FREQ (1000)/*1KHz*/ for other frequency?

    evmK2G - J12 pin 33
    evmAM572x - P17 pin 5
    idkAM437x - J16 pin 14
    evmAM335x - J5 pin 13

    Regards,
    Garrett
  • I ported the example to my AM5559 ICE. The changes I made are as follows

    I tried to set EHRPWM2A on (GPMC_AD8) of Host Expansion Connector 1- J4

    /*Module clock is the frequency of PWMSS operates*/
    #define MODULE_CLK (100000000)/*100MHz*/
    #define PWM_BASE_ADDRESS (SOC_PWMSS2_REG)
    #define DELAY (9000000)

    #endif

    #define TBCLK_FREQ (MODULE_CLK/4)
    #define PWM_FREQ (50)/*50Hz*/


    /* Enables clock for PWM module */
    void BoardDiag_pwmClockConfig(void)
    {
    #if defined(evmAM335x)

    /* Enable PRCM for PWMSS2 */
    HW_WR_REG32((SOC_CM_PER_REGS + CM_PER_EPWMSS2_CLKCTRL), 0x02);

    /* Enable the PWM clock using the PMWSS2 CLKCONFIG Register*/
    HW_WR_REG32((PWM_BASE_ADDRESS + PWMSS_CLKCONFIG), 0x100);

    /* Time base clock for PWMSS2 module */
    HW_WR_REG32((SOC_CONTROL_REGS + CONTROL_PWMSS_CTRL), 0x4);

    }


    /* Configures pinmux for PWM module */
    void BoardDiag_pwmPinmuxConfig(void)
    {
    uint32_t regVal;

    #if defined(evmAM335x)

    /* Channel A*/
    regVal = HW_RD_REG32(SOC_CONTROL_REGS + CONTROL_CONF_GPMC_AD(8));
    regVal = ((regVal & ~0x0F) | 0x04);
    HW_WR_REG32(SOC_CONTROL_REGS + CONTROL_CONF_GPMC_AD(8), regVal);

    }

    Then called
    BoardDiag_pwmInit(PWM_BASE_ADDRESS);
    BoardDiag_pwmConfig(PWM_BASE_ADDRESS, 5); // 5% duty cycle



    Am I missing something here?
  • Hi,

    I made the following changes to the code

    #define TBCLK_FREQ (MODULE_CLK/100) --> changed TBCLK_FREQ to 1MHz

    now counter takes 1us for each count
    ie 65536us for the 16 bit counter

    for a 50Hz PWM (20 ms) 20000us --> TBPRD = 20000

    However the DSO output showed 90Hz
    TBCLK_FREQ = (MODULE_CLK/32) gave 56Hz

    How to achieve exactly 50Hz?
  • DIJO,

    Can you try to update the duty cycle to 50% instead of 5%?
    BoardDiag_pwmConfig(PWM_BASE_ADDRESS, 50); // 50% duty cycle

    From PCCTL Register defintion:
    10-8 CHPDUTY R/W 0h Chopping Clock Duty Cycle
    0h (R/W) = Duty = 1/8 (12.5%)
    1h (R/W) = Duty = 2/8 (25.0%)
    2h (R/W) = Duty = 3/8 (37.5%)
    3h (R/W) = Duty = 4/8 (50.0%)
    4h (R/W) = Duty = 5/8 (62.5%)
    5h (R/W) = Duty = 6/8 (75.0%)
    6h (R/W) = Duty = 7/8 (87.5%)
    7h (R/W) = Reserved.

    Regards,
    Garrett