Page 1 of 1

/* * ======== pwmled2.c ======== */ /* For usleep() */ #include #include /* Driver Header files

Posted: Tue Jul 12, 2022 8:11 am
by answerhappygod
/* * ======== pwmled2.c ======== *//* For usleep() */#include <unistd.h>#include <stddef.h>
/* Driver Header files */#include <ti/drivers/PWM.h>
/* Driver configuration */#include "ti_drivers_config.h"
/* * ======== mainThread ======== * Task periodically increments the PWM duty for the onboard LED. */void *mainThread(void *arg0){ /* Period and duty in microseconds */ uint16_t pwmPeriod = 3000; uint16_t duty = 0; uint16_t dutyInc = 100;
/* Sleep time in microseconds */ uint32_t time = 50000; PWM_Handle pwm1 = NULL; PWM_Handle pwm2 = NULL; PWM_Params params;
/* Call driver init functions. */ PWM_init();
PWM_Params_init(&params); params.dutyUnits = PWM_DUTY_US; params.dutyValue = 0; params.periodUnits = PWM_PERIOD_US; params.periodValue = pwmPeriod; pwm1 = PWM_open(CONFIG_PWM_0, &params); if (pwm1 == NULL) { /* CONFIG_PWM_0 did not open */ while (1); }
PWM_start(pwm1);
pwm2 = PWM_open(CONFIG_PWM_1, &params); if (pwm2 == NULL) { /* CONFIG_PWM_0 did not open */ while (1); }
PWM_start(pwm2);
/* Loop forever incrementing the PWM duty */ while (1) { PWM_setDuty(pwm1, duty);
PWM_setDuty(pwm2, duty);
duty = (duty + dutyInc);
if (duty == pwmPeriod || (!duty)){ dutyInc = -dutyInc; }
usleep(time); }}
Now it is time to modify pwmled2. Your code will need toaccomplish the following:
• Set duty for PWM1 to 90%.
• Set duty for PWM2 to 10%.
• Set the sleep(1) function so it sleeps for 1 second.
• Set duty for PWM1 to 0%.
• Set duty for PWM2 to 90%.
• Create your code in a loop.
Note that it will be difficult to determine the PWM values fromthe LEDs due to the differences between the yellow and green LEDs.The yellow LED is much brighter than the green LED. The green LEDat 10% appears as though it is turned off. Also, the PWM_setDuty()function does not take percentages. Thus the functionPWM_setDuty(pwm1, 90) will not work. Instead you need to calculatethe value (90% of the period).
Please can someone help me modify my code I am solost as to what I need to do with my code to make theseLED lights do what is intended in this task!
Thank you in advance I will be sure to give good feedback towhoever solves this! This is in Java btw!