CE351 lec17 PWM pins, TOP, BOTTOM, Mode 14
Watch on YouTube →
Overview
Yiyan Li explains active-low PWM control for LEDs, including how `analogWrite(pin, 255)` turns an LED off and how clearing a compare-output control bit disconnects PWM. The lecture reviews an 8-bit Timer2 preload calculation for a 10 ms interval, then applies 8-bit RGB PWM values and a 10 ms interrupt routine to fade through six colors in sequence.
Key takeaways
- For the active-low LEDs discussed, `analogWrite(pin, 255)` turns a channel off and `analogWrite(pin, 0)` turns it fully on.
- With a 16 MHz clock and a Timer2 prescaler of 1024, a 10 ms interval is approximately 156 timer counts, so an 8-bit overflow timer can start near 100.
- The RGB sequence yellow, red, fuchsia, blue, turquoise, and green can be encoded as channel values using 0 for on and 255 for off.
- Adding 255 to an 8-bit channel value is equivalent to subtracting 1 because the arithmetic wraps modulo 256.
- A 10 ms interrupt and one-unit channel steps provide gradual color transitions; changing either the interrupt period or step size changes the transition effect.
Chapters
0:00
Active-Low PWM Control and the Timer2 10 ms Preload
- The LED outputs are active-low: a pin value of 0 turns an LED on, while 255 turns it off.
- PWM can be disconnected by clearing its compare-output control bit, returning the pin to normal port operation.
- For an 8-bit Timer2 at 16 MHz with a 1024 prescaler, a 10 ms interval requires about 156 timer counts; preload the counter with 256 minus that count.
4:29
Timer2 Output-Compare Pins and Active-Low RGB Values
- The Timer2 compare-output configuration selects the corresponding OC2A output pin; the compare mode determines when that pin is set or cleared.
- Each RGB channel uses an 8-bit PWM value, with 0 meaning fully on and 255 meaning off.
- Represent red as (0, 255, 255), green as (255, 0, 255), blue as (255, 255, 0), and yellow as (0, 0, 255).
7:46
Six-Color RGB Tour and the Provided Code Template
- The color sequence is yellow, red, fuchsia, blue, turquoise, and green, with each color represented by red, green, and blue channel values.
- The template stores initial colors and per-channel deltas in arrays, allowing one shared index to select the current color and its transition behavior.
- After each transition, advance the color index; after all six colors, return to the initial color.
12:00
Fading with 10 ms Interrupts and 8-Bit Wraparound
- An interrupt every 10 ms adjusts each RGB channel by its configured delta, gradually fading the current color toward the next.
- The routine can use addition for every channel update: adding 1 increments a value, while adding 255 wraps around and acts like subtracting 1.
- A step size of 1 and a 10 ms interrupt interval produce a gradual transition; larger steps or a different interrupt frequency change the fade's smoothness and speed.
- The lecture closes by noting that the next in-class problem is postponed to Friday and that the quiz will cover timer and PWM calculations.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Yiyan Li.