I am trying to blink the yellow and green LEDs on my CC32xx board. To do that I need to edit some code that was presented to me. I need to 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%, and create my code in a loop.
So far, I have set PWM1 to 90% of the period and PWM2 to 10% of the period. And changed the value of variable time to 1000000 ms, which is 1 second. How do you change value of PWM1 to 0% and PWM2 to 90% of period after the sleep function executes? Here is my code:
/*
* ======== 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 on board 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 = 1000000;
PWM_Handle pwm1 = NULL;
PWM_Handle pwm2 = NULL;
PWM_Params params;
/* Call driver init functions. */
PWM_init();
PWM_Params_init(¶ms);
params.dutyUnits = PWM_DUTY_US;
params.dutyValue = 0;
params.periodUnits = PWM_PERIOD_US;
params.periodValue = pwmPeriod;
pwm1 = PWM_open(CONFIG_PWM_0, ¶ms);
if (pwm1 == NULL) {
/* CONFIG_PWM_0 did not open */
while (1);
}
PWM_start(pwm1);
pwm2 = PWM_open(CONFIG_PWM_1, ¶ms);
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, 2700);
PWM_setDuty(pwm2, 300);
duty = (duty + dutyInc);
if (duty == pwmPeriod || (!duty)) {
dutyInc = - dutyInc;
}
usleep(time);
}
}
CCR) value to the max value of the timer period (e.g. the rollover value). The duty-cycle is the percentage of time that power is being applied. So if your timer has 16-bit precision (max 32767) and you have a 50% duty-cycle (CCR = 16384) the power is off from0 - 16383and on from16384 - 32767. To set the duty-cycle to0setCCR = 32767so there is no on period. Conversely for 100% duty-cycle, setCCR = 0.pwmPeriod = 3000;so to set a 90% PWM, you would need to setCCR = 300so the PWM power is on for 90% of the3000tick period. TheCCRvalue seems to be yourparams.dutyValue.