a polyphonic pwm output implementation, 8 channels are used in this project

the sd / mmc module and the lcd module shares some pins

both sd / mmc module and the lcd module are isolated and can be included in other projects

the core part of the code implements pwm sound and controls timing for content reads and displays

sd / mmc module

the sd / mmc module talks to a sd memory card via spi interface. we are using low level raw device access for simpicity reasons and the fact that we do not have enough program space for a proper file system. the same resource constraint also force us to use a non 512 byte read sector. instead our read block is only 16 bytes long. this can be adjusted to 64 bytes for a bigger device (430g2452/2553 for example). bit-banging is used for spi for freedom on layout / pin selection and comptability between low-end and high-end devices.

the sd card contains the video and sound data to reproduce "bad apple". it is read on the fly to create the sound and sight show. data content for both the video and sound can be created via the supplied zcontent.pl script. input for content includes an avi video file and a midi file. this script can be used to generated alternate contents for most avi and midi files.

polyphonic pwm out implementation

this is almost a direct copy from a pic project i found, www.pic24.ru link

the pwm output uses timera with a base / sampling frequency of about 16khz. timer is setup w/ pin toggling. at each sampling frequency triggered interrupt the following is done;

loop thru all sound channels and sum them up, divide and setup CCR1 for mixed frequency

during the wait, at about 16khz frequency, interrupt handler will apply channel freqeuncy plus sine table phase adjustments to timera. this realizes the pwm output.

when the next step kicks in, the new duration is 0x3c time units

the 2nd byte in this step shows 0x0f = b00001111, ie, channel 0 to 3 needs to be adjusted.

the next 4 bytes turns off channel 0 and 1, sets channel 2 and 3 to 0x2a and 0x33 respectively.

video lcd show implemenation

it was originally for pic devices but easy to change to msp430, i take the control part link also nokia 5110 initilization method taken from 43oh.com forum link i originally stage the project w/ 7110 lcd and later turn to a 5110 for simplicity. the 7110 display did show more detail.

the video show is achieved by writing to the lcd successively. contents are kind or run-length encoded from bmp files, which in turn was extracted / converted from an avi source. pixel output to lcd is done frame by frame with a software timer delay. the lcd control logic is structured such that 6 rows of 84 bytes are written via spi successively. at the break of each row, we also check to see if we need to update the sound channels. this provides better sound / sight synchronization over doing it at the end of each frame.

video contents are read from the sd card at offset 0. for each word of data, the highest 3 bits represent what the word is for. a word can carry

if bit 15 is set, run-length of "black" pixels follows. i.e. 0x8234 means the next 0x0234 pixels are "black"

if bit 14 is set, run-length of "white" pixels follows. i.e. 0x4234 means the next 0x0234 pixels are "black"

if bit 12 is set, the lower 8 bit represents the next 8 pixels. i.e. 0x203c means the next 8 pixels are 00111100.

the encoding is not optimized for space but rather selected for run-time efficiency. we do have a lot of flash space in a typical sd card.

construction

the initial project was done on a mini breadboard. with the small number of parts in this project one can easily do the layout directly from the schematic. there are a few notes though.

for the nokia 5110 breakout, the spi pin mapping is selected so that the breakout board aligns nicely w/ the launchpad.

the sd card adapter shares two spi pins (CLK and DATA) with the nokia lcd, you just need two additional wire for CS (chip select) and DATA OUT. that is apart from power.

the low pass audio filter is constructed very casually. i just took the resistor / capacitor that lies closest to me.

alternatively, you can construct this project by putting together everything on a perfboard w/ a bit of soldering work.

the firmware was done under ubuntu 11.10 w/ mspgcc4 + mspdebug as programmer. it is also test built under windows 7 with cygwin environment, mspgcc4 is also used and a MSP430Flasher.exe (command line programmer released by TI) is used to program the launchpad. it should build also w/ CCS as i had compiler directives to switch code portions. however i did not verify, you are on your own if you are on CCS or IAR.

the are additional details / options that you can tweak, they are explained in the source code. they are not listed here as you only need them if you built the project.

content generation

data content for both the video and sound can be created via the supplied zcontent.pl script. input for content includes an avi video file and a midi file. this script can be used to generated alternate contents for most avi and midi files.