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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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).
I WILL ONLY UPVOTE IF YOUR ANSWER IS RELEVENT ANDCORRECT.
This will be my second time posting this due to peopleanswering with random text.
Thank you to whoever answers thiscorrectly.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply