This is only a preview of the September 2012 issue of Silicon Chip. You can view 22 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Colour MaxiMite Microcomputer, Pt.1":
Items relevant to "Barking Dog Blaster: Shut That Annoying Mutt Up!":
Items relevant to "USB Test Instrument Interface For PCs":
Items relevant to "Digital Sound Effects Generator":
Purchase a printed copy of this issue for $10.00. |
Pt.1: By GEOFF GRAHAM
The COLOUR
MAXIMITE
A PIC32-Based Microcomputer With Colour Output & Stereo Audio
The original Maximite microcomputer (March-May 2011) has been
a huge hit with readers and thousands are now in use all over the
world, from Australia to Russia. So how do you improve on such
a big hit? How about by adding eight vibrant colours and a stereo
music synthesiser for a start? The result is stunning and it takes the
Maximite to a whole new level.
T
HE MAXIMITE is a small, self-contained computer that is ideal for
experimenting, learning programming
and for use as an embedded controller. It uses a standard VGA monitor
for display, a standard PS2 keyboard
for input and an SD card for storage.
It includes its own operating system
and BASIC programming language
(called MMBasic), so you do not need
to tether it to a larger computer. It also
starts up instantly, so you can just
plug it in and immediately get going
by entering commands and a program.
The new Colour Maximite has 40
input/output (I/O) lines which can be
22 Silicon Chip
independently configured as analog
inputs, digital inputs or digital outputs. You can measure voltages and
frequencies, detect switch closures,
and so on, and get it to respond by turning on lights, closing relays, etc – all
under control of your BASIC program.
Perhaps the most amazing thing
about the Colour Maximite is that,
like its predecessor, everything (VGA,
USB, colour, music, etc) is generated
by a single chip that costs less than
$10.
For people who are familiar with
the original Maximite, the Colour
Maximite has a similar component
count so the cost of building the colour
version should be about the same. It’s
also reasonably easy to build; just an
hour or two is all that’s needed.
Suggested uses
What would you want to use the
Colour Maximite for? Well, for a start,
you could simply use it as a small computer that will remind you of the early
days of personal computing, when
computers were less complicated and
much easier to use. The Colour Maximite allows you test your programming
skills and have fun creating small
programs that can do anything from
siliconchip.com.au
Now with
100-pin micro
&
Arduino conne
ctor
Features & Specifications
•
•
Self-contained high-performance microcomputer.
Microchip 32-bit processor running at 80MHz with 512KB flash memory and
128KB RAM.
•
Colour VGA output, 480 x 432 pixels with eight colours (black, red,
green, blue, cyan, yellow, purple and white).
•
•
•
Standard PS/2-style keyboard input.
Stereo audio synthesiser for music and sound effects.
Battery backed real-time clock (optional).
• 20 external I/O lines which can be configured as analog inputs, digital
inputs/outputs, frequency measurement, etc.
• Arduino compatible connector with an additional 20 I/O lines that
are independent of the original 20 I/Os.
•
•
SD card support – up to 32GB for storing programs and files.
USB port for connecting to a personal computer (Windows, Mac or Linux)
as a terminal or for file transfer.
•
•
•
Extensive communications protocols including serial, I2C, SPI and 1-wire.
2-channel audio/analog/PWM analog output.
Graphic capability includes selectable fonts, user designed fonts, drawing
lines, circles, squares and control over any pixel with any colour.
•
Special commands for animated games. BLIT will copy a block of the
video screen at high speed and SPRITE will create animated sprites
that can be moved on the screen without disturbing the background.
•
•
•
•
Firmware upgrades via USB.
Full-featured BASIC interpreter and operating system.
Instant on (ready for you to type in and test programs).
Powered from USB, 9V plugpack or battery.
Note: new features for the Colour Maximite shown in bold.
discovering prime numbers to hunting
the Wumpus. It will take you back to
the days when the Tandy TRS-80 and
Commodore 64 were hi-tech.
A second use for the Colour Maximite is in controlling the outside world.
As stated, with its 40 I/O pins, you can
use the Colour Maximite as an embedded controller to monitor voltages and
signals and then respond by operating
motors, turning on lights or driving an
LCD. The Arduino connector makes
it easy to add your own customised
circuits or relay drivers to interface
to the real world.
There are already many Maximites
out there that are used by readers to
monitor GPS receivers, control windmill power systems and many other
tasks both complex and simple. With
double the number of I/O pins compared to its predecessor, the Colour
Maximite can be used for even more
complex projects.
The Colour Maximite also supports
a wide range of communications protocols – serial, I2C, SPI and 1-wire.
siliconchip.com.au
These are mostly used for communicating between semiconductor chips
so, using the Colour Maximite, you
can easily measure temperatures, log
data or interface with a test instrument.
The Colour Maximite should also
encourage another group of readers who enjoy writing and playing
animated games. Colour is especially
useful for games and the Colour Maximite has a special high-speed colour
mode designed for that use. Version
4.0 of MMBasic also has some special
commands (BLIT and SPRITE) that are
designed to move video images around
the screen – just what you need for an
animated game.
Colour, colour
The technique for producing colour
was developed by Dr Kilian Singer,
a Maximite fan at the University of
Mainz in Germany. He built a prototype Maximite on a breadboard, started
experimenting with it . . . and came up
with colour.
The technique he used is deceptive-
ly simple. The monochrome Maximite
generates its image by tying the three
colour inputs on the monitor together
and drives them with a single SPI
channel (we will delve more into that
technique later). To generate colour,
we just use three separate SPI outputs
to independently drive the three colour inputs to the monitor.
Sounds simple – so why didn’t we
do that in the first place and give the
original Maximite colour?
The answer is that the original
Maximite did not have the speed or
memory capacity. But with successive
releases of the Maximite firmware, we
have optimised its speed and memory
usage to the point where this technique
is now viable.
It’s not a completely free lunch
though. Generating colour uses more
of the processor’s time so, with eight
colours, programs will run about 25%
slower and there’s less free memory
than when generating a single colour.
Most readers won’t notice this so it
is a worthwhile trade-off. And in any
September 2012 23
but you need to be aware that many
require a specialised driver to be included in your program (which must
be written in the C language).
For this reason, we recommend that
the Colour Maximite’s Arduino connector be used with simple prototyping boards, relay boards and others
that do not require special software to
drive them and can work with 3.3V.
There are plenty of these out there and
they are very cheap.
With the Arduino-compatible connector, you can construct special
circuits on a prototyping board and
permanently add them to your Colour
Maximite. This feature can be used for
adding signal amplifiers, relay drivers
and many other simple applications.
Stereo audio output
The Colour Maximite interfaces to a VGA monitor and a standard PS/2 key
board. You can see how small the unit is compared to these external parts.
The monitor is shown here displaying the start-up screen, with MMBasic
loaded and ready to run programs.
case, you can easily switch into monochrome mode within your programs
and get the speed and memory of the
monochrome version if required.
ger (14 x 14mm) but we have plenty
of space on the PCB so that’s not a
problem.
New PIC32 chip
With the 100-pin chip, you also get
a lot more I/O pins so we decided to
put them to good use.
First, we decided to add an Arduinocompatible connector. This provides
an additional 20 I/O pins that can be
controlled from within MMBasic and
are independent of the standard 20
Maximite-compatible I/O pins on the
back panel.
The Arduino connector is mounted
on the top of the PCB and is primarily intended for use with Arduinocompatible prototyping boards which
can be purchased cheaply from many
retailers and on the internet. These
boards are called “shields” in “Arduino speak” and can be stacked on
top of each other.
There are many Arduino shields
available (we covered the Arduino
world in the January 2012 issue)
One of the issues with generating
colour is that it requires three separate
SPI outputs. We also need an additional SPI output for the SD card, so
that’s four in total. The 64-pin PIC32
chip used in the original Maximite
only has three SPI devices so, for the
Colour Maximite, we needed to move
to the 100-pin variant which has four
SPI outputs.
Most 100-pin chips have fine leads
with a very small gap between them
and that makes it extremely hard to
hand solder the chip to a PCB. That’s
the reason we didn’t use the 100-pin
chip in the original Maximite design
(the cost is similar).
Fortunately, Microchip now produce a 100-pin version of the PIC32
with the same pin spacing as the 64pin chip. The chip’s package is big24 Silicon Chip
Arduino connector
Another new feature in the Colour
Maximite is a stereo audio output. This
can be used to play music, generate
tones and create program-controlled
analog voltages.
The PLAYMOD command will
start a music synthesiser which
is built into the latest version of
MMBasic. This command will
read a sequence of instructions from
a file in the MOD format and generate
high-quality stereo music which will
play in the background.
You can use this feature to liven
up games, add sound effects to your
programs and provide some interesting warning signals.
The TONE command also uses the
stereo audio output and will generate a sinewave at the output with
selectable frequencies for the left and
right channels. This is intended for
generating attention-catching sounds
but because the frequency is very accurate, it can be also be used in many
other applications, eg, creating DTMF
tones or testing the frequency response
of loudspeakers.
Another new command in MMBasic is the PWM command which uses
the audio output connector to deliver
analog voltage signals. There are two
outputs and these can be set to any
voltage from 0-3.3V under program
control. They could be used to drive
a voltage-controlled power supply, a
motor controller or anything else that
needs an analog voltage input.
Battery-backed clock
Yet another new feature in the
Colour Maximite is the provision of a
siliconchip.com.au
battery-backed clock. This runs independently of the PIC32 and will keep
the correct time when you remove
power from the computer.
Not all readers need this feature,
so we have made it optional – refer
to the accompanying panel “Adding
The Battery-Backed Clock Option”
for details.
BASIC language
A great feature of the Maximite is
that it comes complete with its own
BASIC programming language, called
MMBasic.
This language is generally compatible with Microsoft BASIC and allows
you to type your program directly into
the Maximite. You can then test and
run your program while getting instant
feedback. This is a full-featured implementation of the BASIC language
and it supports floating point, arrays
with multiple dimensions, long variable names and many other powerful
features.
A key feature of MMBasic is its
support for the SD-card interface in
the Colour Maximite. You can store
programs and data on the card and
because the Colour Maximite uses the
standard FAT16 or FAT32 file system,
you can pop the card into your desktop
computer to access and edit data created by your programs.
The most important benefit of
BASIC is that it is very easy to learn
and use. This makes it ideal for people
who would like an easy introduction
to programming and want to just play
around without being forced into a
complicated programming environment.
Since its introduction with the original Maximite, MMBasic has been continuously improved. It now includes a
full-screen editor and your programs
do not need to use line numbers. You
can also use modern programming
structures like subroutines and functions with parameter lists to make your
programs more readable and easier to
maintain.
With the Colour Maximite, we have
introduced version 4.0 of MMBasic.
The most obvious addition to this version is support for colour and there’s
also support for a stereo synthesiser.
Other additions include two commands especially suited for programming games. These commands are (1)
BLIT which will rapidly copy an area
of the video output to another location
siliconchip.com.au
Colour Maximite: Parts List
1 PCB, code 07109121, 130 x
102mm
1 plastic case, 140 x 110 x 35mm
(Jaycar HB-5970, Altronics
H0472, Element14 1526699)
1 SD memory card connector
(Hirose DM1A, Element14
1764372, 4UCON 19607)
1 USB Type-B socket, PCB-mount
(Jaycar PS-0920, Altronics
P1307, Element14 1696537)
1 DE-15 (or HD-15) high-density
15-pin female D connector (AMP
1-1734530-1, MULTICOMP
SPC15430, Element14 1557991
or 1564252)
1 8MHz crystal (HC-49 low profile)
1 IDC 26-pin boxed header, 90°
PCB-mount
1 6-pin mini DIN female connector
socket, PCB-mount
1 2.1mm DC power socket, PCBmount
1 3.5mm stereo phono socket,
panel-mount
1 micro-tactile pushbutton switch
2 3-pin SIL headers, 0.1-inch
(male)
2 shorting blocks
1 3-pin polarised header plug,
0.1-inch, PCB-mount
1 3-pin polarised header socket
2 8-pin header sockets (Jaycar
HM3207)
2 6-pin header sockets (Jaycar
HM3207)
1 type 6073 mini TO-220 heatsink
(Jaycar HH8502, Altronics
H0630)
4 No.4 x 9mm self-tapping screws
(to secure PCB)
1 M3 x 6mm machine screw
1 M3 nut
1 M3 star washer
1 100mm-length 3-way ribbon cable
Semiconductors
1 PIC32MX695F512L-80I/PF or
PIC32MX795F512L-80I/PF
microcontroller (IC1) (Microchip
Direct, Element14 1778489 or
1778491)
on the screen; and (2) SPRITE which
enables you to create animated graphics that can move across the screen
without disturbing the underlying
graphics.
1 7805 5V voltage regulator, TO220 package (REG1)
1 TC1262-3.3VAB 3.3V voltage regulator, T0-220 package (REG2)
(Microchip Direct, Element14
1852182)
1 1N4004 silicon diode (D1)
2 1N5819 Schottky diodes (D2-D3)
3 1N4148 silicon diodes (D4-D6)
1 green 3mm LED (LED1)
1 orange 3mm LED (LED2)
Capacitors
1 10µF 6.3V ceramic, SMD 0805
package (Element14 1844286)
2 10µF 25V tantalum
1 330nF MKT
7 100nF monolithic ceramic
2 47nF MKT or polyester
2 22pF ceramic
Resistors (0.25W 5%)
1 10kΩ
2 47Ω
2 4.7kΩ
1 10Ω
5 1kΩ
1 2.2Ω
3 120Ω
Parts For Battery-Backed Clock
1 coin cell holder (see futurlec.com,
Element14 2064715)
1 CR2032 lithium cell (coin type) or
1 x CR2032 PCB-mount lithium
cell (Jaycar CR-2032VC, Element14 189267001)
1 32.768kHz watch crystal
Semiconductors
1 DS1307 real time clock (RTC),
8-pin PDIP package ( see
futurlec.com, Element14
1188042)
Capacitors
1 100nF ceramic or MKT
Resistors (0.25W, 5%)
2 10kΩ
Note: a PCB (with screen-printing
& solder mask) and a programmed
PIC32 micro are available from the
SILICON CHIP Partshop.
Version 4.0 of MMBasic is not exclusive to the Colour Maximite. There
is also a version for the original Maximite and it is worth updating to it if
you are running an earlier version. Of
September 2012 25
Left: inside the Colour
Maximite’s case. There’s
not a lot to it as all the
“smarts” are inside the
100-pin PIC32 chip in
the centre of the PCB.
The unit has a USB
interface and supports
SD cards with capacities
up to 32GB for storing
programs and files.
course, you will not get colour output
but the other features will all work,
including the music synthesiser (with
mono output).
How it works
Take a look now at Fig.1 which
shows the complete circuit diagram
of the Colour Maximite. It’s really
quite simple and basically consists of
a PIC32 chip with a lot of connectors
attached.
The most complicated part of the
Colour Maximite is the VGA driver
and that only uses one resistor and
one diode for each colour.
VGA colour video consists of separate red, green and blue signals. If you
mix red and blue you get purple, while
mixing red and green gives yellow and
so on. If you count black and white
as colours, this means that we can get
eight colours just by switching the red,
green and blue signals either fully on
or fully off.
In the Colour Maximite, each colour
uses an identical scheme to generate
the video so we’ll just look at one
colour channel to see how it’s done.
Fig.2 shows the basic details.
Within MMBasic, the video data is
stored as a bitmap in general RAM.
This means that when something is
to be displayed, the firmware must
convert it into individual pixels before
writing these to the video buffer. This
applies regardless as to whether it is a
character or a graphic symbol.
The process of turning this bitmap
26 Silicon Chip
into a video stream starts with the
horizontal sync pulse. This is created by a timer within the PIC32 that
is configured to generate a 3.813μs
horizontal sync pulse every 31.778μs
(about 31kHz). Once configured, this
timer runs continuously without further intervention.
An interrupt is triggered on the
leading edge of each horizontal sync
pulse, which causes the processor to
stop whatever it is doing at the time
and run a special section of its program. In this routine, the processor
calculates the memory address of the
next line of pixels and instructs the
DMA (Direct Memory Access) system
to copy that part of memory to the SPI
(Serial Peripheral Interface).
The SPI is a circuit in the PIC32 that
takes a byte of data and outputs it one
bit at a time with specific timing. It is
this stream of 1s and 0s that forms the
video signal. A logic 1 (or high voltage)
is an illuminated pixel while a logic 0
is a pixel that is off. The resistor and
diode at the output clamp the video
signal to 0.7V to conform to the VGA
standard.
As the scan line progresses across
the screen, the DMA sequentially reads
the data in memory and pushes it to
the SPI device which in turn sends
the data bit by bit to its output. The
beauty of this scheme is that, other
than setting up the DMA and SPI at
the beginning of the scan line, the
processor is free to undertake other
duties (like running your BASIC pro-
gram) while the video is generated in
the background.
Framing input
There’s just one problem with this
scheme. Because of the way the CPU
works, you cannot precisely guarantee
when it will start the video stream – it
may be a little earlier or later than the
previous scan line. While these differences are small (only a few tens of
nanoseconds), they will show up as a
jitter in the video output.
To eliminate this, we take the
horizontal sync pulse generated by the
timer and feed it back to the SPI as a
“framing input”. This can be seen in
Fig.1 where pins 69, 47 & 14 are the
framing inputs (one for each colour)
and 77 is the horizontal sync output.
Framing is a special feature of the
PIC32’s SPI and it forces the SPI to
wait for the trailing edge of the sync
pulse before starting the data stream.
The benefit of this feature is that the
video stream will always be precisely
Fig.1 (right): the circuit is based on
a PIC32 microcontroller. It manages
everything, including the colour VGA,
keyboard, SD card and I/O and it does
this while running a BASIC program
at high speed. Regulators REG1 &
REG2 respectively produce a +5V rail
for the keyboard and a +3.3V rail to
power the PIC32 and the SD card.
Note: this diagram does not include
the battery-backed clock option which
is shown separately in Fig.3.
siliconchip.com.au
D1 1N4004
EXT POWER
A
REG1 7805 D2 1N5819
K
PWR SW
OR LINK
REG2 TC1262-3.3
GND
10 F
TANT
REG1, REG2
+3.3V
OUT
IN
J1
GND
330nF
CON1
OUT
IN
K
A
6x
100nF
10 F
TANT
+5V
GND
10
VIN
D3
1N5819
POWER
30
85
A
55
Vdd
RE0
Vcap
RG8
10 F
USB
TYPE B
1k
1
4
56
3
57
CON2
73
BOOTLOAD
SOUND OR
PWM OUT
4.7k
L/#1
78
76
1k
CON9
Vbus
RC14
D–
RC13
84
3
4
2
63
KYBD DATA
1
X1 8MHz
CON4
(FRONT
VIEW)
+3.3V
+5V
22pF
64
22pF
RF13
RD13
RF4
RD7
OSC1
RD6
26
24
22
21
PIN 1
20
19
18
17
16
15
14
13
PIN
PIN
PIN
PIN
2
3
4
5
21
22
23
10
9
8
7
PIN 7
PIN 8
42
PIN 9
PIN 10
44
6
5
4
3
2
1
CON6
PIN 11
PIN 12
PIN 13
PIN
PIN
PIN
PIN
PIN
14
15
16
17
18
PIN 19
PIN 20
SCL
SDA
MMBASIC
PIN NUMBERS
41
43
18
67
RB5
PGED2
RB4
RB3
PGEC2
6
RB9
RB8
RB12
RB13
RD8
RB14
RB15
RD11
7
9
10
47
12
11
HORIZ SYNC
13
VERT SYNC
14
60
15
82
CON3
CARD PRESENT
CD
38
CARD ENABLE
50
DATA TO CARD
39
CLOCK TO CARD
49
DATA FROM CARD
83
9
1
2
3
4
5
6
7
8
CARD WRITE PROTECT
LED2
A
K
47
RG15
RE5
27
RESET
32
68
71
Vss
31
36
45
65
D0
D4
D5
D6
D7
79
91
92
97
100
CON7
SCL
SDA
RF0
88
RF1
89
RG1
90
RG0
RE4
J3
J2
RD12
81
RD4
RG13
RA0
ICSP HDR*
1
MCLR
2
Vcc
3
GND
4
PGD
5
PGC
6
NC
10k
33
D1
D2
D3
RA6
CON5
+3.3V
26
RA7
95
RG14
96
RG12
RC1
RC2
8
RC3
15
SD
CARD
SOCKET
SD ACTIVITY
13
87
RE8
7
17
K
SELECT COMPOSITE
74
35
RA15
RA14
19
RE9
1
K
8
RB11
34
RB10
66
3
K
WP
RB2
RB1
25
RB0
PIN 6
5
77
IC1
PIC32MX795F512L-80I/PT 94
RE1
OR
PIC32MX695F512L-80I/PT
24
11
12
4
6
72
23
20
3x 120
OSC2
MCLR
25
VIDEO – BLUE 3
A D6 A D5 A D4
2.2
RD5
80
VGA
RD1
RF5
KYBD CLOCK
1
VIDEO – GREEN 2
RD3
RA1
5
K
RD14
14
RG9
PS2
KEYBD
6
12
47
VIDEO – RED
RD2
69
RD9
D+
1k
47nF
4.7k
47nF
1k
93
A
RD0
53
RF8
RA4
1k
R/#2
+5V
54
2
S1
LED1
2 16 37 46 62 86
AVdd VUSB
OUT
+3.3V
100nF
K
GND
IN
A5
A4
A3
A2
A1
A0
VIN
RESET
D8
+5V
+3.3V
D9
D10
D11
D12
D13
CON8
ARDUINO
CONNECTORS
75
D4, D5, D6: 1N4148
A
K
LEDS
SC
2012
COLOUR MAXIMITE COMPUTER
siliconchip.com.au
1N4004, 1N5819
A
K
K
A
1
IC1
September 2012 27
DMA
SPI
VIDEO
OUTPUT
FRAMING
INPUT
TIMER
RAM
PIC32
(4 s PULSE
AT 31kHz)
HORIZONTAL
SYNC
Fig.2: the video is generated entirely inside the PIC32 chip. It starts with the
MMBasic software which converts the data to a bitmap and then writes that
bitmap to a portion of memory reserved as the video buffer. This buffer is
then streamed by the DMA controller to the SPI output which in turn feeds
it to the video output one bit at a time, with each bit representing one pixel.
synchronised with the sync pulse –
and therefore will display without
any jitter.
As far as we know, the PIC32 is
the only microcontroller that has
the resources needed for the Colour
Maximite and has framed SPI. That is
why we used the PIC32 and not some
other processor (there are many similar
processors on offer).
The video bits are clocked out at a
frequency of 20MHz. This means that
the DMA circuit must read the video
buffer and pump the data to the SPI
at that same frequency. And because
there are three colours with three
DMA/SPI channels running in parallel, the total data rate is 60 million bits
per second.
Fortunately, the PIC32 has a sophisticated system to connect memory and
peripherals (called the switching matrix) but the overhead in handling this
volume of data is one of the reasons
why the Colour Maximite runs a lit-
tle slower when in the 8-colour mode
compared to the monochrome mode.
Power supply
The Colour Maximite will happily
run on a DC supply from 7-16V (9V
recommended) with a current drain
of about 160mA. It will also run on
5V via the USB connector.
When running from a 7-16V rail, a
simple 3-terminal regulator (REG1) is
used to derive the 5V supply. Because
the power can also come via the USB
connector, diodes are used to select
the source for the rest of the computer.
A second 3-terminal regulator
(REG2), a Microchip TC1262, is used
to drop the 5V rail to 3.3V for the PIC32
micro and the SD card. While this
regulator looks like any other 3-terminal regulator, this particular type
was chosen for two key characteristics.
First, it has a low drop-out voltage,
which is essential because the USB
supply can be as low as 4.5V and this
This rear view shows (from left to right) the VGA socket, the DC power socket,
the multi-way I/O connector, the keyboard socket and the audio and USB
sockets. Power comes from either a USB port or a 9V plugpack (or battery).
28 Silicon Chip
combined with the 0.3V drop across
the diode gives the regulator less than
0.9V to work with. Second, it has a
very accurate output voltage. The
specifications state ±0.5% but on the
samples we checked, the output was
within 0.05% of 3.3V.
This is important because this voltage is used as the reference when the
PIC32 measures a voltage on one of
its input pins. The more accurate the
supply voltage, the more accurate the
reading will be.
There is a third regulator which
you cannot see. This is internal to the
PIC32 and provides 1.8V for the MIPS
CPU which is at the core of the PIC32
chip. This voltage appears at pin 85
of the PIC32, where a 10µF ceramic
capacitor is used to suppress noise and
stabilise the regulator. It is difficult to
find a through-hole component of this
value so a surface-mount capacitor is
used in this location.
There are also quite a few 100nF
capacitors sprinkled around the PCB
and connected across the 3.3V supply rail. They are there to suppress
the switching noise generated by
the PIC32 as it races through your
program.
External I/O
Many Arduino systems make the
I2C signals available on connector pins
A4 & A5. We have therefore provided
two jumpers (J2 & J3) so that you can
select between the normal I/O function for these pins (A4 & A5) or the
I2C signals (SCL and SCA). Note that
these I2C signals are also on external
I/O pins 12 & 13 on the back panel, so
effectively these jumpers join these I/O
pins together when in the I2C position.
The keyboard, SD card, USB and
external I/O connectors all connect
direct to the PIC32. Care is required
when using the external I/O pins, as
there is no special protection for these
inputs. The PIC32 is a tough little chip
but it can still be damaged by a highvoltage static spark or a voltage outside
its operating range. As a result, it’s a
good idea to always touch a ground
point before handling the I/O pins.
Similarly, always double-check your
connections before applying power.
The sound output circuit shown in
Fig.1 is intended for driving an audio
amplifier but you can easily modify the
output to drive headphones or even an
efficient speaker. The audio generated
by MMBasic is output as a pulse width
siliconchip.com.au
Adding The Battery-Backed Clock Option
+5V
100nF
10k
8
3
X2
32.768kHz 1
3V
LiMn
CELL
IC2
DS1307
2
10k
5
SDA
59
6
SCL
58
PIC32
RA3
RA2
4
Fig.3: the add-on circuit for the battery-backed clock option. It’s based on a
Maxim DS1307 real-time clock (RTC) chip and a 32.768kHz watch crystal.
O
NE OF THE most popular requests for
the original Maximite was the addition
of a battery-backed real-time clock.
The Maximite already had an accurate
method of keeping time but the problem
was that the time was lost when ever the
power was turned off. This meant that it
had to be reset (if you needed the correct time) each time the Maximite was
powered up.
For most people, this wasn’t an issue. If
you are writing a game or calculating prime
numbers, the time is irrelevant. However,
for some uses (eg, data logging), being
Moon Lander
Check out this video and see what
Fabrice Muller (one of our beta testers
in France) has done with with the Colour
Maximite:
http://youtu.be/knq5vX65Xy4
Everything, including the sound, is
generated by the Colour Maximite!
modulated (PWM) signal on pin 76 of
the PIC32 for the right channel and pin
78 for the left.
PWM can be used to generate an
analog output from a digital source.
It uses a high-frequency sequence of
pulses (about 100kHz) and MMBasic
can modulate the output by varying
the duty cycle. When the signal is
averaged (using a low-pass filter), we
end up with an analog voltage that’s
controlled by your BASIC program.
So before we feed the signal to an
amplifier, we need a low-pass filter.
This is done using a 1kΩ resistor and
47nF capacitor in each channel, which
together form a simple low-pass filter
with a -3dB point of about 4kHz.
Following this, an attenuator consiliconchip.com.au
able to keep the correct time is important.
For this reason, we have made space on
the PCB for a battery-backed clock. When
you add these extra clock components,
MMBasic will automatically recognise
the presence of the clock and retrieve the
time from it each time the system boots.
Conversely, if you leave the components
out, MMBasic will carry on as before and
use the PIC’s internal clock which is reset
to zero on power up.
Circuit details
The circuit shown in Fig.3 is simple
sisting of 4.7kΩ and 1kΩ resistors
reduces the output to about 0.5V p-p
(peak-to-peak). This attenuator also
isolates the filter from variations in
the load presented by the amplifier.
An alternative is to drive a set of
earphones. The low-pass filter isn’t
required in this case, as the headphone
coils will do the averaging for you.
This means that you can omit the capacitor in the low-pass filter and the
attenuator. However, to avoid damaging your hearing, the 1kΩ resistor
should be increased to 4.7kΩ or higher.
If you can live with a low volume,
you can even drive an efficient speaker
direct. In this configuration, you need
to reduce the 1kΩ resistor to 22Ω,
replace the 4.7kΩ resistor with a link
and leave out the 47nF capacitor. The
sound level will depend on the efficiency of the speaker but don’t expect
it to be loud.
Analog outputs
As previously stated, the sound output can also be used to generate two
independent analog voltage outputs.
MMBasic has a command specifically
for this (the PWM command) and when
you use the outputs in this mode,
enough. It’s based on a Maxim DS1307
real-time clock (IC2) and this uses a
32.768kHz watch crystal to accurately
track the time and the date, including
adjustments for leap years.
The DS1307 communicates via the I2C
protocol with the PIC32. MMBasic uses
this to interrogate the chip on power-up
and then uses the PIC’s own crystal-locked
clock to keep track of time from then on.
The reason for this is that it’s much faster
to retrieve the time from internal registers
rather than request it over the relatively
slow I2C bus.
A great feature of the DS1307 is that it
monitors its supply voltage on pin 8 and
automatically switches to battery power
when the supply voltage drops below a
threshold. At the same time, it disables
the I2C bus to prevent random noise from
being interpreted as a command to change
the time.
We’ve specified a CR2032 lithium cell in
this circuit because it’s cheap and readily
available but it’s really overkill. The DS1307
consumes about 0.25μA when running off
the cell and given the 140mAh capacity
of the CR2032, this translates into a cell
life of about 64 years! This means that
the limiting factor will be the shelf-life of
the CR2032 which is more than 10 years.
you should not use any of the audio
commands.
In this case, you probably want a
much lower filter frequency to give a
smoother output so you should replace
the values shown on the schematic
with something more suited to your
application. This can be easily calculated using the formula:
RC = 1 ÷ 2πF
where R and C are the values in the
low-pass filter and “F” is the roll-off
frequency.
Typical values would be 4.7kΩ and
330nF, which would give a fast enough
response for you to quickly change the
output while eliminating most of the
PWM switching.
If you want to use these outputs to
generate a PWM square wave rather
than an analog voltage, you can use
the same method as described above
for connecting a speaker; ie, use a 22Ω
resistor and a wire link.
Next month: construction!
Well, that’s all we have space for this
month. In Pt.2, we will describe how to
put the Colour Maximite together and
give you an introduction to programSC
ming in colour.
September 2012 29
|