Introduction

Perusing through the impressive list of past projects, we decided to make our final project a combination of two technologies—wireless technology and the MP3 player. Specifically, we decided to create an MP3 player that broadcasted the songs to an FM dial. We call this the "MP3 Radio."

To accomplish this, we used an ATMEL ATmega32 MCU, a STA013 MP3 decoder, and an IF VCO MAX2606 FM transmitter as our main hardware components. On our software side, we used C and PHP-GTK as our programming languages; and CodeVision C Compiler and Visual Studio C++ as our compilers.

The user interface consists of two components: one on the PC side, and one on the external hardware piece. On the PC, using PHP-GTK, we created a GUI application, which allowed the user to create the playlist and then start the "broadcast." Externally, on the STK-500, the user can control the MP3 player with the following pushbuttons:

Using our "MP3 radio," users are no longer confined by the limits of traditional speakers. In fact, speakers are no longer needed, as long as there's a radio nearby. One very practicable application is to adapt this as an add-on to a PDA. Thus, you can transform your walkman and your car radio into MP3 players. Moreover, it was a great way for us to explore two distinct technologies we are interested in.


High Level Design

The flow of how our project works is fairly straightforward. It is outlined by the steps below:

  1. GUI: The GUI (source code: mp3radio.php), coded with PHP-GTK, generates the playlist. To do this, it merely moves the selected MP3s to a specific directory ".\playlist\." Then, the button "Broadcast MP3s" calls the script serialOut.exe. To compile the PHP, we experimented with several programs. Finally, we found one that actually worked, called PriadoBlender.

  2. As the name suggests, serialOut.exe (source code: serialOut.c) sends stuff through a serial connection. This is done using COM1. We generated an array storing all the names of all the MP3s in the "playlist" directory. Then, we send each file, character by character, through the RS232 connected to COM1. To do this, we modified a terminal program donated to us by Bob Gardner (@AVRFreaks.net). We set the baud rate to 57,600 bps.

  3. Our mcu, via the USART interrupt, reads the data sent in from the RS232 from COM1. If a pushbutton is pressed or a song is done playing, the mcu sends the appropriate command to the computer.

  4. Next, the mcu sends the MP3 data to the decoder. We did not bother buffering our data, because our baud rate is so much slower than the maximum data input rate of our STA013 MP3 decoder, 20Mbits/sec. Moreover, our memory was too small to create a reasonably sized buffer.

  5. Our decoder outputs the correct clock and data waveforms for our digital to analog converter (CS4334 DAC).

  6. Finally, the output signal from the DAC is fed into our FM transmitter. Our transmitter can send signals at frequencies between 88.0 and 108.0 MHz.
The following diagram illustrates this high-level structure:


Figure 1. Diagram of High-level Structure

Hardware/Software Tradeoffs:
The most significant tradeoff involved the limiting speed of the RS-232. We found that, due to the error associated with the higher baud rates (e.g. -3.7% with 115,200 bps), the small amount of memory on the microcontroller, and cycles overheard in C programming, we had to send at a baud rate of 38,400 bps. Thus, we had to encode our MP3s into 32 kbps bitrate MP3s, which is the smallest, lowest-quality possible bitrate for an MP3.

A second tradeoff, as mentioned, is the small amount of memory—only 1 kB of SRAM. Thus, we were unable to effectively buffer the MP3 data before sending it to the STA013 decoder. This means we had to stream the MP3 data from the computer directly to the decoder, which is the reason why we chose a baud rate of 38,400 bps.

Finally, the quality of our songs was compromised by the FM transmitter, which can only transmit in mono. Higher quality songs are possible if we use a stereo-quality FM transmitter chip, which would require transmitting at two different frequencies. Due to our budget and time constraints, we were unable to use a stereo-quality chip.

Relevant Standards:
This topic will be discussed in the Conclusion.


Program/Hardware Design

The Software

As aforementioned, we programmed our scripts using C and PHP-GTK. In total, our project requires 3 scripts to operate:
  1. mp3radio.php;
  2. serialOut.c; and
  3. serialIn.c.
Please note that these scripts have only been tested on Windows 2000/XP. In fact, it is very unlikely that there will run on other operating systems as the initialization of the serial ports are very specific.

Mp3radio.php
This first script, mp3radio.php, acts as the user interface for creating his or her playlist. It includes a list of the current tracks on the playlist, and the following buttons:

This script contains the following functions... The reason we chose to code in PHP is because it is an easy-to-learn web-based language. We wanted a web language, so that we can easily incorporate a file upload option. However, at first, we ran into a deadend as we were unsuccessful in our many attempts to compile PHP into an executable. Thus, we rewrote our program using PHP-GTK, a GUI add-on to PHP, and were finally able to compile our program using PriadoBlender. However, in order for mp3radio.exe to run properly, the following DLL files must be in the same folder: iconv.dll, intl.dll, libgdk-0.dll, libglib-2.0-0.dll, libgmodule-2.0-0.dll, libgtk-0.dll, mmcache.dll, php4ts.dll, php_gtk.dll. These files are required for PHP and PHP-GTK to run properly on computers without these softwares installed. Here's a rocking screenshot:


Figure 2. GUI to Make Playlist

SerialOut.c
Of the three scripts, this was the most difficult to write. It took three completely different tries. But, as they say, third time's the charm.

SerialIn.c
This is the microcontroller-side script. Each time data is received, we break into the USART interrupt and send the MP3 data, bit by bit, to the decoder. This script included the following functions... Some code was borrowed from the spring 2002 MP3 project by Nelson Li and Jason Dirner As stated, we also used two interrupts, [USART_RXC] and [TIM0_COMP]. Each time data is received through COM1, the USART is triggered. It then grabs the character from UDR and checks whether DATA_REQ is low. DATA_REQ is an active-low value controlled by the decoder. If the STA013 decoder buffer is full, DATA_REQ is set to 1. Otherwise, it remains at 0, indicating that the mcu can send it more data. Thus, if DATA_REQ is 0, we call toDecoder() to send out the received char; otherwise, we send the PAUSE command to serialOut.exe, thus discontinuing any more MP3 from being sent.

The timer0 compare interrupt is used to keep track of time. It is set to trigger each millisecond. This is needed for two functions:

Using pushbutton 5, the user able to toggle between 4 distinct modes: NORMAL, ROCK, JAZZ, and CLASSICAL (in this order). These modes are preprogrammed settings which characterize specific genres of music. To do this, we set the treble and bass levels to different values for each mode. Check it...

MODE Treble (dB) Bass (dB)
NORMAL 0 0
ROCK 0 4.5
JAZZ -4.5 13.5
CLASSICAL -13.5 -6.5
Table 1: Modes

Notice that we've set the rock mode's trebel level to 0 decibels. This is because any positive value of trebel seemed to yield extreme distortion (that was unbearable to the ear).

The Hardware

The hardware consists of the following chips:
  1. STA013 MP3 decoder from STMicroelectronics;
  2. CS4334 dual 24-bit DAC from Cirrus Logic;
  3. MAX2606 integrated IF VCO from Maxim-IC;
  4. MAX884 linear voltage regulator from Maxim-IC;
  5. ATMega32 Microcontroller from Atmel; and
  6. 74HC04 Hex Inverter from Phillips Semiconductor.
Figure 3 below shows a block diagram of the hardware side.


Figure 3: Block diagram of hardware design

A 14.7456 MHz crystal from Maxim-IC was used along with a 74HC04 Hex Inverter chip. The crystal value matched a standard value used the STA013, which are given as 10 MHz, 14.31818 MHz, and 14.7456 MHz in the datasheet, although other values may be used as well. Initially, we were worried that the discrepancy between the 14.7456 MHz STA013 clock and the 16 MHz MCU clock might cause some problems; however, it seems like the two frequencies are completely independent of each other. The clock circuit is shown in Figure 4 below.


Figure 4: 14.7456 MHz crystal driving circuit

The STA013 is connected to the microcontroller through six pins of PORTC, which are summarized below:

Since the STA013 is a 3.3V chip, it is imperative that we maintain a constant, regulated power supply for the decoder within the 2.4 to 3.6V range specified in the data sheet. This was done by connecting the 5V VDD from the MCU to a MAX884 linear voltage regulator (datasheet) to step down the voltage to 3.3V. The regulator uses very little power (on the order of microwatts) and has a low dropoff voltage of 200 mV which ensure longetivity of the circuit). Figure 6 shows a schematic of the MAX844 regulator.


Figure 6: MAX884 voltage regulator circuit

Also, it is important that none of the 5V pins are connected directly to the 3V chip, as forewarned on the PJRC website, which requires bi-directional level shifting. Essentially, we connect the SCL, SDI, SCKR, and RESET pins to PORTC through a 4.7 kOhm resistor and a 47 pF capacitor in parallel, as shown in the following figure taken from the PJRC website.


Figure 7: Bi-directional level shifting for SCL, SDI, SCKR, and RESET pins
(Source: http://www.pjrc.com/tech/mp3/sta013.html)

Essentially, the 4.7 kO resistor and 47 pF capacitor serve to drive the input pin on a rising edge and limit the steady-state current to less than 0.5 mA. The capacitor is especially important since the data and clock pins must be driven rapidly (over 1 MHz). The SDA signal can be similarly connected using the following scheme.


Figure 8: Bi-directional level shifting for SDA pin
(Source: http://www.pjrc.com/tech/mp3/sta013.html)

The 4.7 kOhm pull-up resistor to 3.3 V is needed to satisfy the 2.0 V CMOS input high requirement, whereas the 270 O resistor limits the current into the STA013 SDA pin.

Since the STA013 is a SOP28 pin with 0.5 mm leads, it could not fit directly into a proto-board or standard solder board. Even though Aries Electronics sells a 32-pin SOIC-to-DIP adapter, which can be obtained from Digikey (P/N: A323-ND), the $10 cost was beyond our budget; therefore we were left to make our own 28-pin adapter. We were initially hesitant about soldering the 28-pins onto our custom adapter or wire leads due to the cost of the chip; instead, we used two large clips to press the leads down on the pins to achieve adequate connections. However, this did not work …

We initially soldered resistor leads, which are thinner than the normal enamel-coated copper wires in lab, onto a small solder board. Since the holes are spaced about 1 mm apart, we really only had to adjust the pins that went in between them. Needless to say, this was not an easy soldering job, and trying to pin the leads down on the chip took even more time. Eventually, with less than week left before our demo, we decided to redesign our adaptor, this time using wires instead of resistor leads. Again, we found that the only way to achieve adequate connection between the pins, which is crucial for high-frequency signals such as the clock pins, is to solder all 28 pins. With this done, we now have our custom-built 28-pin SOIC-to-DIP adaptor, as shown in the figure below.


Figure 9: Completed adapter design (those are not antennas!)

Figures A and B below show the STA013 and CS4334 schematics as obtained from the PJRC website. Separate 5V and 3.3V power rails were maintained in order to provide the 3.3V VDD for the STA013 and the 5V VDD for the CS4334.


Figure 10: STA013 wiring schematic


Figure 11: CS4334 wiring schematic

The FM transmitter part of the circuit has a two-channel input which is subsequently summed to create a mono signal. The MAX2606 VCO is used because it provides high-reliability, low-power transmission capabilities in the 70 to 150 MHz frequency range. It contains an integrated varactor to act as the tuning capacitor, which when coupled with an external inductor, provides the necessary oscillation.

The nominal oscillation frequency is set primarily by the external inductor, which is specified at 390 nH on the Maxim website. However, we quickly found out that despite our compact soldering job, the parasitic capacitance of the wire and element leads decreased the oscillation frequency to only 40 MHz, far too long for the FM band. Therefore, we had to scrap the standard 390 nH inductor and create our own using wire coils and a 3 mm diameter core. The following website gives a good tutorial on making your own air-coil inductors, http://sound.westhost.com/project54.htm, which gives the approximate inductance value as

L = N2 * r2 / (228r + 254l)

Where L = inductance (µH), N = number of turns of coil, r = average coil radius, and l = coil length. All dimensions are measured in mm.

The oscillation frequency increases linearly (roughly) as the inductance decreases; therefore, we aimed for a nominal inductance of two-thirds to half of the specified value. This value can later be tuned by simply varying the spacing of the coils. Our resulting inductance is 280 nH which places the center frequency at just over 100 MHz. The frequency can also be tuned using a 100 kO potentiometer connected to a pull-up resistor to VDD and GND. The 10 kO potentiometer shown in the figure below adjusts the attenuation along the two channels, essentially attenuating signals to below 60 mV in order to reduce distortion.


Figure 12: MAX2606 wiring schematic

More information about the FM transmitter can be found on the MAX2606 datasheet. A very short antenna was used during testing to prevent an possible interference with FM radio stations or other groups. However, a longer steel antenna can be attached to increase the quality of the transmission. Either way, the transmission distance for a normal MP3 input is no more than a few feet from the antenna, which has been tried and tested in the lab. Figure 13 below shows the FM transmitter, conveniently hanging from the lab bench.


Figure 13: FM transmitter circuit

The overall schematic of our circuit is shown below:


Figure 14: Complete wiring schematic

The overall analog design contained several components, which are all connected using wire clips. Ideally, we would have liked to move all the major components (STA013/CS4334 decoder, MAX2606 transmitter, ATMega32 MCU, and 14.7456 MHz clock circuit) onto the same board to reduce parasitic impedances and increase the robustness of the circuit. This would also require a lot fewer wire clips, which may facilitate the debugging process ...


Results
We were able to complete all of our objectives. This includes... Since we had finished a couple days ahead of schedule, we decided to implement some extra features to our MP3 player, which include... Our proof-of-principle MP3 radio plays 32 bitrate/44100Hz-quality MP3 files, which can be loaded on the computer. Each song is subsequently decoded with a variable bit-rate MP3 decoder, and broadcasted with minimal distortion over the FM band to a distance of a few feet. The PC-side program, serialOut.exe, and mcu-side script, serialIn.c, run concurrently. They were able to successfully communicate through COM1—whereby, serialOut.exe would continuously poll for received data and serialIn.c would break into the USART interrupt when new MP3 data was received.

With the STK-500 and our hardware/software bundle, anyone with a computer (Windows OS 2000+) will be able to use our MP3 radio. During our lab sessions, we did not experience any interference with other projects, because we had limited our FM transmission distance to within a few feet. Also, there were no other groups that we knew of that transmitted between 88 MHz and 108 MHz.


Conclusions

Here's some great advice... Don't build your own adapter! =) Why? Well, a picture is worth a thousand words...


Figure 15. Kudos to Jian

What we could've done differently

  1. Buy a SOIC-to-DIP adaptor.
  2. Increase the FM transmission distance.
  3. Increase our RS-232 baud rate with error-checking to allow higher bitrate-quality MP3s.

Relevant Standards/Ethical Considerations
This design process and specifications are required to meet the following set of standards and codes:

  1. IEEE Code of Ethics;
  2. EIA RS-232;
  3. MP3 (MPEG-1 Audio Layer-3);
  4. Federal Communications Committee (FCC); and
  5. Recording Industry Association of America (RIAA).

The RS-232 standard defines the serial connection from the PC serial port to the base station using a standard male-female DB25 (or D9) connector as defined. The standard lists several parameters such as:

  1. A "Space" (logic 0) will be between +3 and +25 Volts;
  2. A "Mark" (logic 1) will be between -3 and -25 Volts; and
  3. The region between +3 and -3 volts is undefined.

A series of baud (or bits per second data transmission rate) rates are also specified, with a maximum of 115,200 baud under the new RS-232D standard. More information regarding the RS-232 standard may be found on the 476 Course Page or this Beyond Logic site.

MP3 defines the audio compression/encoding standard originally developed by the Motion Picture Experts Group (MPEG) and formalized by ISO. The MP3 takes advantage of several compression schemes, such as Joint Stereo and Huffman coding, to compress the audio file into one twelfth its original size while preserving its original sound quality. Encoding the MP3 file requires careful consideration of the following three parameters:

  1. Channel type (either stereo or mono). In general, a stereo encoding is of higher quality and is more reliable, but doubles the size of the MP3 file. Our project used a mono signal to reduce the size of the MP3 file in order to transmit it over the RS-232 port.

  2. Sample frequency: This defines the number of samples taken per second. A higher sample frequency corresponds to higher reproduction quality but with larger size. We used sample frequencies of 44,100 Hz (44,100 samples per second), 22,050 Hz, and 11,030 Hz to encode our files.

  3. Bitrate. This specifies the quality of the MP3 file in a digital format, i.e. using bit values. A larger bitrate gives higher reproduction quality. Standard CD-quality MP3 files is 192 kbps, whereas our bitrate was only 32 kbps. More information about the MP3 standard may be found at Paolo Corsini’s website, including a table of bitrate versus compression ratios.

The FCC was established by the Communications Act of 1934 and is charged with regulating interstate and international communications by radio, television, wire, satellite and cable. In this particular application, the FCC rules and regulations govern the output power and broadcast frequencies of AM and FM (88.0 to 108.0 MHz in the United States) radio transmissions. The complete set of FCC regulations can be found in the U.S. Code of Federal Regulations 47CFR Part 73 (MIT website with links); however, to summarize, each channel has a bandwidth of 200 kHz and can pass audio and subcarrier frequencies up to 100 kHz. Deviation is often limited to 150 kHz total in order to prevent interference to adjacent channels/stations on the band. Stations may go up to 10% over this if they use stereo or other subcarriers (online dictionary with definition). In designing our FM transmitter, we must be careful not to interfere with radio broadcasts on the FM band, which mainly involves decreasing the output power to reduce the transmission distance and tuning the frequency to an unused portion of the FM band. Fortunately, the MAX2606 RF VCO chip broadcasts with an output power of -21 dBm into a 50 Ohms load (much less than the maximum acceptable emission of 10 dBm).

Due to the compact nature of MP3 files, they are often distributed and used in a manner that violates copyright laws. In fact, the illegal online distribution of audio tracks continues to be a major legal battle for the RIAA and accused “music pirates.” Since our device deals with the transmission of MP3 encoded audio files, it is important that we minimize any possibility for outside agents (i.e. another receiver nearby) to eavesdrop on the FM transmission. This may be in direct violation of the IEEE Code of Ethics and many copyright laws. Furthermore, since we encoded MP3 files directly, the user must be aware of all copyright issues and potential legal actions associated with the files.

IEEE Code of Ethics
It is imperative that our design meets all requirements stated in the IEEE Code of Ethics, particularly the following codes:

  1. To accept responsibility in making engineering decisions consistent with the safety, health and welfare of the public, and to disclose promptly factors that might endanger the public or the environment.

    We had to make sure that our broadcasts over the FM (88.0 to 108.0 MHz) band did not interfere with other radio transmissions, which may adversely impact the environment for other people. Just imagine you’re listening to your favorite song on the radio, and suddenly, some random, lewd song comes out of nowhere. We limited any possible interference by reducing the size of our transmitting antenna and output power so that our maximum transmission distance is only a few feet.

  2. To be honest and realistic in stating claims or estimates based on available data.

    We notify the user outright that our prototype MP3 radio is only capable to transmitting low-quality (32 kbps), mono-channel MP3 files due to reliability issues with the RS-232 protocol. Currently, we only send data at 38,400 baud, instead of the maximum 115,200 baud. We hope to increase this capability in future releases in order to provide better quality MP3 songs, but for the present, we are completely honest and realistic in stating our capabilities.

  3. To maintain and improve our technical competence and to undertake technological tasks for others only if qualified by training or experience, or after full disclosure of pertinent limitations.

    We focused on our core areas of expertise—Dave did a tremendous amount of work with the PC interface, RS-232 communication protocol, and MCU state-machine implementation, while Jian focused on the FM transmitter, STA013/CC4334, and analog interface designs. Both of us did a lot of research on these areas before implementing them in order to augment our technical competencies.

  4. To seek, accept, and offer honest criticism of technical work, to acknowledge and correct errors, and to credit properly the contributions of others.

    We were always open to suggestions from Professor Land, the lab TA’s, and other ECE476 students, particularly in the planning stages of the project. We initially proposed transmitting MP3 files at 433/900 MHz to a set of wireless headphones or speakers, but quickly found out the technical difficulties of such a project given our current constraints. From there, we worked with Professor Land to reorganize our project and with the TA’s along the way to check our progress.

  5. To assist colleagues and co-workers in their professional development and to support them in following this code of ethics.

    Like many of the other groups, we were always willing to help out other groups if needed; we were always truthful and realistic about our suggestions and answers. The soldering line was always a problem, particularly late in the semester, so we tried to be as efficient as possible and always yielded the seat to other groups as soon as we were done.

Intellectual Property Considerations
We had used some code from a previous year's group, as mentioned above. Moreover, we were given a terminal program, written in C, by a Bob Gardner. In both cases, we gave the original authors' credit for their work. The design of the FM transmitter circuit is found on the MAXIM-IC web site; and similarly, the design for the MP3 decoder was obtained from the PJRC web site.

Special Thanks
We would like to thank Professor Land for helping us so much throughout the course of the semester, particularly with all the sage advice given during lab, and for helping us solder the CC3443 24-bit decoder and MAX2606 RF VCO chips onto respective surfboards. Also, we would like to thank our lab TA’s, David Li and Jeannette Lukito for all their help. This course would have been a lot harder if not for their help on our lab problems. Finally, we’d like to thank MAXIM-IC, Analog Devices, and Fairchild Semiconductor for supplying us with sample chips, Paul Stoffregen of PJRC for a remarkably helpful page on the STA013 without which we would have been completely lost, and Chris Lehmann for helping us solder part of our MP3 decoder circuit.


Appendices
Files

iconv intl libgdk-0 libglib-2.0-0 libgtk-0
mmcache php4ts php_gtk libgmodule-2.0-0
Table 2. DLL files used

Cost

Item Manufacturer Part Number Cost
MP3 Decoder STMicroelectronics STA013 $12
24-Bit DAC Cirrus Logic CS4334 $5
Shipping & Handling PJRC   $5.18
14.7456 MHz Xtal Maxim-IC SE3431-ND $0.96
Solder Boards Professor Land   $2.50 (x1 large)
$2.10 (x3 small)

$4.90

Surf Boards Professor Land   $10
ATMega32 Atmel ATMEGA32-16PI $0 (free sample)
Voltage Regulator Maxim-IC MAX884 $0 (free sample)
IF VCO Maxim-IC MAX2606 $0 (free sample)
Resistors & Capacitors Digital & Analog labs   free
8-pin, 14-pin sockets Analog lab   free
STK-500 Digital lab   free
16 MHz Xtal Digital lab   free
  Total: $38.04
Table 3: Cost Analysis

Links
These awesome sites saved us countless hours.

Random pictures


Figure 16: Patented 3D Design

Figure 17: Dave Chai at the Computer, working hard


Figure 18: Jian Gong working on the adapter

Copyright © 2004. David Chai & Jian Gong. All rights reserved. [printer-friendly version]