What better way to celebrate your significant other's birthday than a homemade musical card? Pretty rough around the edges, but it was a lot of fun, so consider it "Mk. 1" and maybe the idea will be revisited next year, or maybe as a Christmas card.
Effectively this was an extremely simplified extension of the synthesizer project. The main goal here was energy efficiency, so a low-end MSP430 chip was used and support circuitry was minimized. The device cycles through three songs, playing a different one each time the button is pressed. After playing a song it returns to a low-power state to save power.
The hardware here is very straightforward. The MSP430 wakes up when you press the button, generates generates a PWM signal on P1.6 which is fed to the speaker through a DC blocking capacitor. The RST pin is held high by a 47k Ω resistor to allow in-circuit programming via TI's Spy-Bi-Wire interface.
The software implements a numerically controlled oscillator for sound playback, using the PWM output of the timer as a crude DAC. For the lookup table, I used a short piano sample (mostly because I already had the data and code from the synth project).
Control flow can be summed up as follows:
- After initialization, the MSP430 goes into LPM4 (low power mode 4) to save power.
- The button attached to P1.3 (pin 5) is pressed, waking the MSP430 from LPM4. Playback data for the next song is initialized, and a timer is started.
The timer handles everything else:
- Generating a PWM audio signal on P1.6 (pin 8).
- Incrementing the phase accumulator if a sound is currently playing.
- Stepping through the current song's note sequence, starting and stopping notes as necessary.
- Once the song is finished, the CPU goes back into LPM4 and sleeps until another pin interrupt.
As you can see (hear) in the video above, it plays three different songs using a piano-like instrument. Fairly happy with how it came out, but there are quite a few things I want to improve in the next version:
- Thickness: Proper PCB with SMD components to make it thinner. No reason this can't be made to fit inside a small pocket in a birthday card.
- Software Architecture: Move mixer/sequencer code outside of timer ISR, add buffer. (Will allow for much more audio processing time, so I can implement polyphony and more sound processing.)
- Sound Quality: Implement looping and ADSR support. Should support sustained notes and more interesting sounds.
- Graphics: Maybe eventually add a tiny OLED display for some simple graphics? Could be fun! :-)