old_projects

Bad Apple

[November, 2010] Initial write-up.

[Dec 1st, 2011] entered as november / december project of month contest in 43oh.com

Jukebox Like Device Plays Bad Apple Meme.



IMG

Description

Parts / Bill of Materials

Schematic

//               MSP430F20x2/3       ----------o--------------o Audio out
//             -----------------     |         |              o 
//         /|\|              XIN|-   |        ---             |
//          | |                 |   .-.       --- 10-500nF    |
//          --|RST          XOUT|-  | | 1-10K  |              |
//            |                 |   |_|        |---------------
//      LED <-|P1.0             |    |        ___                               
//            |                 |    |        ///    SD / MMC card      /|\
//            |    pwm out  P2.6|-----           ---------------------   |
//            |                 |               |                Vcc 4|---
//            |    as CS    P1.7|-------------->|1 CS, select device  |
//            |    as MOSI  P1.6|<--------------|7 MISO, data out     |
//            |                 |   ----------->|2 MOSI, data in      |
//            |                 |   | --------->|5 CLK, spi clock     |
//            |                 |   | |         |                Gnd 3|---
//            |                 |   | |          ---------------------   |
//            |                 |   | |                                 ---
//            |                 |   | |           Nokia 5110 breadout   ///
//            |                 |   | |   ----------------------------- 
//            |    as SCLK  P1.1|---|-o->|7 SCLK, spi clock            |
//            |    as MISO  P1.2|---o--->|6 MOSI, data in              |
//            |    as D/C   P1.3|------->|5 D/C, data or control       |
//            |    as RST   P1.4|------->|4 RST, reset, low active     |
//            |    as SCE   P1.5|------->|3 SCE, select , low active   | /|\
//            |                 |    ----|2 Gnd                        |  |
//            |                 |    |   |                        Vcc 1|---
//                                  ---   -----------------------------
//                                  ///
//
//        SD (back side)                          Micro-SD (back side)
//        __________________                      __________________
//       /  1 2 3 4 5 6 7 8 | 1. CS      .. SEL  /  1 2 3 4 5 6 7 8 | 1. NC            
//       |9                 | 2. DATAIN  .. SDO  |                  | 2. CS      .. SEL
//       |                  | 3. GND     .. Gnd  |                  | 3. DATAIN  .. SDO
//       |  S O - + C   I   | 4. 3.3V    .. Vcc  |    S O + C - I   | 4. 3.3V    .. Vcc
//       |                  | 5. CLK     .. Clk  |                  | 5. CLK     .. Clk
//       |                  | 6. GND/NC  .. Gnd  |                  | 6. GND/NC
//       |                  | 7. DATAOUT .. SDI  |                  | 7. DATAOUT .. SDI
//       |                  | 8. DAT1            |                  | 8. DAT1
//       |                  | 9. DAT2            |                  | 9. DAT2

The circuit is consist of three modules.

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;

Channel sound / midi contents are kind of serially encoded, read from the sd card as a sequence of bytes. For example, the following shows 2 sequences / steps of channel changes

 0x78, 0x03, 0x1b, 0x27,
 0x3c, 0x0f, 0x00, 0x00, 0x2a, 0x33,

Video LCD Show Implementation

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

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.

Lazy no-shield breadboarding, tie-points wired, ready to mount main components

IMG

Assembled

IMG

Sd card adaptor used to host micro-sd card

IMG

Front view as how the clip is shown

IMG

Firmware

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.

The followings are needed for content generation

This is what u get

Downloads

Source files

Click to download bad_apple.c

Click to download common.h

Click to download nokia_lcd.h

Click to download mmc.h

Click to download param_5110.h

Click to download param_7110.h

Content generation script

Click to download zcontent.pl

Firmware binary for mspdebug

Click to download bad_apple.elf

Firmware binary for ti MSP430Flasher.exe / ccs, etc

Click to download bad_apple.hex

Sd card raw content (for use w/ dd)

Click to download out_5110.img

Click to download out_7110.img

Content source, compressed package includes midi and avi

Click to download bad_apple_midi_avi.tgz

All source files now reside on my repository