This is only a preview of the July 2008 issue of Silicon Chip. You can view 30 of the 104 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 "DSP Musicolour Light Show; Pt.2":
Items relevant to "A PIC-Based Musical Tuning Aid":
Items relevant to "Balanced Mic Preamp For PCs & MP3 Players":
Items relevant to "Bridge Adaptor For Stereo Power Amplifiers":
Purchase a printed copy of this issue for $10.00. |
If Swan’s 2nd Law is: “ Microcontrollers can never have too
many I/O channels” . . . what’s his first?
Drum roll –
Yet Another
PICAXE!
A
lthough PICAXE microcontrollers are now well
established and popular in numerous electronic
projects, due in no small part to SILICON CHIP’s
enthusiasm, many users know only of the entry level 08M,
versatile 18X or powerful 28X.
However, the recent arrival of a 20-pin PICAXE now takes
the family to an awesome 14 members, although four earlier
offerings are now discontinued and two “X2” fire breathers
have yet to be released. This new PICAXE-20M (based upon
a MicroChip PIC16F677) is really just a stretched 08M, as it
offers similar memory and follows the same commands as
the ever popular 08M and more recent 14M.
Thankfully, its 10-a-side DIP packaging enables easier
identification in the sea of chips lurking in many IC parts
drawers, since its 20 pins make it noticeably longer than
by Stan Swan
common 14,16 or even 18-pin DIP logic ICs.
The so-called 20M is mainly intended to meet the demand
for further input and output (I/Os) channels than the four
offered by the smaller 08M, or 5-6 of the 14M.
Its provision of eight I/Os, arranged with inputs (0-7) on
one side and outputs (0-7) on the other, looks to have strong
appeal for projects where extra chips (such as Shift Registers)
and wiring would otherwise be needed.
Circuit size will naturally be reduced with just a single
IC, yet greater flexibility will result, thanks of course to the
PICAXE programmable features.
All three “M” chips are especially well-suited for hobbyists and educational users, allowing enhanced design
for just a few dollars more, when the need for extra I/O
channels arises.
The 14 PICAXE microcontrollers
Summary – mid 2008
PICAXE
type
IC
pins
Memory
~progr.
lines
Outputs
Inputs
ADC
(8-10bit)
EEPROM
memory
(bytes)
Speed
(MHz)
Best
use?
Microchip
PIC type
Approx.
Cost
(Aust$)
08
8
40
1-4 config.
1-4 config.
1x 4 bit low
128 less prog.
4
-
12F629
$5
08M
8
80
1-4 config.
1-4 config.
3
256 less prog.
4,8
Educ.
12F683
$6
14M
14
80
6
5
3-5 config
256 less prog.
4,8
Educ.
12F684
$7
20M
20
80
8
8
4
256 less prog.
4,8
Educ.
16F677
$8
18A
18
80
8
5
3
256 less prog.
4,8
-
16F819
$11
18X
18
600
8
5
3
256 plus I2C
4,8
Std.
16F88
$16
28X1
28
1000
9-17
0-12
0-4
256 plus I2C
4-20
Std
16F886
$22
28X2
28
2 x 1000
22 configurable I/O
0-12
256 plus I2C
4-40
Adv.
18F2420
$TBA
40X1
40
1000
9-17
3-7
256 plus I2C
4-20
Adv.
16F887
$28
0-12
I2C
4-40
Adv.
18F4420
$TBA
40X2
40
2 x 1000
8-20
33 configurable I/O
256 plus
Earlier (2002-05) PICAXEs below are now considered obsolete, with supplies discontinued.
18
18
40
8
5
3x4bit low
128 less prog.
4
X
16F627
($8)
28A
28
80
8
8
4
64 +256
28X
40X
28
40
40 Silicon Chip
600
600
9-17
8-16
0-12
8-20
4
3-7
4-
X
16F872
($10)
128 plus
I2C
4-
X
16F873A
($15)
128 plus
I2C
4-
X
16F874A
($26)
siliconchip.com.au
1
2
3
4
PICAXE 08M
+V
SERIAL IN
ADC 4 / OUT 4 / IN 4
INFRAIN 3 / IN 3
8
7
6
5
0V
OUT O / SERIAL OUT /INFRAOUT
IN 1 / OUT 1 / ADC 1
IN 2 / OUT 2 / PWM 2 / TUNE
PICAXE 08M
1
14
2
13
3
4
5
6
PICAXE 14M
+V
SERIAL IN
ADC 4 / IN 4
INFRAIN 3 / IN 3
IN 2
IN 1
ADC 0 / IN 0
12
11
10
9
8
7
2
SERIAL
OUT
SERIAL
IN
3
5
10k
4
0V
OUT 0 / SERIAL OUT /INFRAOUT
OUT 1
OUT 2
OUT 3
OUT 4
OUT 5
3
PROGRAM
EDITOR
(TO PC
SERIAL PORT)
20
2
19
3
18
4
5
6
7
PICAXE 20M
1
17
16
15
14
8
13
9
12
10
11
8
5
3V
BATTERY
1
2
λ
5
λ
7
λ
λ
0V
SERIAL OUT
OUT 0 / INFRAOUT
OUT 1
OUT 2
OUT 3
OUT 4
OUT 5
OUT 6
OUT 7
3
8
λ
λ
2
9
λ
λ
10
λ
12
6
λ
λ
Pleasingly, the larger 14 and 20 “M” offerings retain the
same programming and supply connections as the classic
08M, although only the 08M allows pins to be set either as
Inputs or Outputs.
I/O background
Comparable to kids demanding the attention of a solitary
teacher, it’s almost a byword with microcontroller projects
that sensors and indicating devices will require more channels than are available.
This is especially a problem with outputs and traditionally it has been addressed by multiplexing techniques, so
that data signals are “juggled” around the displays at speeds
16-SEGMENT
4
S1
0
1
The three “M” PICAXES are very similar in pinouts
and architecture, meaning little change in code as you
move up the chain (in fact, the 08M is pin-for-pin for
the top eight of the 14M). The main difference is all
those beautiful extra inputs and output channels!
14-SEGMENT
7
3 PICAXE 6
08M
λ
PICAXE 20M
7-SEGMENT
1
11
4
PICAXE 14M
+V
SERIAL IN
ADC 7 / IN 7
IN 6
IN 5
IN 4
ADC 3 / IN 3
ADC 2 / IN 2
ADC 1 / IN 1
INFRAIN / IN 0
2
22k
5x7 MATRIX
Here’s an example of a LED chaser using just a PICAXE
08M. In discrete logic this would require at least three or
four chips to achieve. Although this looks elegant when
compared to 1:1 LED driving, annoying flickering may be
an issue and considerable hookup wiring is needed.
greater than human persistence of vision (POV).
POV makes LEDs appear to be solidly lit, even although
they’re being rapidly pulsed (at ~100Hz) and offers a bonus
of lowering average LED current demands.
The colourfully-named “Charlieplexing” (after Maxim
engineer Charlie Allen) also enables relatively few I/O pins
to drive a large number of LEDs, utilising the Tri-state nature of micro channels, when a pin can be sink, source or
be open circuit.
With “n” outputs n x(n-1) LEDs can be controlled. So a
4-output (Pins 0,1,2,4) PICAXE-08M can control 4x(4-1) =
4x3 = 12 LEDs and still have a Pin 3 left for some kind of
input.
But before you get too excited, realise that multiplexing of
any type requires all manner of fancy “digital jigsaw” coding
and wiring (as shown above), and for just a dollar or so extra
the larger PICAXEs may ease the pain!
LED displays
Four common types of LED displays. At left is the standard
7-segment (+DP) type we are using in this article. Next in line,
extra segments are added to make a much-more versatile
14-segment (+DP) display. Third has the upper and lower
segments broken in two to form a 16 segments, capable of
displaying most – but not all – letters and numbers (eg, “D”
and “O” can’t be displayed because it looks exactly the same
as zero). Finally, the LEDs are broken down into a 5x7 matrix
which is capable of displaying any letter, numeral and an
array of symbols. It’s just a matter of how the LEDs are driven.
siliconchip.com.au
LEDs have been an enormous
success story since their early 1970s
introduction and ever-brighter types
are now revolutionising lighting and
displays. We’re all bombarded daily
by single status LEDs on TV sets and
phone chargers, to bar arrangements
showing volume on audio gear.
But aren’t colour LCDs now all the
rage? Quite true, but when compared
with older 16x2 mono LCDs, LED displays are very bright, much cheaper
July 2008 41
COM
A
B
C
D
E
F
G
C
COM
A
B
C
D
E
F
G
a
b
f
g
e
c
d
dp
DP
7-SEGMENT
DISPLAY1
DATA1
DATA2
DATA3
DATA4
DATA5
DATA6
DATA7
DATA0
E
B
C
a
7-SEGMENT
DISPLAY1
b
f
g
e
A
B
C
D
E
F
G
c
d
8
8
E
B
DISPLAY1
8
DISPLAY2
a
b
c
d
e
f
g
dp
DP
dp
7-SEGMENT
DISPLAY2
a
b
c
d
e
f
g
dp
b
g
e
c
d
dp
COM
B
DISPLAY1
7-SEGMENT
DISPLAY2
a
f
C
E
8
DATA1
DATA2
DATA3
DATA4
DATA5
DATA6
DATA7
DATA0
+V
DP
A
B
C
D
E
F
G
a
b
f
g
e
c
d
dp
DP
COM
B
C
E
DISPLAY2
Here’s how the various segments in 7-segment displays
are driven. At left is a “common anode” circuit – here
the transistor controlling the device must be turned
on as well as the data lines controlling the individual
segments. For example, if data lines 1, 2, 7, 5 and 4 are
activated, the display shows a “2”. At right is the same
setup, this time for “common cathode” displays. These are
in fact used more frequently than common anode types.
($2-$4), and although rather power hungry (~5mA each
segment) are easily driven and understood.
In dim lighting, when extra LCD backlighting can draw
significant currents, LED displays are supreme, especially
for “at a glance” monitoring.
If arranged in suitable patterns, traditionally in seven
segments with all the LED cathodes joined (hence common
cathode or CC), they can spell out numbers and letters that
may be quite sufficient for simple status and alerts. Each
character is just built up of suitably lit segments, with these
traditionally referred to as a,b,c,d,e,f,g and dp(decimal point).
The letter or number “0” will use segments a,b,c,d,e,f , while
a “3” has a,b,c,d,g illuminated.
Aside from displaying the numbers 0-9, with suitable
program tweaking even basic characters (E, F, L, J, O, P, H,
PROGRAMMING
RESISTORS
4.7k
3
5
10k
SERIAL IN
22k
+V
PROGRAM
EDITOR
(TO PC
SERIAL PORT)
DS
18B20 OUT
ADC7/
INPUT 7
INPUT6
INPUT5
INPUT4
PICAXE
20M
20
10
ADC2/
INPUT2
1
DS18B20
OUT
+V 0V
SC
2008
ADC3/
INPUT3
ADC1/
INPUT1
INFRAIN/
INPUT0
2
1
19
3
18
4
17
5
16
6
PICAXE
20M
15
7
14
8
13
9
12
10
11
20
OUTPUT1
#
OUTPUT2
#
OUTPUT3
OUTPUT4
OUTPUT5
OUTPUT6
OUTPUT7
Picaxe 20m LED THERMOMETER
#
#
#
8
2
S, A, I, U and C etc) and sequences such as HI and LO can
be shown. The real world is full of crucial information (eg,
lift floors etc) shown in such a cryptic manner.
14 and even 16-segment LEDS are available for more
specialised displays but LED matrix arrays (such as the 5x7
shown) usually offer more character versatility – we will
come back to these on a later project.
But why the appeal of LEDs with PICAXEs? Driving a
classic 7-segment display, when faced with just a few output
lines, normally requires extra ICs like the DIP16 CMOS 4511,
specifically designed for the task. Such approaches however
involve considerable wiring, extra component costs and loss
of display flexibility.
Hence it’s VERY satisfying to see the 20Ms “gang of eight”
outputs, as these immediately appeal for direct but versatile
7-segment use. It’s akin perhaps to hav+4.5-5V
ing your very own personal teacher.
(EG 3 x ‘AA’,
You can’t beat 1:1 if the luxury is
4 x NiCd or
# VALUE DEPENDS
NiMH, etc)
ON DISPLAY USED
available – and each display LED is
AND SUPPLY
thus fed from a dedicated output, with
0V
– 330 Ω TYPICAL
an 8th available for the decimal point.
SERIAL OUT
#
Voila – it’s almost as if 20Ms and
OUTPUT0/
7-segment displays were made for
INFRAOUT #
each other!
DP
A
B
C
D
E
F
G
a
b
f
g
e
c
d
dp
COM
#
ACTUAL PINOUTS
DEPEND ON
7-SEGMENT
DISPLAY USED
The new PICAXE-20M, with eight I/Os, is ideal to drive a 7-segment LED display.
With a DS18B20 temperature sensor on the input, it makes a great thermometer.
42 Silicon Chip
An application – and an
answer to Stan’s first law!
The 20M inputs can monitor almost
any regular sensor using normal READADC, and it would be straightforward
to connect a thermistor, LDR or the
like in a simple voltage divider, with
values being shown on the outputs perhaps via multiple LED bars.
However, readers may well recall
Swan’s 1st Law –“You can never have
too many thermometers” and with
this in mind, an enhanced but simple PICAXE 20M + 7 segment LED +
DS18B20 digital thermometer circuit
has evolved.
siliconchip.com.au
‘PICAXE-20M,7 seg LED & DS18B20 demo. Stan.SWAN + PICAXE “Forum”
‘Uses single 7 seg display,sequencing digits so 24°C temp=”2” then “4” etc
‘Ranges very cold subzero (preceeded with flashing -ve) to ~99°C within 1/2°C
‘Suits further tweaking for info.display needs or enhanced battery life etc
‘204/256 bytes.Much tighter programming possible- EEPROM,symbol etc
‘Program download at => www.picaxe.orconhosting.net.nz/20m7segds.bas
‘Breadboard layout => www.picaxe.orconhosting.net.nz/20m7segds.jpg
‘--------------------------------------------------------------------------temp20m:readtemp 7,b0 ‘DS18B20 temp reading at 20M input 7
if b0>128 then gosub negtemps ‘Sub zero temps value correction
b1= b0/10
b2= b0//10
if b1=0 then units
‘divide orig temp to get tens value
‘divide orig temp so remainder yields units value
‘suppress “0” if temps between ±9°C,so “4” & not “04”
tens:
‘tens numeral test,with first digit suppressed if 0
on b1 gosub zero,one,two,three,four,five,six,seven,eight,nine
wait 1:pins=%00000000
‘blanks all 7 segs to ensure tens & units
pause 200
‘don’t run together if similar- 11,22,33 etc
units:
‘units numeral test
on b2 gosub zero,one,two,three,four,five,six,seven,eight,nine
wait 2
‘units digit extra hold on,as likely of most interest
pins=%00000000:wait 1 ‘blanks for DP heartbeat between each temp.display
for b3 = 1 to 3:pins=%00000001:wait 1:pins=%00000000:wait 1:next b3
goto temp20m
‘Bit order follows 20M outputs 7,6,5,4,3,2,1,0 (or 7 seg g,f,e,d,c,b,a,+DP)
‘if wired as on 20M breadboard demo using DSE Z4104 7 seg LED
zero: pins=%01111110:return
‘0 shows
one: pins=%01100000:return
‘1 shows
two: pins=%10110110:return
‘2 shows
three:pins=%10011110:return
‘3 shows
four: pins=%11001100:return
‘4 shows
five: pins=%11011010:return
‘5 shows
six: pins=%11111010:return
‘6 shows
seven:pins=%00001110:return
‘7 shows
eight:pins=%11111110:return
‘8 shows
nine: pins=%11001110:return
‘9 shows
negtemps:’DS18B20 subzero negative temps routine + flashing -ve alert
for b3 = 1 to 2:pins=%10000000:pause 200:pins=%00000000:pause 200:next b3
b0 = b0 - 127:return ‘b0 now correctly able to show subzero temps
Stan’s traditional breadboard layout of the PICAXE-20M
“thermometer”. The temperature sensor is bottom right.
Here’s the commented (‘) code for the Thermometer. It’s not
too long to type out – or you can download it if you wish.
The ever popular DS18B20, which reads temperatures
over a wide range to within ½°C, returns direct °C values
for monitoring by the READTEMP command.
Rather than use a second 7-segment display, a skinflint
approach has been followed, where the display is just sequenced. So a temperature of 24° is shown as “2” then a”4”,
with suitable blanking to prevent confusion. The DS18B20
measurement range is from an amazing –55°C to + 125°C,
although peaking at 99°C in our case, with sub-zero temperatures preceded by a flashing “-”.
Instead of coding with tedious multiple HIGH/LOW commands to build up a 7 segment pattern, outputs are setup in
the efficient but cryptic %10101010 style. These are serviced
g,f,e,d,c,b,a,dp so the command PINS=%00001110 shows a
“7”. Even more efficient coding techniques could be used but
the current approach is very readable while leaving scope
for ample hacking and display tweaking.
may then be required.
The LED brightness relates to the values of these resistors,
so alter the normal 330W droppers to suit, perhaps even using
>1000W if the display is too bright in a darkened room. Such
higher values will have the benefit of prolonging battery life
(presently perhaps ~100 hours), which will naturally relate
to the numbers of segments being lit.
The circuit in fact works perfectly well on just 3V (although
the display will be dimmer), and when thus compacted the
entire design could even be housed in a small sealed waterproof plastic container. The DS18B20 can conveniently be
extended off circuit and perhaps sealed in a rugged probe,
as naturally the circuitry itself may need protecting if in
liquids or at thermal extremes.
Circuit layout
Using a 7-segment display with side pins, the entire circuit readily fits on a small standard solderless breadboard.
Larger or bottom-pinned LED displays will rather cramp the
dropping resistor arrays and flying leads or a second board
siliconchip.com.au
Conclusion
At ~$8 the new 20M looks well suited initially just in a
cost effective display niche based on its 8 outputs, since
these greatly streamline 7-segment LED driving, while offering display versatility.
For convenience clickable links for code downloading,
resources and references are all hosted at www.picaxe.
orconhosting.net.nz/20M.htm
SC
July 2008 43
|