Making sounds
Posted: Sat Jun 18, 2016 10:50 am
A piezo speaker is a cheap and popular peripheral for teaching beginning electronics. It's fun to have your microcontroller board beep, then play simple songs, then act as an instrument. It's also nice for improving feedback on user interface in more advanced projects.
I'm preparing a workshop now, and one thing I wanted to include was playing simple songs. I thought that I can use the PWM object for this -- after all you can specify frequency in it. Turns out that the resolution of that frequency at acoustic range is very bad -- so bad, in fact, that most notes on a scale get rounded to the same frequency.
Now I'm wondering if there is some other way to play that song. Bit-banging is of course one option, and shouldn't be problematic with a 80Mhz CPU. Timers is another option. Any other ideas?
I'm preparing a workshop now, and one thing I wanted to include was playing simple songs. I thought that I can use the PWM object for this -- after all you can specify frequency in it. Turns out that the resolution of that frequency at acoustic range is very bad -- so bad, in fact, that most notes on a scale get rounded to the same frequency.
Now I'm wondering if there is some other way to play that song. Bit-banging is of course one option, and shouldn't be problematic with a 80Mhz CPU. Timers is another option. Any other ideas?