
Although it’s technically possible to get 16 bits of resolution on a ATMega328, most implementations of PWM on everyone’s favorite ‘mega – including just about every Arduino sketch – are limited to 8 bit PWM. This means the pins can only output 256 different values, so if you’re playing around with music made on an Arduino don’t expect very high fidelity.
There is a clever way around this: use two PWMs, and use one pin for high bytes and another for low bytes. That’s what Open Music Labs did when working on a synthesizer project that needed very high quality audio.
The basic idea behind the build is that PWM pins can be used to create audio frequencies. Using two PWM pins and adding them together means it’s possible to add extra bits of resolution. This requires using different values of resistors on each pin. For example, using the same value of resistors on two PWM pins increases the resolution by one bit. Two pins with a resistor value ratio of 1:4 increases the resolution by four bits, and so on.
There’s a great tutorial for setting up these higher resolution, dual PWM outputs on an ATMega or Arduino, as well as a distortion analysis for this dual PWM setup.
Filed under: Microcontrollers
