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/CC2650: CC2650

Part Number: CC2650

Tool/software: TI-RTOS

goodmorning,

Could you show me how to use PWM in PWM_DUTY_FRACTION mode. I tried but it seem not to work. thank you!

here is my config:

void pwm_demo(UArg arg0, UArg arg1)
{
//uint16_t pwmPeriod = 1000; 
//uint16_t pwmfrequences = 1000; peirod in Hz
uint16_t duty = 0; // %
uint16_t dutyInc = 2.5; // %

PWM_Params_init(&pwmParams);
pwmParams.periodUnits = PWM_PERIOD_HZ;
pwmParams.periodValue = 1e3;
pwmParams.dutyUnits = PWM_DUTY_FRACTION;// mode fraction doesn't work, but PWM_DUTY_US mode has worked normally.
.pwmParams.dutyValue = 0;
pwmParams.idleLevel = PWM_IDLE_HIGH;
pwmHandle = PWM_open(Board_PWM1, &pwmParams);

if (pwmHandle == NULL) {
System_abort("Board_PWM1 did not open");
}

PWM_start(pwmHandle);

while (1) {
PWM_setDuty(pwmHandle, duty);

duty = duty + dutyInc; // increase the duty 2.5% each time
  if (duty == 100 || duty == 0) {
      dutyInc = - dutyInc;
  }
  Task_sleep(5000);
 }
}

  • Hello,

    Please take a look at the PWM_LED example available in the TI-RTOS for the CC2650 v2.21.01.xx

    dev.ti.com/.../

    Best regards,

    David
  • I took a look at that before building my project, but my problem is:

         when I use duty in US, my function run correctly,

         when I use duty in FRACTION, my function only work if I don't use PWM_setDuty(); .My func like this:

                   

    void pwm_demo(UArg arg0, UArg arg1)
    {
    uint16_t pwmfrequences = 1000;

    uint16_t duty = 0;
    uint16_t dutyInc = 2.5;

    PWM_Params_init(&pwmParams);
    pwmParams.periodUnits = PWM_PERIOD_HZ;
    pwmParams.periodValue = 1e3;
    pwmParams.dutyUnits = PWM_DUTY_FRACTION;// mode fraction doesn't work
    pwmParams.dutyValue = 20; //%
    pwmParams.idleLevel = PWM_IDLE_HIGH;
    pwmHandle = PWM_open(Board_PWM1, &pwmParams);

    if (pwmHandle == NULL) {
    System_abort("Board_PWM1 did not open");
    }

    PWM_start(pwmHandle);

    }

    => my led is dim because I set duty value  = 20% right.

         and when I add this:

    while(1)
    {
    PWM_setDuty(pwmHandle, duty);

    duty = duty + dutyInc;
    if(duty == 100 || duty == 0)
    dutyInc = -dutyInc;
    Task_sleep(5000);
    }

    with dutyInc = 2.5; //%

           duty = 0;

    =>  my led is not toggle anymore and I don't know why.

  • Hello,

      PWM_DUTY_FRACTION: The duty is in a fractional part of the period where 0 is 0% and PWM_DUTY_FRACTION_MAX is 100%. Therefore, try the following:

    Void pwmLEDFxn(UArg arg0, UArg arg1)
    {
        PWM_Handle pwm1;
        PWM_Params params;
        uint32_t   duty = 0;
        float percentage = 0;
    
        PWM_Params_init(&params);
        params.dutyValue = PWM_DUTY_FRACTION_MAX;
        pwm1 = PWM_open(Board_PWM0, &params);
    
        if (pwm1 == NULL) {
            System_abort("Board_PWM0 did not open");
        }
        PWM_start(pwm1);
    
        /* Loop forever incrementing the PWM duty */
        while (1) {
            duty = (percentage / 100) * PWM_DUTY_FRACTION_MAX;
            PWM_setDuty(pwm1, duty);
            Task_sleep((UInt) arg0);
            percentage += 1;
    
            if (percentage > 100)
            {
                percentage = 0;
            }
        }
    }

    Hopefully this helps.

      David

  • Thank you so much David, I copied your function into my program but it didn't work, the led was not dim

    I don;t know if it because of hardware or not,   PWM_DUTY_US is still ok.