AN1128

AN1128
TCP/IP Networking: Internet Radio Using OLED Display
and MP3 Audio Decoder
Author:
Howard Schlunder
Rodger Richey
Microchip Technology Inc.
FIGURE 1:
INTERNET RADIO
DEMONSTRATION BOARD
ICD 2
REAL ICE™
INTRODUCTION
Internet Radios are defined as a “hardware device that
receives and plays audio from Internet Radio stations
or a user’s PC”. The audio is streamed to the radio
using MPEG-1 Audio Layer 3 (MP3), Windows® Media
Audio (WMA) or Advanced Audio Coding (AAC)
compressed audio formats. The “radio stations” range
anywhere from public AM or FM radio stations that
broadcast over the air as well as on the Internet, to
University radio stations down to any individual wishing
to create their own radio station.
The idea of an Internet Radio is not a new idea. You can
buy commercially available Internet Radios, ranging in
price from $129 US to $400 US, from companies such
as Barix™, Logitech™/Slim Devices, Roku™ Labs and
Philips®. Most of these make the connection using
wired Ethernet; some have a wireless connection.
Power
Jack
Ethernet
Jack
Heartbeat
LED
Headphone
Plug
OLED
Display
Push Button
Switches
The focus of this application note is to show how to
create a low-cost Internet Radio that connects to
SHOUTcast servers and plays MP3 audio. The
hardware uses the PIC18F67J60 microcontroller with
integrated 10Base-T MAC and PHY and an external
MP3 audio decoder. The software uses the standard
Microchip TCP/IP Stack with external serial SRAM buffering to ease the streaming of compressed audio data to
the MP3 decoder. Figure 1 shows a picture of the Internet Radio Demonstration Board (DM183033) that is
available for purchase on MicrochipDirect or through
one of Microchip’s distributors. Figure 2 shows the block
diagram for the Internet Radio design used in this
application note.
© 2009 Microchip Technology Inc.
DS01128B-page 1
AN1128
FIGURE 2:
INTERNET RADIO BLOCK DIAGRAM
23K256 x 2
RJ45 MagJack
PIC18F67J60
®
32-Kbyte
Serial
SRAM
CS
32-Kbyte
Serial
SRAM
SPI
I/O Pins
I/O Pins
CS
10Base-T
MAC/PHY
I/O Pins
MP3 Audio
Connector
+5V to +9V
OLED Display
128 x 64
MCP1703
MAKING THE CONNECTION
The heart of this design is the PIC18F67J60 microcontroller. This MCU has an integrated 10Base-T MAC
and PHY peripheral in addition to the standard peripheral set of 64-pin PIC18 MCUs. It controls the entire
process, from making the connection to the audio
VS1011
server, to streaming the data to the MP3 decoder, to
displaying status on the LEDs and OLED display and
reading user input on the push button switches.
While this particular application does not use many of
the resources on the PIC18F67J60, it does have a full
complement of peripherals. Table 1 shows the feature
set for all PIC18FXXJ60 devices.
PIC18F66J60
64K
3808
8192
39
11
2/3
1
Y
Y
1
2
2/3
N
PIC18F66J65
96K
3808
8192
39
11
2/3
1
Y
Y
1
2
2/3
N
N
PIC18F67J60
128K
3808
8192
39
11
2/3
1
Y
Y
1
2
2/3
N
N
PIC18F86J60
64K
3808
8192
55
15
2/3
1
Y
Y
2
2
2/3
N
N
PIC18F86J65
96K
3808
8192
55
15
2/3
1
Y
Y
2
2
2/3
N
N
PIC18F87J60
128K
3808
8192
55
15
2/3
1
Y
Y
2
2
2/3
N
N
PIC18F96J60
64K
3808
8192
70
16
2/3
2
Y
Y
2
2
2/3
Y
Y
Device
Flash
SRAM
Data
Program
Memory Memory
(bytes)
(bytes)
MSSP
Ethernet
TX/RX
Buffer
(bytes)
I/O
10-Bit
A/D (ch)
CCP/
ECCP
SPI
Master
I2C™
Timers
PSP
8/16-Bit
External
Memory Bus
Comparators
PIC18FXXJ60 MICROCONTROLLER FAMILY FEATURES
EUSART
TABLE 1:
Headphone
Connector
N
PIC18F96J65
96K
3808
8192
70
16
2/3
2
Y
Y
2
2
2/3
Y
Y
PIC18F97J60
128K
3808
8192
70
16
2/3
2
Y
Y
2
2
2/3
Y
Y
DS01128B-page 2
© 2009 Microchip Technology Inc.
AN1128
The second crucial piece of this application is the
Microchip TCP/IP Stack. The Stack is what makes the
connection to the audio server and then receives the
audio stream for deployment to the MP3 decoder. The
Stack is a suite of programs that provides services to all
FIGURE 3:
TCP/IP-based applications. You don't need to know all
of the intimate details of the TCP/IP specifications to
use the Stack. Microcontrollers using embedded TCP/
IP Stacks can be used to enable a myriad of
applications, such as those shown in Figure 3.
EMBEDDED ETHERNET ENABLED APPLICATIONS
Lights
Pool
Leveler
Entry Monitor
Security
Cell Phone
Sprinkler
System
10 Mbps
Ethernet
Thermostat
Fire/Smoke
Detector
Office Phone
Games
Power
Based on the TCP/IP reference model, the Stack is
divided into multiple layers, where each layer accesses
services from one or more layers below it. Per the
specifications, many of the TCP/IP layers are “live”, in
the sense that they not only act when a service is
requested, but also when events like time-outs or new
packets arrive. The Stack is modular in design and
written in the C programming language. Typical
© 2009 Microchip Technology Inc.
implementations will use 30-60 Kbytes of code,
depending on which modules are included, leaving
plenty of code space on the PIC18FXXJ60 devices.
Table 2 shows many of the supported protocols. The
size of each protocol is not listed here in the application
note but is available in the help files that come with the
TCP/IP Stack.
DS01128B-page 3
AN1128
TABLE 2:
MICROCHIP TCP/IP STACK SUPPORTED PROTOCOLS
Application
Transport
HTTP
FTP
SMTP
Telnet
SNMP
NetBIOS
UDP
Bootloader
Ping
ICMP
IPv4, ARP
Ethernet – ENC28J60 or PIC18F97J60 Family
The Microchip TCP/IP Stack software provides many
essential services to implement the Internet Radio,
including protocols, such as TCP, UDP, DHCP, DNS, IP
and ARP. The Transmission Control Protocol (TCP)
transports the main MP3 audio and metadata while providing flow control to prevent the SHOUTcast server
from sending more data than can be held in the Internet
Radio RAM at any given time.
The User Datagram Protocol (UDP) transports DHCP
and DNS packets. The Dynamic Host Configuration
Protocol (DHCP) automatically provides the board’s IP
address, gateway address, subnet mask and other
configuration parameters when the Ethernet
connection is first established. These configuration
parameters tell the board how the network is organized
and how to reach the Internet. The Domain Name
System (DNS) is used whenever the user changes the
current radio station. It converts the radio station’s
static host name (ex: “scfire-dll-aa02.stream.aol.com”)
into a potentially dynamic IP address (ex:
149.174.134.200) which the rest of the TCP/IP Stack
protocols require.
The Internet Protocol (IP) transports both TCP and UDP
packets across the Internet to the correct destination.
However, before the IP transport can be used, the Stack
uses the Address Resolution Protocol (ARP) to obtain
the Ethernet MAC address (ex: 00-04-A3-BE-EF-1E)
associated with the local Internet gateway. All of these
services work simultaneously, or in tandem, to establish
the connection to the radio server and then ensure a
robust user listening experience. These protocols all
work in the background without requiring any manual
user configuration or intervention.
While this application is based on the PIC18FXXJ60
devices, the Stack has been optimized for use on any
PIC18, PIC24, dsPIC® or PIC32 device with enough
program memory. It includes support for the ENC28J60
Stand-Alone Ethernet Interface Controller for each of
these device platforms. The best part is that the Stack
is royalty-free and requires a no fee license agreement,
restricting use to Microchip microcontrollers and digital
signal controllers. The Stack can be downloaded at
www.microchip.com/tcpip. The files for the Internet
Radio are part of this distribution.
DS01128B-page 4
DNS
TCP
Internet and
Network
Access
Physical
DHCP
Now that we have the embedded application defined,
we need to have the audio source. There are many
sources of audio available off the Internet using file formats described previously. For this application, we will
focus on the SHOUTcast protocol and servers.
SHOUTcast is a freeware audio streaming technology
developed by Nullsoft™. SHOUTcast only uses MP3 or
AAC audio encoding and an HTTP-like protocol to
transfer files from the server to the client. SHOUTcast
is available in both server and client forms on Windows
95/98/ME/NT/2000/XP, Macintosh® OS X, FreeBSD™,
Linux and Solaris™ at www.shoutcast.com.
To make the connection from the PIC18F67J60 device
to the SHOUTcast server, we must send it a message.
The following example shows a typical data structure
within the Internet Radio code used to establish the
connection.
EXAMPLE 1:
stations[0].HumanName = "SKY.FM Top Hits, 96K";
stations[0].HostName =
"scfire-dll-aa02.stream.aol.com";
stations[0].port = 80;
stations[0].Message =
"GET /stream/1014 HTTP/1.0\r\n"
"Host: scfire-dll-aa02.stream.aol.com\r\n"
"Accept: */*\r\n"
"Icy-MetaData:1\r\n"
"Connection: close\r\n\r\n";
The structure, stations[ ], holds the information for
the various radio stations that are preprogrammed into
the microcontroller. Metadata refers to information
about the data. In the case of a SHOUTcast stream,
metadata refers to the song name and artist. If metadata is not enabled, the human readable name of the
radio station that is provided in the structure can be
displayed. With metadata enabled, the station name
can be automatically obtained from the SHOUTcast
server during the initial connection phase. In the current application, the HumanName string is not used. We
use the radio station name provided in the metadata
from the SHOUTcast server.
The remote DNS HostName is provided, specifying
where on the Internet the SHOUTcast server is
located. The TCP port through which the connection
is made follows. Normally, the port is 80, but can vary
depending on the setup of the SHOUTcast server
you are connecting to.
© 2009 Microchip Technology Inc.
AN1128
The last piece is the Message to initiate the connection
to the SHOUTcast server. The GET command specifies
the name of the audio file or stream on the server. The
Host specifies which target server we want to connect
to. In some cases, there are multiple servers running
through a single Internet IP address, and in most
cases, the Host parameter is always identical to the
HostName field. The Accept field indicates that we
are interested in receiving any audio data type, not limited to MP3s alone. In addition to MP3s, the Internet
Radio can also play uncompressed PCM WAV
streams. Icy-metadata determines if song metadata
should be inserted into the stream. The most common
data inserted is artist name and song title. In the current
application, we enable metadata and parse the incoming stream. Typically, the SHOUTcast server sends a
variable length block of metadata after every
8192 bytes of audio. We must continuously check the
location in the stream and extract the metadata. If the
metadata was not filtered out of the stream, the audio
decoder would play it, resulting in an audio glitch. The
Connection: close field notifies the server that it
should immediately disconnect our TCP client if the
server runs out of data to send us. This generally
occurs only during the initial connection phase if we
provide an invalid GET string, or the server is
overloaded and cannot handle another radio listener.
By immediately disconnecting, we can attempt to automatically reconnect or give up and switch to a different
radio station.
The typical response from the SHOUTcast server is
shown below. Each of the tags in this response starts with
an Icy prefix. This is part of the SHOUTcast protocol.
EXAMPLE 2:
ICY 200 OK
icy-notice1: <BR>This stream requires <a
href="http://www.winamp.com/">Winamp</a><BR>
icy-notice2: SHOUTcast Distributed Network Audio
Server/SolarisSparc v1.9.93atdn<BR>
icy-name: S K Y . F M - Top Hits Music who cares about
the chart order, less rap & more hits!
icy-genre: Pop Top 40 Dance Rock
icy-url: http://www.sky.fm
icy-pub: 1
icy-metaint: 8192
icy-br: 96
icy-irc: #shoutcast
icy-icq: 0
icy-aim: N/A
© 2009 Microchip Technology Inc.
The main information used by the Internet Radio
application is the following:
• icy-name – radio station name
• icy-metaint – the interval at which metadata
arrives in the audio stream
• icy-br – the bit rate in kbps of the audio stream;
the bit rate can also be read out of the MP3
decoder chip
If the radio receives the icy-name SHOUTcast
response, the MP3 client task will execute a callback
function, allowing the main application to save the
result. The callback is NewServerTitleProc(BYTE
*strServerTitle), where strServerTitle is set
to the contents of icy-name. The string is volatile and
must be saved by the main application code if it wishes
to continue using the string after returning from the
callback function.
The other tags are not meaningful for this application so
are discarded automatically by the MP3 client task. Once
we receive the server response, the audio stream
follows, which we will discuss in the next section.
Two useful pieces of information, usually transferred as
metadata in the audio stream, are the song title and
author. The MP3 client code checks at every metadata
interval (icy-metaint), usually every 8192 bytes, for
the following text:
• StreamTitle='<artist name, song name>';
• StreamUrl='<url>';
The callback function, NewStreamTitleProc(BYTE
*strStreamTitle), provides the contents of the
StreamTitle metadata. Here again, the data is
volatile and must be saved by the application.
Providing this data makes a big difference in customer
satisfaction with the Internet Radio because the song
title and artist can be displayed.
DS01128B-page 5
AN1128
DECODING THE AUDIO STREAM
stripped off while being transferred out of the Ethernet
module SRAM and are not stored in this external
32K x 8 SRAM. The TCP protocol communicates the
amount of free space in this external SRAM chip back
to the remote SHOUTcast server, permitting the
SHOUTcast server to throttle the data transmission to
prevent buffer overflow. Similarly, a large amount of
free space communicated to the SHOUTcast server
encourages the transmission of more audio data to
prevent buffer underflow.
The ~4 Kbytes of general purpose RAM inside the
PIC18F67J60 are not enough to buffer the incoming
audio stream and keep up when experiencing excessive packet loss on the Internet. The TCP transport
protocol carrying the MP3 data across the Internet has
a variable retransmission delay, which can be 300 ms
or longer for packets that get lost. This requires a larger
RAM buffer, which would allow the software to have
enough audio data buffered which can compensate for
these variable latency issues. The result of not enough
RAM are clicks and pops in the audio output resulting
from missing packets.
In the main() program loop, the MP3Client.c application module periodically copies data out of the TCP
buffer and into the second 32K x 8 SRAM chip. While
being copied, the application strips out the song title
and other metadata from the stream and displays it on
the OLED. The second external SRAM is written with
the raw MP3 stream with no extraneous metadata,
allowing minimal processing before being finally copied
into the VS1011 audio decoder.
In order to provide more RAM, two external serial
SRAMs from Microchip Technology (23K256) provide a
total of 64 Kbytes; 32 Kbytes for the TCP layer and
32 Kbytes for the audio buffer. Figure 4 shows a flow
diagram for the incoming stream for the server.
The SPI SRAM chips are functionally isolated from
each other; however, they are both serving the function
of implementing FIFO buffers. In the first chip instance,
the 32K x 8 SRAM bolts directly into the TCP module of
the TCP/IP Stack. The TCP layer stores all incoming
application layer data in this chip. This includes the
MP3 stream with the embedded song title and other
metadata. All TCP, IP and Ethernet headers are
FIGURE 4:
Periodically, during code execution, a timer expires and
triggers the MP3Client.c application’s Interrupt
Service Routine (ISR). In the ISR, the MP3 data is
copied out of the second external SRAM and written
directly to the VS1011 audio decoder. The VS1011
signals to the ISR when more data is required by
asserting its DREQ signal output.
DATA FLOW DIAGRAM USING EXTERNAL SERIAL SRAM
Microchip Internet Radio
PIC18F67J60
VLSI VS1011
MP3 Decoder
and DAC
MP3Client.c
Application
Interrupt Context
MP3Client.c
Application
main() Context
OLED
display
and push
buttons
SHOUTcast
Shoutcast
Server
Server
DS01128B-page 6
Internet
Ethernet Module
8K x 8 SRAM
256K
32K xx 88
SPI
SPISRAM2
SRAM
23K256
256K
32K x 8
SPI
SPI SRAM
SRAM
23K256
Microchip TCP/IP
Stack
(TCP Layer)
© 2009 Microchip Technology Inc.
AN1128
With the audio data buffered, we can stream it to the
MP3 decoder. As mentioned before, we need to strip out
the metadata; otherwise, the MP3 decoder tries to
decode this as compressed audio data which results in
blips in the reconstructed audio output. For this application, we selected the VS1011 MPEG Audio Codec from
VLSI Solution Oy. This device contains all the necessary
components for decoding and playing the audio stream:
• High-performance, low-power processor core
• Decodes MPEG 1.0 and 2.0 Audio Layer III, WAV,
PCM and IMA ADPCM
• Up to 320 Kbit/s MP3
• Volume, bass and treble controls
• High-quality stereo DAC
• Stereo earphone driver capable of 30Ω loads
• Separate serial control and data interfaces
© 2009 Microchip Technology Inc.
Figure 5 shows a generic block diagram of the connection between the PIC18F67J60 and the VS1011. The
following signals, with descriptions, are used:
•
•
•
•
•
•
•
SO – SPI serial output
SI – SPI serial input
SCLK – SPI serial clock
xCS – SPI chip select for commands
xRESET – chip Reset
xDCS – SPI chip select for data
DREQ – data request
DS01128B-page 7
AN1128
FIGURE 5:
MCU TO MP3 DECODER CONNECTIONS
2.7V AVDD Limits 2.5V-3.6V
10 μF
6.3V
100 nF
AGND
2.7V
DVDD Limits 2.5V-3.6V
10 μF
6.3V
100 nF
GND
VS1011
30
29
28
23
3
PIC® Microcontroller
or
Digital Signal Controller
SO
SI
SCLK
XCS
XRESET
DVDD
DGND 22, 21, 20, 16, 4
8
AVDD
OPEN
13
XDCS/BSYNC
LEFT
18
XT1/HCLK RIGHT
17
XT2
GBUF
33
34
9
10
32
100K
GND
33 pF
19, 14, 6
45, 43, 38
GND
46
39
42
GPD0
GPD1
GPD2/OCLK
44
GPD3/SDATA RCAP
AGND 47, 41, 40, 37
TEST
1M
100 nF
AGND
33 pF
AGND
24.576 MHz
Connect AGND to GND together as close
to the chip as possible
100K 100K 100K 100K
GND
GND
GND
AGND
20
20
10
CN1
AVDD
100n
47n
10n
47n
GND GND GND
DS01128B-page 8
ESD protection type
diodes should be used
GND
© 2009 Microchip Technology Inc.
AN1128
Once the chip is configured, we only need to feed it
data when it requests it. The occasional request to
change volume, bass or treble is fed to the SPI control
interface and does not interfere with data transfer. The
software monitors the DREQ line from the VS1011, and
while asserted, feeds data to the device. When DREQ
goes high, it indicates that the VS1011 is capable of
accepting at least 32 bytes of data. If DREQ goes low,
the firmware stops sending data.
As mentioned before, the VS1011 has controls for
volume, bass and treble. We had to make some tradeoffs at this point. Our display was small and we only
had three push button switches. Our goal was a simple
user interface. We, therefore, only have control of radio
station, volume and bass; treble was left out.
Volume is controlled by the SCI_VOL register in the
VS1011. It is a 16-bit register, with the upper 8 bits for the
left channel and the lower 8 bits for the right channel. A
value of 0 represents the highest volume and a value of
254 represents total silence. Each step represents a
0.5 dB increment. On power-up of the application,
the volume of both channels is set to 31. The
SetVolume(BYTE vRight, BYTE vLeft) function
is used to modify the volume. It follows the device
settings, where 0 is maximum volume and 254 is
silence.
Bass is controlled in a similar manner. The SCI_BASS
register in the VS1011 contains controls for both bass
and treble. Bass control has two settings: bass boost
and frequency limit. The boost control value ranges
from 0 to 15, with 0 being off and each step representing 1 dB of bass enhancement. The frequency limit also
has a 2 to 15 range with each step representing increments of 10 Hz. The SetBassBoost(BYTE bass,
BYTE gfreq) function is used to set both.
USER INTERFACE
Now that the hardware and software is set up and working, we need to provide status feedback to the user and
allow them to control the application. The discrete LED
provides a heartbeat from the TCP/IP Stack, indicating
that the TCP/IP Stack is operating correctly.
The application provides three push button switches for
control. The push button switches are used to navigate
the simple menu structure which is displayed on the
OLED display. You can change the channel forward or
backward, and increase or decrease the bass and
volume levels.
The OLED display allows the application to display the
status of the Internet Radio. It provides the radio station
name, the song title and artist, and also the navigation
menu to change the radio station, bass and volume.
This display is a monochrome, 128 x 64 display from
OSD Displays, part number OSD-2864ASWAG01.
© 2009 Microchip Technology Inc.
OLED displays provide excellent contrast, high brightness, low-power, fast response times, wide viewing
angles and several colors. The only two drawbacks to
the display are the lifetime and burn-in. This display
has a life of 10,000 hours at maximum brightness. The
life can be extended by adding an ambient light sensor
and dim the display according to the ambient light. The
OLED displays can also suffer from burn-in of images
displayed. It is therefore recommended that a screen
saver is implemented when images are displayed for
long periods of time. For the purposes of this application, the navigation menu is blanked after 60 seconds
and the radio station name and song title and artist are
constantly rotated at 1 character shift per second. This
ensures that there is no static image displayed for more
than 60 seconds.
The particular display used in this application is available with SPI, I2C™, and both 68 and 80 series parallel
interfaces. The only difference between the Serial and
Parallel modes is that you can not read from the display
in the Serial modes. The Parallel mode is implemented
in this application because we wanted to use a put pixel
subroutine which requires reading the contents of
memory and then modifying one bit of data. The other
feature of this display is that it provides a voltage boost
driver circuit that can be used with an assortment of
external components to create the 9-12V required for
the drive circuit.
The OLED display uses the SH1101A driver from Sino
Wealth. The 132 x 64-bit RAM is organized as 8 pages,
0 through 7, as shown in Figure 6. The OSD Displays
supplied OLED display has only 128 columns, and
therefore, has 4 extra bytes. Note that the first column
that is visible on the display starts at column 2, not 0,
as one would expect.
FIGURE 6:
GRAPHIC DISPLAY DATA
RAM FOR THE OLED
DISPLAY
Page 0 (Area Color Section)
Page 1 (Area Color Section
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
DS01128B-page 9
AN1128
Each page of the driver is arranged as shown in
Figure 6. Each byte written to the display is shown
vertically. This results in a page being 8 pixels high by
128 pixels wide. As Figure 7 shows, the Least
Significant bit is towards the top of the page and the
FIGURE 7:
Most Significant bit is towards the bottom of the page.
In the example shown, page 2 is selected and the
fourth byte in the page is written with 0xFF, which turns
all bits in that column on.
PAGE 2 EXAMPLE SHOWING STRUCTURE OF RAM vs. WHAT IS DISPLAYED
SEG0
SEG2 (First visible column)
SEG131
LSb [D0]
Page 2
••••••••••••
MSb [D7]
This application displays an initial welcome screen.
The opening graphic is 128 x 64 pixels and the image
is stored in the file, OSDOLED.c. We use the function,
oledPutImage(rom unsigned char *ptr,
unsigned char sizex, unsigned char sizey,
unsigned char startx, unsigned char
starty), to write this image to the display. This function allows a variable image size and placement on the
display. We provide a pointer to the array of data, the x
and y size of the image, and also the x and y
coordinates to start.
The application also provides a font. The font is stored in
the file, OSDOLED.c, and is only the characters from
0x20 to 0x7E on the ASCII chart. Since most applications don't use the characters outside this range, we
remove them from the array to save memory. The font is
5 x 8 with the last line being blank. There are two functions associated with writing characters to the display.
Characters can be written as 1 or 2 pages high using the
functions, oledWriteChar1x(char
letter,
unsigned char page, unsigned char column)
or oledWriteChar2x(char letter, unsigned
char page, unsigned char column). Because of
the structure of the display, font sizes are limited to page
height boundaries. For one-page tall characters, you
DS01128B-page 10
select the page and starting column. The character is
written to the page at the starting column address. The
function does not check to see if the starting column
value is within the size of the display. For the two-page
tall characters, the only difference is that the page states
the 1st of two pages to display the characters. This
function also performs no checking on location.
In this application, pages 0 and 1 are used to display
the song title. Pages 2 and 3 display the URL as
obtained through the metadata. These pages are
shifted from left to right, to display text longer than the
width of the display. Page 4 displays the IP address
obtained through DHCP. Pages 5-7 are used for menuing. Page 5 is only used on the submenus to display
which submenu the application is currently in. Pages 6
and 7 display the action that is taken by pushing the
corresponding push button switch. These pages disappear after 60 seconds as part of the screen saver. Any
press of a push button switch will display the menu for
input.
To better understand the operation of this display, it is
recommended that you obtain copies of the SH1011A
data sheet and the OSD Displays OLED data sheet.
See the “References” section for more details.
© 2009 Microchip Technology Inc.
AN1128
DEBUGGING INTERNET
CONNECTIONS
When developing applications using TCP/IP and Ethernet, you may find an instance where having a tool to
debug an issue is required. When developing the
SHOUTcast interface code, we used a tool called
Wireshark to figure out what an application sends to a
SHOUTcast server to initiate the stream, what the
server responds with and how the metadata is embedded in the audio stream. Wireshark allows data to be
captured from TCP/IP connections on your PC. You
can use Winamp or other player software to make
connections to SHOUTcast servers and capture the
data streams. The other important piece of information
acquired with Wireshark is the IP address and port
number for these Internet Radio stations. This is
needed to make the connection. Wireshark is a free
download available at http://www.wireshark.org.
FUTURE CONSIDERATIONS
This application note was designed to provide an
example of the capabilities of 8-bit microcontrollers running TCP/IP Stacks and interfacing to existing Internet
infrastructure. There are many improvements that can
be made to make the Internet Radio design more
desirable and customer friendly.
The first change is more for aesthetics than performance. Many handheld devices are using QVGA
graphics LCDs to display information. These displays
are quite powerful, ranging in colors from 256 to more
than 65,000 colors. They are often packaged with a
resistive touch screen that can replace any push button
switches. The combination of the two can result in a
very powerful user interface to the Internet Radio.
Companies such as Ramtex Internation ApS, Segger
Microcontroller Systems and Microchip offer graphics
LCD libraries that greatly simplify the interface to the
display and generation of objects, menus, etc.
© 2009 Microchip Technology Inc.
The second potential change to the application pertains
to applications that require more processing power
than the PIC18F67J60 can provide. Microchip offers a
wide range of 16-bit microcontrollers that increase the
performance up to 40 MIPs. The PIC24F microcontrollers offer 16 MIPs of performance and many
peripherals, such as a Parallel Master Port (PMP) to
interface to graphics LCDs or the Peripheral Pin Select
(PPS) module that allows efficient use of I/O pins.
Microchip also offers 32-bit microcontrollers in our
PIC32 product line with all the same features of PIC24,
with up to a 1.5 DMIPS/MHz core. To add the Ethernet
interface capability, the ENC28J60 from Microchip
provides the same Ethernet MAC and PHY used in the
PIC18F67J60, but in a 28-pin stand-alone package
with SPI connection.
Finally, connections to a subscription-based audio
streaming web site, such as Slacker™, Pandora,
Live365, etc., can be developed to provide unique
audio streaming capabilities. These services allow
users to define playlists and select artists to tailor the
audio stream to the listener.
CONCLUSION
At first, the idea of creating an Internet Radio on anything other than a 32-bit microcontroller may not seem
feasible. Once the data rates of streaming audio are
considered and application overhead is understood,
the processing power of the PIC18F67J60 family of
microcontrollers coupled with an integrated 10Base-T
MAC/PHY can be used to create the basic platform for
these radios. The extra bandwidth can be applied to
enhance the user interface with touch screens and
graphics LCDs.
Many thanks to Professor Dr. Francesco P. Volpe and
Christoph Stein from the Microcomputer Lab at the
University of Applied Sciences Aschaffenburg in
Germany for their innovative use of PIC microcontrollers
in Ethernet applications.
DS01128B-page 11
AN1128
MEMORY USAGE
REFERENCES
Total Flash program memory on
PIC18F67J60 = 131,072 bytes
SH1011A Data Sheet – www.sinowealth.com
Total memory used by Internet Radio = 40 Kbytes
VS1011 Data Sheet and Application Notes – www.vlsi.fi
Main routine = 4.7 Kbytes
23K256 Data Sheet – www.microchip.com
OLED driver (includes font and introductory
image) = 2.7 Kbytes
SHOUTcast – www.shoutcast.com
VS1011 driver = ~1 Kbyte
MP3 client = ~2.5 Kbytes
Intro graphics image = ~1 Kbyte
Font table = ~0.5 Kbytes
Miscellaneous routines = ~2.6 Kbytes
TCP/IP Stack protocols = ~26 Kbytes
OSD-2864ASWAG01 – www.osddisplays.com
Microchip TCP/IP Stack – www.microchip.com/tcpip
PIC18F97J60 Family Data Sheet – www.microchip.com
Original Internet Radio Design
Prof. Dr. Francesco P. Volpe & Christoph Stein,
Microcomputer Lab, University of Applied Sciences
Aschaffenburg, Wuerzburger Strasse 45, D-63743
Aschaffenburg, Germany; [email protected]
Protocols used = TCP, UDP, DHCP, PIC18F97J60
Ethernet driver, ARP, IP, DNS
Total data memory on PIC18F67J60 = 3808 bytes
Total data memory used by Internet Radio = 1820 bytes
Audio and TCP/IP Stack buffering uses 64 Kbytes from
the external serial SRAMs.
DS01128B-page 12
© 2009 Microchip Technology Inc.
+3.3V
C16
1 MF
C9
1 MF
10K
R23
C10
.1 MF
2
10uH
L2
16
15
14
13
12
11
10
9
8
7
6
5
4
3
D3
RE4
RF2/AN7/C1OUT
RF3/AN8/C2INB
RF4/AN9/C2INA
RF5/AN10/C1INB/CVREF
RF6/AN11/C1INA
RF7/ SS1
VDDCORE/VCAP
VSS
RG4/CCP5/P1D
MCLR
RB3/INT3
RB2/INT2
RB1/INT1
RB0/INT0
RE0/P2D
RE1/P2C
.12 ohm 1%
R24
MGSF1N02LT1
10 MF
C20
D4
D5
D6
D7
D/C
MCLR
VS_CS
XDCS
DREQ
D0
D1
17
D Q1
S
ENVREG
D5
RE5
G
+3.3V
C14
.1 MF
MBR0520
18
+3.3V
RF1/AN6/C2OUT
RF1
1
D2
64
RE2/P2B
63
RE3/P3C
62
RE4/P3B
61
20
AVDD
19
xRESET
RE5/P1C
AVSS
60
RD0/P1B
RA3/AN3/VREF+
RESET
59
RD1/CCP3/P3A
57
58
U1
PIC18F67J60
24
RA1/LEDB/AN1
23
R15
C34
6.8uF_Tant
110K 1%
R16
930K 1%
LEDB
VSS
25
RA0/LEDA/AN0
LEDA
21
R/W
RD2/CCP4/P3D
C2
.1 MF
26
RA2/AN2/VREF22
VDD
56
VSS
55
VSS_TXPLL
VDD
54
VDD_TXPLL
RA5/AN4
27
+3.3V
TPOUT+
4.7 MF
TPOUTVSS_OSC
RB6/KBI2/PGC
RB5/KBI1/PGM
RB4/KBI0
VSS_RX
TPIN-
TPIN+
VDD_RX
R2
1 MF
R13
D7
D5
D3
D1
VPP
R/W
RESET
+3.3V
820K
VCOMH
C19
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
IREF
D6
D4
D2
D0
E
D/C
CS
RC2
SCLK
SO
SI
RB7
RB6
RB5
RB4
TPIN-
TPIN+
2.26K 1%
+3.3V
RESET
RC2/CCP1/P1A
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RB7/KBI3/PGD
VDD_OSC
OSC1/CLKI
OSC2/CLKO/RA6
VBREF
FB
SW
C13
1000 pF
C30
C15
.1 MF
CS
53
RBIAS
52
29
RA4/T0CKI
28
E
VSS_TX
RC1/T1OSI/CCP2/P2A
50
TPOUT-
49
VDD_TX
RC7/RX/DT
51
TPOUT+
RC0/T1OSO
30
RC6/TX/CK
31
© 2009 Microchip Technology Inc.
32
TXD
RXD
+3.3V
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
+3.3V
J5
C8
33 pF
TPIN-
TPIN+
L1
C5
1
2
3
R25
R26
.1 MF
TPOUT-
TPOUT+
CS10-25.000MABJTR
C7
33 pF
25 MHz
Y1
+3.3V
Jameco 252735 Power Supply
5V 2.5A
NC
GND
SW
VDD2
FB
SENSE
VBREF
VDD1
C86
PS
CS
RES
A0
WR
RD
VCOMH
VPP
D0
D1
D2
D3
D4
D5
D6
D7
IREF
NC
4
3
2
1
C11
.1 MF
+3.3V
C6
.1 MF
+3.3V
C4
.1 MF
+3.3V
C1
.1 MF
2.2 MF
C31
2
2
R12
R9
R8
R7
R5
R4
C3
.1 MF
LEDB
LEDA
2
180
180
49.9
49.9
49.9
49.9
2
Yellow
Grn/Orn
IN
1
GND
OUT
MCP1703-3302E/MB
C29
.1 MF
3
08B0-1X1T-36-F
7
8
10
9
5
6
4
3
1
J1
220 MF
C33
+3.3V
J4
J5
J6
J7
J8
J3
J2
J1
RE5
SO
100K
ICD Connector
RB6
RB7
MCLR
+3.3V
RB4
10K
6
5
4
3
2
1
S1
+3.3V
SO
R34
RE4
100K
+3.3V
R10
+3.3V
R33
4
3
2
1
4
3
2
1
U4
R6
U6
Vcc
RF1
10K
R14
5
6
7
8
5
6
7
8
180
+3.3V
SI
SCK
HOLD
N256S0830HDA
23K256
GND
NC
SO
CS
SI
SCK
HOLD
Vcc
N256S0830HDA
23K256
GND
NC
SO
CS
J4
RC2
S3
SCLK
SI
SCLK
SI
RB5
10K
R11
+3.3V
C39
.1 MF
+3.3V
C32
.1 MF
+3.3V
D3
S2
FIGURE A-1:
TXD
APPENDIX A:
RXD
+3.3V
AN1128
SCHEMATICS
INTERNET RADIO SCHEMATICS (SHEET 1 OF 2)
DS01128B-page 13
CS10-24.576MABJ-UT
C27
22 pF
C28
Y2
R19
22 pF
1M
VS_CS
AVDD
AVDD
24
23
22
21
20
19
18
17
16
15
14
13
NC
xCS
DGND4
DGND3
DGND2
DVDD2
XTALI
XTALO
DGND1
NC
DVDD1
xDCS/BSYNC
11
+3.3V
10K
R18
25
xDCS
12
NC
NC
DREQ
10
NC
NC
26
GPIO3/SDATA
NC
27
GPIO2/DCLK
9
29
SCLK
28
SCLK
8
AVDD
U2
VS1011
30
DREQ
7
+3.3V
10K
R17
31
SO
SO
SI
SI
NC
6
DVDD0
NC
5
NC
TEST
32
4
DGND0
GPIO0/SPIBOOT
33
3
xRESET
GPIO1
34
2
NC
NC
R22
NC
AGND0
AVDD0
RIGHT
AGND1
AGND2
GBUF
AVDD1
RCAP
AVDD2
LEFT
AGND3
100K
1
NC
NC
DS01128B-page 14
35
37
38
39
40
41
42
43
44
45
46
47
48
R32
100K
AVDD
AVDD
AVDD
10
10
C25
100 nF
R30
R29
C38
100 nF
C17
C36
10 nF
C35
20
20
10 nF
R21
10 MF
R20
RIGHT
LEFT
C18
100 nF
C23
100 nF
47 nF
C37
10
R31
L3
AVDD
47 nF
C26
10 MH
+3.3V
J2
MG054S05X150DP
D4
5
4
3
2
1
FIGURE A-2:
36
xRESET
AN1128
INTERNET RADIO SCHEMATICS (SHEET 2 OF 2)
© 2009 Microchip Technology Inc.
AN1128
APPENDIX B:
SOFTWARE
FLOWCHARTS
Since the TCP/IP Stack is very large, the software
flowchart is only for the main routine found in the
MainDemo.c file. The files are part of the Microchip
TCP/IP Stack distribution that can be found at
www.microchip.com/tcpip.
FIGURE B-1:
MAIN ROUTINE SOFTWARE FLOWCHART (MainDemo.c)
MainDemo.c
Initialize Device
NO
Initialize TCP/IP
Stack
Time Elapsed
= 60 secs?
YES
Initialize OLED
menuState = IDLE
Initialize VS1011
Clear OLED Lines
5,6,7
NO
Time Elapsed
= 0.5 sec?
Time Elapsed
= 1 sec?
YES
YES
Toggle LED0
Station Name
> 21
NO
YES
Shift Song Name
Left 1 Character
Call Stack and
Protocol Tasks
Is DHCP
Bound?
YES
Song Name
> 21
NO
YES
Shift Song Name
Left 1 Character
MP3ClientTask()
Process
Push Button
Switches
Time Elapsed
= 16 secs?
Track IP Address
Renewals since
Reset
YES
menuState =
MENU
Reset OLED to
menuState
© 2009 Microchip Technology Inc.
DS01128B-page 15
AN1128
NOTES:
DS01128B-page 16
© 2009 Microchip Technology Inc.
Note the following details of the code protection feature on Microchip devices:
•
Microchip products meet the specification contained in their particular Microchip Data Sheet.
•
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•
Microchip is willing to work with the customer who is concerned about the integrity of their code.
•
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro,
PICSTART, rfPIC, SmartShunt and UNI/O are registered
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
FilterLab, Linear Active Thermistor, MXDEV, MXLAB,
SEEVAL, SmartSensor and The Embedded Control Solutions
Company are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, In-Circuit Serial
Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB
Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM,
PICDEM.net, PICtail, PIC32 logo, PowerCal, PowerInfo,
PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total
Endurance, WiperLock and ZENA are trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2009, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
© 2009 Microchip Technology Inc.
DS01128B-page 17
WORLDWIDE SALES AND SERVICE
AMERICAS
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
Asia Pacific Office
Suites 3707-14, 37th Floor
Tower 6, The Gateway
Harbour City, Kowloon
Hong Kong
Tel: 852-2401-1200
Fax: 852-2401-3431
India - Bangalore
Tel: 91-80-3090-4444
Fax: 91-80-3090-4080
India - New Delhi
Tel: 91-11-4160-8631
Fax: 91-11-4160-8632
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Santa Clara
Santa Clara, CA
Tel: 408-961-6444
Fax: 408-961-6445
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
Korea - Daegu
Tel: 82-53-744-4301
Fax: 82-53-744-4302
China - Hong Kong SAR
Tel: 852-2401-1200
Fax: 852-2401-3431
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
China - Nanjing
Tel: 86-25-8473-2460
Fax: 86-25-8473-2470
Malaysia - Kuala Lumpur
Tel: 60-3-6201-9857
Fax: 60-3-6201-9859
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
Malaysia - Penang
Tel: 60-4-227-8870
Fax: 60-4-227-4068
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
Taiwan - Hsin Chu
Tel: 886-3-572-9526
Fax: 886-3-572-6459
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-536-4803
China - Xiamen
Tel: 86-592-2388138
Fax: 86-592-2388130
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
China - Xian
Tel: 86-29-8833-7252
Fax: 86-29-8833-7256
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
China - Zhuhai
Tel: 86-756-3210040
Fax: 86-756-3210049
01/16/09
DS01128B-page 18
© 2009 Microchip Technology Inc.
Similar pages