This is only a preview of the February 2003 issue of Silicon Chip. You can view 27 of the 96 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. Articles in this series:
Items relevant to "The PortaPAL Public Address System":
Items relevant to "The SC480 50W RMS Amplifier Module; Pt.2":
Items relevant to "Using Linux To Share An Optus Cable Modem; Pt.4":
Items relevant to "A Windows-Based EPROM Programmer; Pt.3":
Purchase a printed copy of this issue for $10.00. |
PICAXE –
the new millennium
555?
Stan (the man) Swan,
electronics lecturer from
Massey University in
Wellington (NZ), leads the
charge with the innovative
PICAXE-08, the PIC for everyman.
Stan reckons this PIC is really easy to use, even for old-timers!
T
he legendary electronic industry workhorse IC, the
8-pin 555 timer, was first introduced (unpatented!)
by Signetics in 1972.
It subsequently featured in countless circuits. Virtually
every monthly electronics magazine (SILICON CHIP included)
continues to have further tips, hints and innovative tweaks
for them. In fact, entire “555 Cook Books” have evolved.
In today’s silicon chip age, the 30-year endurance of such
a humble device is a remarkable tribute to its sound initial
design, reliability and cheapness.
It’s been the largest volume IC sold every year and the
original design, although enhanced with lower powered
CMOS versions, remains unmodified.
To put this in historical context, consider that the 555
dates from the first pocket calculators, VCRs and colour
TV sets, and that today’s 21st century
electronic appliances (DVDs, mobile
phones, home PCs, GPS, etc) were then
the stuff of science fiction.
Given its white-hot rate of change,
thirty years in electronics compares to
perhaps three hundred in normal engineering fields (steam engines to space
shuttles?) and by any measure the 555
seems due for a successor.
Enter the PIC
The 1990s arrival of the Microchip
PICs (Peripheral Interface Controllers
or Programmable ICs), with their PC
interfacing, cheapness and non-volatile RAM, initially
showed most promise.
PICs abound in modern electronic devices, including
bread makers, washing machines, sewing machines, PCs,
mobile phones, digital cameras and even toys.
Most PICs now are Flash RAM, with the “F” (rather than
an earlier “C”), indicating block memory cell erasure when
electrons pierce a thin dielectric under Fowler-Nordheim
tunnelling.
Phew! Data remains in the IC without any battery backup,
yet can be easily be edited or retrieved.
An irksome trade-off between cost and programming
difficulties exists however. Bare PICs (such as the popular
PIC16F84) are cheap and powerful but too complicated for
many enthusiasts and educators.
They may be great for controlling
smart washing machines and ideal
for mass production but they intimidate beginners simply wanting to
flash a few LEDs!
In contrast, the Parallax BASIC
“Stamp” variations were better
suited to education and developmental work, since they were easy to
high-level program in BASIC.
But their costs were usually much
Although both the 555 and PICAXE
too high to justify production work
are 8-pin DIP, their internals differ
and their large footprint was – well
radically. Note that the “I/O pin” num– postage-stamp sized.
bers are NOT the same as the chip
More recently, high level editors
“leg” numbers (especially 3 & 4!).
Part 1: Introduction to the PICAXE – by Stan Swan*
8 Silicon Chip
www.siliconchip.com.au
It’s a PIC that even your dog could understand. . .
and PIC intro kits have also abounded but with costs or
assembly complexity still rather daunting for newcomers.
In an admirable blend of industry and education, akin
perhaps to Victorian ventures when schools aligned with
local firms, the UK Oil and Gas Industry recently funded a
West Country firm, Revolution Education, in a remarkable
PIC venture.
The firm already handles a more powerful and larger
PICAXE “18” and “28” range but it’s their new 8-pin
PICAXE-08 that looks set to take the “555 successor”
mantle.
PICAXE-08s are bubble-gum cheap, powerful, have
non-volatile memory and are delightfully easy to use.
They PC-connect via a 3-wire D9 serial cable and program
under a free Windows high level editor using 35 BASIC
“plain English” commands such as “high, low, nap, goto,
sound, if…then, sleep” etc. Even your dog could understand these!
The command set is intentionally similar to that of BASIC
“Stamps”, meaning that circuits and code already produced
The Revolution Education Starter Pack board uses soldered
contacts and although allowing neat assembly, can be heat
damaged and is inconvenient for prototyping. A suggested
layout on 300-hole protoboard is shown at right – much
more convenient for the hobbyist and experimenter.
The PICAXE-08 has unusual supply voltage positions: Pin 1
is +ve and pin 8 is ground. The jumper allows one channel
to be used for I/O as well as normal programming. Wire
colours follow normal resistor colour coding to help identify
channels, ie, black 0, brown 1, red 2, orange 3, yellow 4.
Lo, the PIXAXE!
www.siliconchip.com.au
February 2003 9
PICAXE-08 COMMANDS (Note similarity to Parallax BASIC Stamp PBASIC)
Several “pseudo” commands too, especially SYMBOL (assigns new word to a value) and INPUT = pin
Rem, semicolons (;) or apostrophe (‘) precede remarks/comments, & also colons (:) as usual in BASIC.
DIGITAL OUTPUT.
HIGH
Switch an output pin high (on).
Example: High 2 turns pin 2 on.
LOW
Switch an output pin low (off).
Example: Low 3 turns pin 3 off.
TOGGLE
Toggle (alter) the hi/lo state of an output
pin.
OUTPUT
Set a pin as an output.
Example: Output 1 makes pin 1 an output.
INPUT
Set a pin as an input.
REVERSE Reverse the I/O state of a pin.
PULSOUT Output a timed pin inverted pulse.
Example: Pulsout 0,3 - pin 0, 30 microseconds.
ANALOG OUTPUT
PWM
Provide a pulse width modulation output.
Example: Pwm 1,20,8 - pin 1,20/255 duty,
8 cycles.
SOUND
Make sound(s) 0 = quiet, 255 = hiss.
Example: Sound 4,(100,10) - sound pin
4,~5kHz,~100ms.
DIGITAL INPUT
IF...THEN
Jump to new program line, depending on
condition.
Example: If b3 < b2 then ledoff
PULSIN
Measure input pulse duration (µs).
Example: Pulsin 4,0,w2 - pin 4 input,
logic low triggered.
ANALOG INPUT
READADC Read analog channel (0 - 160) into a
variable.
Example: Read 1,b2 - read channel 1 into b2
PROGRAM FLOW
FOR...NEXT Establish a for-next loop.
Example: For b2=0 to 100 step 2 counts even numbers.
BRANCH
Jump to address specified by output if in
range (akin to ON x GOTO).
GOTO
Jump to address.
Example: If b0=5 goto daylight
goes to daylight routine if b0=5.
GOSUB
Jump to subroutine at address specified.
Example: Gosub test heads to test subroutine.
RETURN
Returns to main program from gosub
routine.
10 Silicon Chip
VARIABLE MANIPULATION
(LET)
Assigns a value to a variable & does limited
L-R maths.
Example: Let w0=b2*22/7 – Pi
LOOKUP Lookup indexed data specified by offset
& store.
Example: lookup 1,(6,7,8) - takes 7
LOOKDOWN
Search values for a target’s match
number & store in variable, akin to $trings
RANDOM Generate a pseudo-random number.
SERIAL I/O
SEROUT Serial data output (to 2400bps).
Example: Serout 0,n2400,(65) - sends
ASCII 65 (=A).
SERIN
Serial data input - many qualifiers!
Example: Serin 0,n2400,(“A”) - waits for
ASCII 65.
INTERNAL EEPROM ACCESS (program & data
storage; take care since program overwriting may occur).
EEPROM Store data in EEPROM before download.
Example: eeprom 0,(“hello”) - starts <at>
location 0.
READ
Read data EEPROM into variable.
Example: Read 255,b2 get location of last program instruction.
WRITE
Write variable into data EEPROM.
Example: Write 220,b3 - stores byte b3 into
address 220.
POWER DOWN
NAP
Enter low power 20µA mode for short period
( <2.3 secs).
Example: Nap 3 - sleeps for 144ms.
SLEEP
Enter low power mode long period (±1%).
Example: Sleep 3600 - sleeps for 1 hr
(max 65535s).
END
Power down until reset (indefinite sleep).
MISCELLANEOUS
PAUSE
Wait up to 65535ms (65.5 ) ~ 1ms overhead.
Example: Pause 100 - pauses ~100ms = 0.1s.
WAIT
Wait for up to 65 seconds.
DEBUG
Displays variable value on attached PC
screen.
Example: Debug b0 - shows b0 value on screen.
Ch.0
Ch. 3
Ch.1
PROGR or switchable OUT
IN only
Low res. Analog I/O
www.siliconchip.com.au
A typical 555 oscillator circuit to
flash a single LED. As you can see,
even this simple circuit requires
more components than the PICAXE.
And that’s all this circuit can do!
may readily convert to PICAXE use.
PICAXE-08s are based on the new
Microchip 8-pin PIC12-F629s but
with the BASIC interpreter squeezed
on-board.
Such interpreters allow easy code
tweaking, since the program doesn’t
need compiling before each run, although a slight execution overhead
(about one millisecond) exists.
They have in-built 4MHz oscillators, 1K code space, 64 bytes RAM,
128 bytes EEPROM (enough for about
40 lines of code), five I/O pins and valuable low-resolution analog-to-digital
conversion (ADC).
Battery needs are a flexible – 2.5V
to 6V at just 2mA, yet they’re able to
supply 20mA at each pin to drive LEDs
or piezo speakers, etc.
Perhaps the PICAXE name represents a miner’s digging tool with
“Silicon – I’ve struck Silicon!” the cry,
instead of “Gold!”
Gold prices are irrelevant however,
since PIXAXE08s sell for an astound-
On the left is the classic 555 oscillator, very cheap but with all aspects
hardware-dependent. Contrast this with larger footprint and much more costly
BASIC “Stamp” approach at right. In the centre is the smaller PICAXE
approach which offers the best of both worlds: software control and “bubble
gum” cheapness.
ingly low $3 each. Being so cheap, they
can be even left in the final soldered
circuit.
Later software tweaking can be
attended to with a 3-wire serial connection if need be.
It’s recommended that all PICAXE
circuits have such a simple inclusion
and the associated 10kΩ and 22kΩ
resistor pair.
Folks, if you’ve been meaning to get
into PICs but thought the process akin
to unravelling DNA sequences, then
PICAXE chips are the answer.
Although Revolution Education
(UK) market a $25 “Starter Pack”
Introducing the PICNIK box – the “Peripheral Interface
Con-troller Nifty Intro Kit.” The protoboard fits neatly into a
parts box and along with the battery pack and sundry other
components, offers a one-stop PICAXE experimenter’s kit.
www.siliconchip.com.au
(along with other project boards) that
could be ideal for dedicated circuits,
this involves fine soldering and inconvenience when away from the
workbench.
For more flexibility, solderless protoboards are better, since these allow
easy component swapping and reuse,
neater circuit layouts, and no burnt
fingers!
It’s a PICNIK!
With increased productivity in
mind, I’ve developed the PICNIK
(Peripheral Interface Controller Nifty
Intro Kit?) box.
Emily, a Year 11 student, uses her notebook PC and a
PICNIK to create an instant solderless PIC workshop. It’s
suitable for education, non-specialist workrooms or home
use.
February 2003 11
What are the goodies in the PICNIK Box . . .
PICAXE-08 IC
Revolution Education, UK (see website) Approx. $3 each in a tube of 5
Small solderless “Wish” protoboard
Sold by most electronics outlets.
4 AA battery holder and battery snaps
Ensure PICAXE is not run from 9V!
4 AA cells
(Power demands are very light, so cheap non-alkalines should do).
Solid core hookup wire
Multi-coloured (avoid stranded wire on protoboards).
Wire snips & strippers
Even fingernail nippers can be used!
Small piezo speaker
Allows direct sound production. (Don’t use a normal 8Ω speaker).
Assorted LEDs
Easily driven by the PICAXE.
330Ω dropping resistors
LEDs can be driven directly but it’s wise to use these.
Light Dependent Resistor (LDR)
Allows easy ADC action via a simple voltage divider with further resistors.
3-wire serial cable
Perhaps from an old serial mouse and PC motherboard header pins.
Other tools & materials
Hot-melt glue gun, wide heatshrink tubing (clear), photocopied labels.
PICAXE Editor and .PDF manuals
from CD, or free download from Rev-Ed (also at www.picaxe.orconhosting.net.nz).
The protoboard neatly fits into a
semi-transparent parts box and along
with the battery pack and sundry other
components, offers a one-stop PICAXE
experimenter’s kit.
Few of its items are exotic, and with
junk box fossicking, the total bill of
materials shouldn’t set you back more
than $30.
Both educational users and experienced circuit developers should find
this a most cost effective approach.
We hope to use the PICNIK box
over the next few months to get you
as enthusiastic about these new chips
as we are!
What’s this? No serial port?
Don’t have a serial port in that spiffy
new notebook? The computer industry
has perhaps been rather TOO keen to
run with USB !
Although wonderfully convenient
and well supported now by modern
peripherals, USB-only machines leave
serial RS-232 “legacy” devices in limbo
– including our PICAXE.
This may also be frustrating for GPS,
data logging and PDA applications.
Help is at hand, however, since USB
to serial adaptors ( but NOT vice versa)
are available, althought they may be
quirky and costly (A$60 range) and
need software drivers.
Undemanding “3 wire” serial needs,
such as this PICAXE-08 ,should be
supported by almost any such adaptor
but if conversion problems arise it’s
suggested you just rescue that older
serial-port-fitted Win95 PC from the
broom cupboard!
12 Silicon Chip
References and updated material
For convenience these are hot-linked at website http://picaxe.orconhosting.net.nz/refs.htm
http://picaxe.orconhosting.net.nz
Author’s pictorial page outlining
PICAXE-08 features
http://picaxe.orconhosting.net.nz/progedit Free program editor and PDF
manuals (6 .cab files ~ 8.5 MB)
www.hippy.freeserve.co.uk/picaxe.htm
Overview of entire PICAXE family
www.rev-ed.co.uk
Revolution Education, Bath UK,
microcontroller products
www.picaxe.co.uk
Rev-Ed’s PICAXE products and
programming editor
www.techsupplies.co.uk
Rev-Ed’s online technical
products shop – global sales!
www.jpixton.dircon.co.uk/pic/history.html
PIC history page
www.microchip.com
Microchip PICmicro products
and data.
Who is Stan Swan?
We first met Stan Swan in his "WiFi" article in
SILICON CHIP back in November 2002.
Stan is a New Zealander who first wrangled
electrons with 1960s valve-era ham radio. He is
a career educator teaching Electronics and Computer Technology at the Wellington (NZ) campus
of Massey University.
His enthusiasm for “hands on” appropriate
technology covers such diverse fields as PC interfacing, alternative energy resources, wireless
data comms, digital photography and Internet
applications. He credits Ray Doty’s “Wordless
Workshop “ and the lucid electronics articles
of US writer Forrest M. Mims III as especially
formative influences.
* Stan’s email address is s.t.swan<at>massey.ac.nz
www.siliconchip.com.au
Your first PICAXE application: a simple LED flasher
The 555 timer oscillates under time periods established by external resistor and capacitor values.
If a LED is used at the output, perhaps on a battery-powered bike light, the flash rate, duty cycle
and battery drain can be juggled by changing these
components.
This may be very inconvenient, especially if only
physically larger capacitors are available!
In contrast, a PICAXE LED flasher uses software
tweaks for fine tuning. Flash rates that are the
most attention-getting or duty cycles that prolong
battery life are simply “cut and tried” at the PC
keyboard.
Not only is this more versatile but the parts
count, cost and circuit size are all reduced.
First attach the programming serial cable, connect a LED (plus suitable dropping resistor (see
below) to output 2 and power up the PICAXE-08.
Run the editor (download free from www.rev-ed.
co.uk or http://picaxe.orconhosting.net.nz) on the PC,
enter the following code and send it to the PICAXE.
The comments (preceded by ‘) are not saved on
the IC but are essential documentation for your
future reference. Colons (:) identify the defined
routine – helpful names are best.
ledflash:
high 2
pause 5
low 2
pause 50
goto ledflash
‘LED flash rate & mark/space
experiment
‘turn on output pin 2 – LED lights up
‘keep it on for 5 milliseconds
‘turn off pin 2 – LED goes out
‘keep it off for 50ms
‘repeat routine
The value of RD, the series resistor, depends on
the supply voltage and the type of LED you are using. In fact, it may not even be required as there is
a 20mA limit on the PICAXE output.
But we are used to using current-limiting resistors with LEDs
so let’s keep it that way and avoid
accidents!
For a red LED (which requires
about 2V <at> 10mA), with a 6V supply,
RD = (6-2)/.01, or 400Ω (330Ω would
be fine).
For a white LED (3.6V <at> 25mA),
RD = (6-3.6)/0.025 = 100Ω.
With an ultra-bright white LED,
normally taking 25mA at 3.6V, this
DIY serial leads can be made using
10:1 duty cycle pulsing still gave the
header pins rescued from old
impression of a steady light, yet avermotherboards or modems. First,
age current dropped to just a few mA.
solder the three serial wires, then
This means batteries should last 10
dribble hot-melt glue onto them.
times as long. The inbuilt slight interAllow this to cool somewhat and
preter overhead could mean the timing
while still warm and pliable, work it
is stretched by a millisecond or so.
with your fingers into a neat “plug”.
NEXT MONTH:
www.siliconchip.com.au
The D9 serial plug has its pins 5, 3 &
2 going to PICAXE legs 8 [ground], 2
(via a 22kΩ resistor) [serial in] and
7 via a jumper (S1) [serial out]. A
small photocopied label slid under
protective clear heat-shrink tubing
will identify the plug after final
hot-air shrinking.
A more ambitious application of the PICNIK box. Build your
solderless kit up now and get to know its features in anticipation!
February 2003 13
|