"Just Music" justly tuned music library

OK, it turns out there is one more way to get sound out of an Arduino.

Read this - http://makezine.com/projects/make-35/advanced-arduino-sound-synthesis/ - then come back.

I’ll wait.

This essentially reprograms the PWM controller at an extremely high speed. Concepts such as duty cycle, which implies a regular repetition, are barely in use here. The PWM should be running at a high enough rate that the duty cycle “settles” to an average value using several repeated cycles in less than 50 microseconds (for 20 kHz; longer for lower max frequencies). Then the PWM is reprogrammed to settle to the next sampled point desired on the output curve.

It is a rather neat technique, but some of the notes elsewhere indicate that it consumes about 40% of the CPU. It also consumes a lot of memory for wavetables, which they recommend to build into the program, not ram. Overall, this suggests that this technique is ideal for a synthesizer, but may be too much for sound for a game library.

In addition, it requires a low-pass filter structure, like I described, on the PWM output before the “sound output”. They are using a simple resistor and capacitor. That low-pass filter essentially turns the PWM output into a standard variable audio output. Someone needs to check if they piezo buzzer in Arduboy can be driven by such a signal. If I recall correctly, this test cannot be done on a Dev Kit because the Dev Kits don’t connect a PWM pin to the piezo sounder, but I might be wrong.

Finally, it appears that this might only be possible with the high speed timer on the ATmega32u4. That would require the peizo buzzer to be driven by a Timer 4 pin.

As cool as this sounds :slight_smile: , be careful about over committing to hardware changes at this point.

1 Like

Correct, we have to do all our PWM in software because we’re not on a hardware PWM pin.