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.

CC2650: PWM with a frequency of less than 700 kHz?

Part Number: CC2650

I use the following code to set the PWM with the correct frequency and fill. However, it does not work if I set the frequency to less than 700 kHz.
How can I set the timer so that the PWM frequency is, for example, 300kHz? 100kHz?

void pwm_set(uint32_t freq, uint8_t duty_percent)
{
   ti_lib_timer_disable(GPT0_BASE, TIMER_A);
   ti_lib_ioc_port_configure_set(PWM_GPIO, IOC_PORT_MCU_PORT_EVENT0, IOC_STD_OUTPUT);
   ti_lib_timer_configure(GPT0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);

   uint32_t interval_load, interval_match;
   uint32_t match_divider = 100*100 / duty_percent;

   interval_load = GET_MCU_CLOCK / freq;
   interval_match = ((interval_load * 100) / match_divider);

   ti_lib_timer_load_set(GPT0_BASE, TIMER_A, interval_load);
   ti_lib_timer_match_set(GPT0_BASE, TIMER_A, interval_match);
   ti_lib_timer_enable(GPT0_BASE, TIMER_A);
}

  • Hi vvzvlad,

    Assuming your sdk version is 2_02_01_18, there is a PWM driver available to use that is documented in the following file path of the SDK:  C:/ti/tirtos_cc13xx_cc26xx_2_20_01_08/products/tidrivers_cc13xx_cc26xx_2_20_01_10/docs/doxygen/html/_p_w_m_timer_c_c26_x_x_8h.html

    I highly suggest you look over this driver documentation. The information here will let you now what files to include and provides a PWN usage example.

    Based on the example provided in the documentation, I was able to achieve a ~300 kHz frequency using the following code:

    Void pwmFxn(UArg arg0, UArg arg1)
    {
    	PWM_Handle hPWM;
    	PWM_Params pwmParams;
    	PWM_Params_init(&pwmParams);
    	pwmParams.idleLevel  = PWM_IDLE_LOW;
    
    	/* PWM in Hz with period in Hz */
    	pwmParams.periodUnits  = PWM_PERIOD_HZ;
    	pwmParams.periodValue = 3e5;
    	pwmParams.dutyUnits    = PWM_DUTY_FRACTION;
    	pwmParams.dutyValue   = PWM_DUTY_FRACTION_MAX/2;
    
    	hPWM = PWM_open(CC2650_PWM0, &pwmParams);
    
    	if(hPWM == NULL) {
    		Log_error0("Opening PWM failed");
    		while(1);
    	}
    
    	PWM_start(hPWM);
    }

    -Sy Su