Example #1
0
Void Task_PWM(UArg arg0, UArg arg1)
{
    PWM_Handle pwm[3];
    PWM_Params params;
    uint16_t   period=1500;
    uint16_t   duty[3]={0, };

    PWM_Params_init(&params);
    params.period = period; //ms
    //params.polarity = PWM_POL_ACTIVE_LOW;
    params.polarity = PWM_POL_ACTIVE_HIGH;
    //params.dutyMode = PWM_DUTY_COUNTS; 
    params.dutyMode = PWM_DUTY_SCALAR;
    //params.dutyMode = PWM_DUTY_TIME:;
    pwm[0] = PWM_open(Board_PWM0, &params);
    pwm[1] = PWM_open(EK_TM4C1294XL_Mk_PF1_M0PWM1, &params);    
    pwm[2] = PWM_open(EK_TM4C1294XL_Mk_PF2_M0PWM2, &params);   
    
    System_printf("\nTask_PWM");
    for (;;) {
        PWM_setDuty(pwm[0], duty[0]);
        PWM_setDuty(pwm[1], duty[1]);
        PWM_setDuty(pwm[2], duty[2]);
        
        duty[0]+=0xf;
        duty[1]=duty[0]+0xff;
        duty[2]=duty[1]+0xff;
        
        Task_sleep(1); //One Tick is 1ms
    }    
}
/*
 *  ======== pwmLEDFxn ========
 *  Task periodically increments the PWM duty for the on board LED.
 */
Void pwmLEDFxn(UArg arg0, UArg arg1)
{
    PWM_Handle pwm1;
    PWM_Handle pwm2 = NULL;
    PWM_Params params;
    uint16_t   pwmPeriod = 3000;      // Period and duty in microseconds
    uint16_t   duty = 0;
    uint16_t   dutyInc = 100;

    PWM_Params_init(&params);
    params.period = pwmPeriod;
    pwm1 = PWM_open(Board_PWM0, &params);
    if (pwm1 == NULL) {
        System_abort("Board_PWM0 did not open");
    }

    if (Board_PWM1 != Board_PWM0) {
        params.polarity = PWM_POL_ACTIVE_LOW;
        pwm2 = PWM_open(Board_PWM1, &params);
        if (pwm2 == NULL) {
            System_abort("Board_PWM1 did not open");
        }
    }

    /* Loop forever incrementing the PWM duty */
    while (1) {
        PWM_setDuty(pwm1, duty);

        if (pwm2) {
            PWM_setDuty(pwm2, duty);
        }

        duty = (duty + dutyInc);
        if (duty == pwmPeriod || (!duty)) {
            dutyInc = - dutyInc;
        }

        Task_sleep((UInt) arg0);
    }
}