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/tm4c123gh6pm: PWM Multiple Frequencies Problem

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: TM4C123GH6PM

Tool/software: TI-RTOS

Hello, I am using TI-RTOS PWM.C and PWMTiva.C to set up some PWM outputs.

I need 20khz and then 200hz frequencies.

It seems like when I initiate one the other frequency gets shifted up and the range of frequencies i have is about 2khz to 20khz or 200 to 2khz

I need 200hz for some servos and 20khz for a motor and I am wondering how I can achieve this with the TI-RTOS api.


	PWM_Params params1;
	uint16_t pwmPeriod = 5000;      // Period and duty in microseconds
	PWM_Params_init(&params1);
	params1.period = pwmPeriod;
	params1.dutyMode =  PWM_DUTY_SCALAR;
	pwm_distance_level = PWM_open(2, &params1);
	if (pwm_distance_level == NULL) {
		System_abort("Board_PWM0 did not open");
	}
	pwm_top_pitch = PWM_open(3, &params1);
	if (pwm_top_pitch == NULL) {
		System_abort("Board_PWM0 did not open");
	}
	pwm_top_yaw = PWM_open(4, &params1);
	if (pwm_top_yaw == NULL) {
		System_abort("Board_PWM0 did not open");
	}
	PWM_setDuty(pwm_distance_level, DISTANCE_LEVEL_HOME);
	PWM_setDuty(pwm_top_pitch, CAMERA_TILT_HOME);
	PWM_setDuty(pwm_top_yaw, CAMERA_TURN_HOME);

PWM_Handle pwm1;
	    PWM_Handle pwm2;
	    PWM_Params params;
	    uint16_t   pwmPeriod = 50;      // Period and duty in microseconds
	    uint16_t   duty = 0;
	    PWM_Params_init(&params);
	    params.period = pwmPeriod;
	    params.dutyMode = PWM_DUTY_SCALAR;
	    pwm1 = PWM_open(Board_PWM0, &params);
	    if (pwm1 == NULL) {
	        System_abort("Board_PWM0 did not open");
	    }
	    if (Board_PWM1 != Board_PWM0) {
	        pwm2 = PWM_open(Board_PWM1, &params);
	        if (pwm2 == NULL) {
	            System_abort("Board_PWM1 did not open");
	        }
	    }



Any help would be appreciated thanks.

  • Hi Chris,

    Try using PWM signals with different PWM generators for your 200Hz and 20KHz frequencies.  See this diagram:

    Best regards,

    Janet

  • I am using PF2 and PF3 as the 20khz

    Then PE4 and PE5 and PB6 as the 200hz signals.

    PF2 and PF3 say in the data sheet they are module 1- PWM generator 3

    PB6 is Module 0- PWM Generator 0

    PE4 and PE5 say they are module 0 and PWM generator 2

    which is initially why I was wondering why I had a conflict

    sorry I should have posted the pins I was using in the first post.
  • I still haven't been able to figure out how to get the PWM inputs to be output at 200hz and 20khz

    PE4 and PE5 and PB6 I need as 200hz  and PF2 and PF3 as 20khz

    I use the TI-RTOS PWM.C and PWMTiva.C but it seems that it rewrites all the PWM clocks when I call PWM_open
    I am kinda confused how I can edit this to make it only right to the specific generator/module for the PWM signal
    I want to open.

    Any help would be appreciated or if I should just instantiate PWM signals with non TI-RTOS API

    #include <ti/drivers/PWM.h>
    #include <ti/drivers/pwm/PWMTiva.h>
    
    PWMTiva_Object pwmTivaObjects[EK_TM4C123GXL_PWMCOUNT];
    
    const PWMTiva_HWAttrs pwmTivaHWAttrs[EK_TM4C123GXL_PWMCOUNT] = {
        {
            .baseAddr = PWM1_BASE,
            .pwmOutput = PWM_OUT_6,
            .pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
        },
        {
            .baseAddr = PWM1_BASE,
            .pwmOutput = PWM_OUT_7,
            .pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
        },
        {
        	.baseAddr = PWM0_BASE,
        	.pwmOutput = PWM_OUT_3,
        	.pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
        },
        {
        	.baseAddr = PWM0_BASE,
        	.pwmOutput = PWM_OUT_4,
        	.pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
        },
        {
          	.baseAddr = PWM0_BASE,
          	.pwmOutput = PWM_OUT_5,
          	.pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
        }
    };
    
    const PWM_Config PWM_config[] = {
        {
            .fxnTablePtr = &PWMTiva_fxnTable,
            .object = &pwmTivaObjects[0],
            .hwAttrs = &pwmTivaHWAttrs[0]
        },
        {
            .fxnTablePtr = &PWMTiva_fxnTable,
            .object = &pwmTivaObjects[1],
            .hwAttrs = &pwmTivaHWAttrs[1]
        },
    	{
    	    .fxnTablePtr = &PWMTiva_fxnTable,
    	    .object = &pwmTivaObjects[2],
    	    .hwAttrs = &pwmTivaHWAttrs[2]
    	},
    	{
    	.fxnTablePtr = &PWMTiva_fxnTable,
    	.object = &pwmTivaObjects[3],
    	.hwAttrs = &pwmTivaHWAttrs[3]
    	},
    	{
    	.fxnTablePtr = &PWMTiva_fxnTable,
    	.object = &pwmTivaObjects[4],
    	.hwAttrs = &pwmTivaHWAttrs[4]
    	},
        {NULL, NULL, NULL}
    };
    
    /*
     *  ======== EK_TM4C123GXL_initPWM ========
     */
    void EK_TM4C123GXL_initPWM(void)
    {
        /* Enable PWM peripherals */
        SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
        /*
         * Enable PWM output on GPIO pins.  Board_LED1 and Board_LED2 are now
         * controlled by PWM peripheral - Do not use GPIO APIs.
         */
        GPIOPinConfigure(GPIO_PF2_M1PWM6);
        GPIOPinConfigure(GPIO_PF3_M1PWM7);
        GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 |GPIO_PIN_3);
    
        GPIOPinConfigure(GPIO_PB5_M0PWM3);
        GPIOPinConfigure(GPIO_PE4_M0PWM4);
        GPIOPinConfigure(GPIO_PE5_M0PWM5);
        GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_4 |GPIO_PIN_5);
        GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
        PWM_init();
    }

  • Hi Chris,
    Can you please *attach* (not copy paste) your test case? I'd like to see the board.c file and the code where you open the PWM objects.
    Thanks,
    Janet
  • Hi Janet,

    I have attached the Board.C which is EK_TM4C123GXL and the two places I call the PWM_open functions.

    In project Main I call the PWM open in the PWM task and that is for the 20khz signals

    In camera control I call the function for the 200hz signals.

    It seems that whatever one gets called last takes precedence and the other signal is shifted up or down.
    2146.EK_TM4C123GXL.c1588.project_main.c2845.camera_control.c

  • Hi Chris,

    We looked into the TM4C123GH6PM data sheet and found ths:

    So the last PWM you open would override the previously set PWM clock divider.  You might be able to use the PWMTimerTiva for your servos.  This driver implements PWM on top of the LM4 timers.

    Best regards,

    Janet

  • Thank you.

    I'll look into setting up the other PWM signals with the PWMTimerTIva.