When you take a microcontroller class in university, one of the early labs they have you drudge through on your way to, promised, mastery over all things embedded, is a tiny music generator.
It’s a more challenging lab than one would expect. It takes understanding the clock of the microcontroller and its sometimes temperamental nature. It takes a clear mental picture of interrupts, and is likely one of the first experiences a burgeoning designer will have worrying about the execution time of one of their loops. Also tables, data structures, and more. It even requires them to go out of their comfort zone a learn about an unrelated field, a challenge often faced in practicing engineering.
Luckily [Łukasz Podkalicki] has done a great job of documenting the adventure. He’s got everything from the schematic and code to the PWM traces on the oscilloscope.
It’s also worth mentioning that he’s got a few other really nice tutorials for the ATtiny13 microcontroller on his blog. A tiny party light generator and a IR receiver among them.
Heh yah I remember my first adventure with directly toggling an io pin speaker… Managed a series of farts interspersed with hiccups… Not what I was aiming for. Had in mind a drum and bass sequencer. Couldn’t get it any faster at the time.
My first ‘toggle the pin’ was on a TRS-80 computer (1978) and I was clicking the cassette drive relay on and off with BASIC. I quickly discovered the port address that goes to the tape drive data and then I could make complex sounds with what is called PWM today by using machine code. It was amazingly simple to do compared to my BASIC programs that did things like modeling/synthesis for chemistry.
Yeah I was trying to PWM but use ROM math routines for a sine wave and I guess that was nowhere near fast enough.
For (co) sine just use a look up table from 0 – 90 deg, ,then the same backwards and the all previous inverted.
ROM math routines waste too much time with type casting.
in the 90′ when I didnt know about microcontrollers/arduinos , I did the music generator with: eprom 27c512, it had the string of 8 bit values according to the tone , at the output of the eprom was a DAC created by resistor ladder r2r, and then a 555 configured as voltage to frequency converter, it played “la cucaracha” and when the “saints go marching in”. now I am spoiled with arduinos and the tone library.
You could have done it with a 555 … wait!
Sound like a great hardware solution to go from an 8 bit data value to a frequency or period.
On a somewhat related matter, check out “Arduino Playtunes”. It uses timers to play midi files on the Atmega. Too bad the Miduino website (where you could generate ready .ino files) stopped working. You can still do it in a console.
Nice, but if you do it non blocking you could play tunes and do other stuff as well.
My version [German] with github link and a bunch of songs (e.g. chrismas):
https://sebastianfoerster86.wordpress.com/2016/03/20/musikalischer-attiny/