Have a garden? Show it off! Share your pics here.

Bat-Pod: a DIY job for The Dark Knight's creators

Movie still from The Dark Knight showing Batman riding his Bat-pod motorcycleBatman kicks butt in his latest movie, The Dark Knight, a gloomy yet action-packed flick that scored big at the box office this weekend. A summer blockbuster has been born, to be sure. The stunningly cool vehicles used in the movie are attracting interest all on their own, especially the sleekly menacing Bat-Pod motorcycle.

It turns out the bike was a bit of a DIY job on the part of the film's creators. According to an article in Popular Mechanics, the 'Pod is actually a motorcycle-ATV hybrid, all wrapped up with plumbing parts and some creative duct-work. The entire exhaust frame was custom built especially for the movie, while those massive wheels suffered blow-out after blow-out until the steering was just right. Another cool little factoid: the footrests disguise the bike's radiator.

Speaking of The Dark Knight, the movie's star, Christian Bale, seems to have gotten himself into a spot of bother with the police. Read all about it at our sister site, Cinematical.

How to burn a CD

three blank CDs

There are more reasons than ever to learn how to burn a CD: to create your own CD wedding favors or to make a story CD for your child, for example.

Are you technically savvy enough to do it? I, for one, am happy to have a husband who is, but in the interest of being a strong, independent woman and a good example to my child, I set out to learn how to do burn a CD myself.

The first thing I learned is that there is this thing called a "Wizard" that pretty much does everything for you; simply drag and drop the files you want to write to the CD and surf the internet during your wait time.

OK, it isn't quite that simple (but it's close), but Worldstart has a tips and tricks page with:
  • CD-R versus CD-RW tips
  • step-by-step instructions
  • a separate tutorial for Microsoft Windows XP, which has its own CD burning software
and more -- everything you will need to know to burn your own CD, in fact. Independence is just a click away!

Record audio with the MSP430 microcontroller

This article continues a series about building a DIY digital audio recorder. Inspired by this microcontroller audio project [via], I set out to build a simple digital recording device. I chose Texas Instrument's MSP430 microcontroller for this project because it's fast (16 MHz), it's cheap ($1), and it's very low power. Read the first part, the second part, and the third.

In the first few segments I developed a digital audio recorder prototype that plays raw audio files from an SD card. This time we finish up the introductory segments by recording audio to the SD card. Before the audio can be recorded by the microcontroller, it has to be prepared by a small amplifier. Read on to learn more about working with microphones and recording audio with a microcontroller.



Gallery: MSP430 audio sampling

Audio sample overviewRaw microphone outputAnalog measurementEcho audio input

Make a talking MSP430 microcontroller

talking msp430This article continues a series about building a DIY digital audio recorder. Inspired by this microcontroller audio project [via], I set out to build a simple digital recording device. I chose Texas Instrument's MSP430 microcontroller for this project because it's fast (16 MHz), it's cheap ($1), and it's very low power. Read the first part, and the second part.

This week we'll progress towards a digital audio recorder by playing audio files from a SD memory card. First, we'll convert an audio file to a raw format and image it directly to a SD card. Then, we'll interface the SD card with the MSP430 and play an audio file. See it in the video:


Next time we'll extend this basic circuit to include a microphone and audio recording capabilities.

Read on to learn more about generating audio with a microcontroller.

next page

Gallery: MSP430 audio output

MSP430 audio prototypeProject overviewSD card SPI interfaceSD card data layoutPlaying a raw audio file

Make a talking MSP430 microcontroller - part 2


Overview

Read the previous article in this series for the fundamentals of microcontroller audio. Learn about basic MSP430 connections and programming in the MSP430 primer. This week we'll use the tiny, inexpensive MSP430 microcontroller to play audio from a SD card.



Playing an audio file
In the previous project, I used the MSP430 pulse-width modulator (PWM) to generate simple tones. The PWM duty cycle changed the frequency, and thus tone, of the generated signal. The signal is cleaned by a simple audio filter, and amplified by powered PC speakers. Hear it in this video clip from the previous article:




Each value generates a different frequency. If we change the values about 8000 times a second (8KHz) we can reproduce telephone quality audio.

8 bit audio (each sample requires one byte) at 8KHz requires 8000 bytes of data per second. 16 bit audio, the quality associated with CD players and PCs, requires twice as much data per sample (16 bits or 2 bytes) -- 16 kilobytes/second.

With 2K of internal flash, the MSP430 can store about one-quarter second of audio. External memory is needed to store any meaningful amount of audio. There's no better source of cheap storage than flash memory chips. A raw flash memory chip would be a special order item, but you probably already have some flash memory -- SD cards! These cards are ubiquitous in digital cameras and low-end MP3 players.
next page

Gallery: MSP430 audio output

MSP430 audio prototypeProject overviewSD card SPI interfaceSD card data layoutPlaying a raw audio file

Make a talking MSP430 microcontroller - part 3


Working with SD cards

NOTE!!! We are going to use the SD card as flash memory. It will not have a full (FAT) file system, and can not be read on a PC by the usual methods. It will not be possible to drag and drop a raw audio file to the card and read it with the MSP430, nor will it be possible see recordings from the file browser on a Mac or PC. Special disk tools provide access to the raw disk, but a full FAT file system implementation is too big for the tiny microcontroller. The F2013 has 128 bytes of RAM and 2 kilobytes of flash. A workable FAT implementation requires 1024 bytes of RAM and several kilobytes of flash program space.

The prototype design accesses the SD card using the simple SPI protocol. SPI is a simple three wire interface that allows a microcontroller to read and write data from external chips. If you want the dirty details on how the SD card works in SPI mode, read some of these tutorials [Tutorial 1, Tutorial 2]. A source code library from TI provides easy access to the disk without writing our own initialization and read/write routines (mmc.c/mmc.h in the project archive).



SD card storage is divided into 512 byte chunks called sectors. A full 512 byte sector must be read or written at once. The MSP430F2013 has only 128 bytes of RAM -- not enough to hold a whole sector for random access. We can still read/write each byte in order, as it's needed. This method will suffice as long as each byte is read or written sequentially.

Playing an audio file is as simple as reading a byte from the SD card and writing it to the PWM duty cycle register.

Converting audio to a raw format
My 'hello world' audio clip comes from the intro to my videos. I converted the clip to an 8KHz .wav file with Audacity and then saved it to raw text file with the free version of Switch, as described here.
  1. First, install Switch.
  2. Start Switch, and add your desired files to the queue by clicking "add files".
  3. Now set the output format to ".raw", and then click "Encoder Options". Set the encoder format to "8 bit unsigned", sample rate to "8000", and channels to "mono".
  4. Now click convert and the raw version of the audio files are created.
The raw text version of the audio file is included in the project archive.
next page

Gallery: MSP430 audio output

MSP430 audio prototypeProject overviewSD card SPI interfaceSD card data layoutPlaying a raw audio file

Make a talking MSP430 microcontroller - part 4


Imaging an SD card

The MSP430 isn't powerful enough to deal with a file system, so we need the audio to start exactly at the first sector the of SD card. A simple copy->paste operation would put the file on the SD card according to the rules of the PC file system. To avoid this, we image the file directly onto the card. This will be familiar if you've ever 'imaged' a CD .iso file, say, for a bootable Linux live CD. I used DiskImage 0.9 from Durban.

Imaging the audio file onto a flash card was pretty easy with DiskImage. I put the SD card in a USB flash card reader and attached it to the USB port. I opened DiskImage and it detected the card as a logical and physical volume.
  1. It's crucial to deal with the disk directly, rather than through the file system. All operations should be done to the listings under "Physical drives - raw drive, independent of partitions" box.
  2. Find the physical partition that represents your SD card - it's easy to identify the correct physical drive because it should be type "Removable" and the correct size (in my case 14MB). Be sure you don't overwrite your actual hard drive, this utility can easily do that!!!
  3. Click on the correct drive to highlight it.
  4. In the "With selected item do" box, click the "Import from file" button. Click yes, and type "i agree" after you verify that the correct disk is selected. Click yes again.
  5. Next, DiskImage prompts for the file that will be imaged onto the disk. Choose the raw audio .txt file outputted earlier.
With the raw audio imaged onto the SD card, we're ready to play it from the MSP430. Take the SD card out of the computer and put it into the card holder on the prototype.

next page

Gallery: MSP430 audio output

MSP430 audio prototypeProject overviewSD card SPI interfaceSD card data layoutPlaying a raw audio file

Make a talking MSP430 microcontroller - part 5


Firmware
The example program is included in the project archive. The example software is written using the demo TI/IAR Kickstart C compiler.



SD card access

The example firmware starts reading the SD card at the first sector. It reads one byte at a time over the SPI interface and places the byte in the PWM duty cycle register. When the end of a sector (byte 511) is reached, the next sector is immediately loaded and initialized so that the next byte is always ready when needed.

The example firmware will copy bytes from the SD card to the PWM register until it reaches the sector defined by the variable flashDisk.lastSector. At the end of this sector, the program begins again at the first sector.

The value to use here is determined by the number of sectors consumed by the audio file. The example audio file consumes 58,447 bytes. The SD card is arranged into 512 byte sectors, so the file ends at sector 115 (sector numbering starts with 0). Update this value if you are working with a custom audio file:

flashDisk.lastSector=115; //last sector (512byte block) where file is stored on flash...

Playback rate
The playback must match the sampling rate of the audio file, or the audio will sound too fast or too slow. Since I sampled audio at 8KHz, the PWM duty cycle register should be updated with a new value 8000 times each second. I appropriated the watchdog timer (WDT) from the MSP430 to sound an alarm (an interrupt) 8000 times per second. When the timer interrupts, a bit of code copies the next byte from the SD card to the PWM duty cycle register.

The timer runs on the calibrated 8 MHz internal clock. The WDT is set to trigger every 512 counts of the internal clock (8MHZ/512), or 15,625 times per second. This is about twice as fast as we need, so the interrupt routine uses a switch that updates the audio only once every other interrupt, or 7,812.5 times per second. Not exactly 8000 samples-a-second, but the internal oscillator will vary with temperature and age anyway. Using the internal crystal keeps the design simple and the part-count low.

If you're after tighter tolerances, consider using a watch crystal on the P2.6/7 pins of the MSP430 as the timer clock source.

When the MSP430 is not copying audio to the PWM, it enters a loop that continually checks if a new audio byte should be loaded into a single byte buffer. The buffer ensures that data is available when it's needed, and that audio quality isn't effected by delays in reading data from the SD card. A ton of power could be saved by entering sleep mode between interrupts, we'll look at this again in a future article.
next page

Next Page >

DIY Lists

About DIY Life

Do Life! DIY Life highlights the best in "do-it-yourself" projects.

Here you'll find all types of projects, from hobbies and crafts to home improvement and tech.


Powered by Blogsmith

DIY Life Contributors

#ContributorPostsCmts
1DIY Life Staff540
2Diane Rixon41
3Bethany Sanders31
4Kristi Anderson20
5Chris Jordan10

Featured Galleries

An easy way to insulate and skirt an elevated structure
USB analog gauge overview
USB analog gauge circuit
Basil harvesting
Bug snacks
Fabric scraps projects