hexagon5un / AVR-Programming

Code examples for the book "Make: AVR Programming"
http://littlehacks.org/AVR-Programming
MIT License
725 stars 340 forks source link

Unclear statement Chapter 10: only 3 LEDs for hardware PWM when ATmega168PA has 6 #39

Open Seikilos opened 5 years ago

Seikilos commented 5 years ago

Chapter 10, page 206 states

You might be wondering why we're only lighting up three LEDs using the hardware PWM, [...] AVR's dedicated PWM pins are limited to [...] four pins at an 8-bit PWM depth, and two at 16 bits.

That makes the mentioned six PWM channels, ok so far.

The pwmTimers.c examples then continues to use OC2A, OC1B and OC1A output compare pins.

What is the book actually implying here? Can't I use 3 more pins for PWM? AFAIK OCR2B and those of Timer/Counter 0 OC0A and OC0B?

Or is it merely saying that in our current setup, where those 8 LEDs are currently wired to the B bank this would not be possible without rewiring some of those LEDs to the D bank?

sjomae commented 9 months ago

3 timers x 2 pins = 6 PWM pin options. The software example uses 2 timers for 3 leds. Later in the chapter, there is a 'hack' described to use PWM on any pin.