Question
Create a new project in Code Composer Studio (FILE | NEW > CCS Project). Name the project PWM_manual. Choose Empty Project(with main.c) under the Project
Create a new project in Code Composer Studio (FILE | NEW > CCS Project). Name the project PWM_manual. Choose Empty Project(with main.c) under the Project templates and examples section, and click Finish. Design a program that will dim an LED. To get started, you can use the blink LED code from the first part of the previous lab. o The blink code contains a delay loop and a statement to toggle the LED. For PWM output, you dont want to toggle. Youll need to turn the LED ON for some time and turn it OFF for some time. o Suggestion: Instead of a delay loop within the endless while(1) loop, use a counter variable. Start the counter at zero. Include an if() statement that turns the LED ON when the counter is zero. Increment the counter by one each time the while(1) loop loops. When the counter reaches a threshold (your choice), use an if() statement to turn the LED OFF. The threshold is your PWM duty cycle. o A third if() statement at the end of the while(1) loop checks the counter and resets it to zero when it exceeds a count that representing the period of the PWM waveform. For example, you might start with a duty cycle threshold of 250 and a period of 1000 counts. o Change the duty cycle count threshold and verify that you can adjust the apparent brightness of the LED. Once you are certain your program works, add code to vary the brightness of all three LEDS in the RGB Everlight fixture at the same time.
Have a total of three duty cycle thresholds in your code, one each for red, green, and blue. Youll need a separate if() statement to turn off each LED at different times. When the counter reaches zero, be sure to turn all three LEDS back on. Suggestion: Use #define statements for the PERIOD and RED, GRN, BLU duty cycles to make them easier to change. Consider adding code that allows you to define RED, GRN, and BLU as percentages, and the program then computes the duty cycle counts (and stores them to variables r,g, and b) before the while() loop starts. Troubleshooting: To make sure your code is doing what you want, slow the waveform period down so you can visibly see the LEDs blinking. o When your code is working, try to change the color of the Everlight LED by varying the duty cycles of each LED.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started