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(¶ms); 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, ¶ms); pwm[1] = PWM_open(EK_TM4C1294XL_Mk_PF1_M0PWM1, ¶ms); pwm[2] = PWM_open(EK_TM4C1294XL_Mk_PF2_M0PWM2, ¶ms); 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(¶ms); params.period = pwmPeriod; pwm1 = PWM_open(Board_PWM0, ¶ms); 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, ¶ms); 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); } }