This is only a preview of the November 2003 issue of Silicon Chip. You can view 27 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 "A 12AX7 Valve Audio Preamplifier":
Items relevant to "Our Best LED Torch EVER!":
Items relevant to "Smart Radio Modem For Microcontrollers":
Items relevant to "The PICAXE, Pt.8: The 18X Series":
Items relevant to "A Programmable PIC-Powered Timer":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Communicate without wires . . .
Smart radio modem
for microcontrollers
This cheap and simple radio modem will
enable your PICAXE, Stamp or other micro
to communicate without wires!
L
By NENAD STOJADINOVIC
OW COST, simple construction
and easy interfacing makes this
project ideal for a whole range of
low-speed wireless data applications.
Remote control and sensing are two
obvious uses and there are undoubtedly many more. Even if you’re just
learning about microcontrollers, you’ll
be able to get two PICAXEs talking in
no time!
62 Silicon Chip
The seeds of this project were sown
when I got a call from Mr Vineyard,
whose grapes kept freezing during the
depths of winter. He said he needed a
system that would turn on a misting
water spray over the vines when the
temperature dropped below a certain
level. Apparently, Jack Frost would
then freeze the water rather than the
grapes. This seemed a bit dubious but
I was assured that this is a well-known
method of frost damage control.
The only complicating factor was
that the temperature sensors needed
to be amongst the vines which were
up to half a kilometre away from the
shed that housed the water control
valves. Given half a dozen sensors,
the amount of wiring needed was
clearly impractical. And Mr Vineyard
was very keen to have a temperature
readout in his home so he could keep
an eye on things.
Going wireless
Wireless networking was an obvious choice for the job. Microcontroller-based temperature sensors placed
www.siliconchip.com.au
www.siliconchip.com.au
November 2003 63
Fig.2: one end of the radio link can also be connected to a PC (or any computer with an RS232 port). As shown here, the receiver includes an RS232 interface
on-board, whereas the transmitter requires an add-on interface.
Fig.1: a block diagram of the radio modem, showing how two microcontrollers can be linked together.
Fig.3: the UHF receiver
module uses a “bit
slicer” circuit to convert
the linear signal into
digital format.
strategically amongst the vines could
transmit their readings back to a
central computer, which would then
control the pumps.
Since commercial wireless networking gear was too expensive for this application, the alternative was to design
the wireless network from the ground
up, with the aid of pre-built UHF radio
modules. These miniature modules
operate in the 433.05 - 434.79MHz
LIPD band and do not require a license
for operation at up to 25mW of output
power.
The advertising blurbs suggest that
it’s simply a matter of pumping serial
data into the transmitter module and
recovering it at the receiver (“data
in - radio out”). Discovering that this
was anything but true is what people
ruefully refer to as a “learning experience”. As it turns out, the data must
be “massaged” (encoded, decoded,
error checked, etc) at either end of the
link to achieve reliable transfer across
the airwaves. This was achieved with
the aid of Microchip’s PIC microcontrollers and many hours of program-
Main Features
•
•
•
•
•
•
Point-to-point, one-way wireless data link
Error-checked data transfer
Low cost & easy to build
1200 bps serial interface
speed
465 bps end-to-end speed
150-200m range in built-up
areas
ming. The fruits of these labours are
presented here.
Project overview
The radio modem consists of a
transmitter and receiver pair. The
designs use pre-built “Laipac” brand
433.92MHz UHF modules, with
PIC12C508 microcontrollers handling
the “smarts”.
Both transmitter and receiver include a TTL-level (0-5V) 1200 bps (bits
per second) serial interface for data
transfer. This makes it very easy to
hook them up to your Stamp, PICAXE,
or other micro (see Fig.1).
In many cases (such as the vineyard
application above), one end of the
link will need to be connected to a PC
(Fig.2). The receiver board includes
an RS232 interface for this purpose.
As it’s usually the remote part of
the link, the transmitter doesn’t include an on-board RS232 interface.
This saves space and reduces power
consumption. Where required, it can
be mounted on an (optional) RS232
interface board which also supplies
power.
The receiver and RS232 interface
can be powered from either a 9V
battery or DC plugpack. When used
without the RS232 interface, the
transmitter must be provided with a
+5V supply. This is usually available
from the sensor or associated circuitry.
Serial data
Most of our readers will already be
familiar with the basics of asynchronous serial data transfer. Those new
to the subject will find lots of useful
information on the Internet. Two
informative sources can be found at:
(1). http://janaxelson.com/serport.htm
(2). www.beyondlogic.org/serial/
serial.htm
The word “serial” simply refers to
the fact that data is transferred from
sender to receiver a single bit at a time.
At a minimum, this requires only one
complete circuit (two wires) between
the sender and receiver.
With wires and logic signalling levels, it’s all pretty straightforward. But
how does it work over the airwaves?
UHF radio modules
Fig.4: the complete circuit diagram for the transmitter. Not much to it is there?
An 8-pin PIC microcontroller (IC1) receives serial data from the host (PICAXE,
Stamp, etc) and transmits it over the airwaves using a UHF transmitter module.
64 Silicon Chip
The radio modules used in this
project transmit data by simply switching the carrier signal on and off. The
terms “On-Off Keying” (OOK) and
“amplitude modulation” (AM) are
used interchangeably to describe this
method of transmission.
The transmitter module consists of
a SAW-stabilised RF oscillator tuned
to 433.92MHz. When a logic ‘0’ (0V)
is applied to the data input (DIN) pin,
the oscillator is off and when logic ‘1’
(+5V) is applied, the oscillator is on.
An antenna coupled to the circuit radiates the carrier signal into the ether.
Things get a bit more complicated
at the receiver side. Unfortunately, the
manufacturer’s data sheets don’t reveal
www.siliconchip.com.au
much about its operation. Of course,
we do know that it amplifies and
rectifies the narrow-band 433.92MHz
(±1.5kHz) signal picked up by the
antenna, with the result appearing on
the Linear Output (LOUT) pin.
Data slicing
A digital version of the signal also
appears on the Digital Output (DOUT)
pin. Conversion between analog (linear) and digital is performed with a “bit
slicer” circuit. As the name suggests,
the bit slicer looks at the incoming
signal and decides whether it should
be a logic ‘0’ or logic ‘1’, “slicing” it
up accordingly.
This is achieved with a circuit
similar to that shown in Fig.3. IC1 is
configured as a comparator and once
the capacitor is charged up, a signal
peak at the input will result in a high
at DOUT while a signal minimum will
result in a low.
The frequency of ‘1’s (transmitter
on) and ‘0’s (transmitter off) in the
data stream determine the accuracy
of the slicer. If the time between ‘1’s
is too long, the capacitor voltage sags
and ‘1’s will be detected as ‘0’s instead.
Conversely, if the data stream contains
Fig.5: this add-on interface connects the transmitter to an RS232-compatible
serial port. The MAX232 chip (IC1) handles the RS232 (±10V) to TTL (0-5V)
level conversion, while 3-terminal regulator REG1 also powers the transmitter
board.
Fig.6: the receiver circuit is almost a mirror image of the transmitter. PIC micro IC1 receives data from the UHF receiver
module and after decoding and error checking, passes it on to the host via the DATA output. Unlike the transmitter, an
RS232 interface (IC2) is included on-board.
www.siliconchip.com.au
November 2003 65
Fig.7: follow this diagram when assembling the transmitter. If you’ve opted for a more elaborate antenna
(instead of the single length of wire), the coax shield can be soldered to the ground pad right next to the antenna
connection point.
too many consecutive ‘1’s, a ‘0’ will go
undetected.
Transmission speed also affects
the average voltage on the capacitor.
Circuit time constant is optimised for
a particular “baseboard” data rate,
which for these modules is specified
as 3000 bps.
As you can see, the ideal situation
exists when the transmitter is fed
with an alternate stream of ‘1’s and
‘0’s at the prescribed data rate. In fact,
data transmission must begin with a
preamble of alternating 1’s and 0’s of
sufficient length to “initialise” the data
slicer at the receiver end.
Of course, during “normal” transmission, data can consist of any combination of ‘1’s and ‘0’s. This is easily
accommodated by encoding the data
before transmission.
Manchester encoding
A number of encoding techniques
can be employed to ensure that the
data stream contains a balance of ‘1’s
and ‘0’s.
This project uses “50% Manchester” encoding, which simply involves
sending every bit along with its
complement. Thus ‘0’ becomes ‘01’
and ‘1’ becomes ‘10’. It is simple and
robust but does take twice the time to
send each byte. However, this is not
of particular concern for our “lowspeed” link.
Error detection
With all the potential for lost or
corrupted data over a radio link,
some kind of error detection system is
mandatory. Along with data encoding,
error detection is another of the main
functions of the PIC microcontrollers
in the transmitter and receiver pair.
The PIC micro in the transmitter
sends data in blocks or “packets”.
Before transmission, all data bytes in
a packet are passed through a polynomial generator, with the result being
an 8-bit number called a “Cyclic Redundancy Check” (CRC). This byte is
appended to the end of a packet before
transmission.
On the receiver side, incoming data
is passed through the same polynomial
generation algorithm and the result is
compared to the received CRC byte. If
they match, the data is deemed good.
Otherwise, it is assumed bad and the
entire packet discarded.
If you’re interested in the algorithm
and microcontroller code required
to generate CRCs, then check out
Microchip’s application note AN730,
entitled “CRC Generating and Checking”. It can be downloaded from
www.microchip.com
Bytes & packets
As mentioned above, data received
from the “host” (your PICAXE, Stamp,
Fig.8: receiver assembly is also quite straightforward. The UHF receiver module
must be oriented with its inductors (coils) facing the two ICs. The “SPARE”
signal line is not used and should be left unconnected.
66 Silicon Chip
www.siliconchip.com.au
Fig.9: the overlay diagram for the optional RS232 interface. Install
all components before mounting the transmitter board. Note that the
electrolytic capacitors go in different ways, so make sure that you have
their positive leads oriented as shown
PC, etc) is assembled into packets
before transmission. Each packet
is preceded with a preamble, two
“authorisation” bytes (FF 00) and a
length byte to indicate the number of
data bytes to follow. Data length may
be from 1-16 bytes, with a CRC byte
appended to the end.
Of course, the receiver returns only
the data part of the transmission to its
host; the other bytes are strictly for
housekeeping. This means that apart
from a certain amount of latency, the
radio modem link looks just like a
piece of wire between the sender and
receiver!
So far, we’ve only described the
radio side of the link. Let’s now look
at how you connect your PICAXE,
Stamp or whatever to the transmitter
and receiver.
Transmitter hook-up
Your microcontroller project interfaces to the transmitter via a 3 or
4-wire interface (see Fig.1). For a
basic setup, you need connect only the
DATA, SEND and GND lines.
Serial data must be sent on the
DATA line at 1,200 bps using the
standard format of 8 data bits, no parity
and 1 stop bit. The SEND line is used
for handshaking and in the idle state
must be held high (+5V).
To transmit data, send 1-16 bytes
and then bring the SEND line low (0V).
Data transmission begins immediately
and after an appropriate delay (see the
“Radio-Modem Performance” panel),
the SEND line can be brought high
www.siliconchip.com.au
Listing 1
symbol
symbol
begin:
SEND = 1
TX_DATA = 2
high
SEND
pause
1
serout
TX_DATA,T1200,(“A”)
low
SEND
pause
500
goto
begin
again and the transmitter is ready to
accept more data.
The PICAXE microcontroller program to transmit a single character at
a time might look something like that
shown in Listing 1.
For maximum transmission speed,
the BUSY line can be connected as
well. This line is an output from the
transmitter and indicates its status.
When BUSY is high, the transmitter
is sending data, and when low, it’s
'transmitter SEND line on pin 1
'transmitter DATA line on pin 2
'raise the SEND line
'1ms delay
'load the ASCII character “A”
'lower the pin to send the data
'wait 0.5 sec while the data goes
'loop to repeat forever
ready to accept the next packet of data.
Listing 2 shows a simple example.
Note that attempting to load more
than the maximum of 16 bytes at a
time will result in BUSY going high
and the additional bytes going into
the bit bucket.
Receiver hook-up
The receiver interface is even simpler and requires only a 2-wire connection. Again, a fragment of PICAXE
Listing 2
symbol
symbol
symbol
begin:
waitrdy:
SEND = 1
TX_DATA = 2
BUSY = 3
high
SEND
pause
1
serout
TX_DATA,T1200,(“Hello”)
low
SEND
pause
1
'transmitter SEND on pin 1
'transmitter DATA on pin 2
'transmitter BUSY on pin 3
'raise the SEND line
‘1ms delay
‘load the ASCII string “Hello”
'lower the pin to send the data
'1ms delay
if BUSY = 1 then waitrdy
goto
begin
'loop until not busy (data sent)
'repeat forever
November 2003 67
Radio Modem – Performance
Range: maximum output power with a 5V supply is listed as 25mW (14dBm)
into a 50Ω antenna. This provides a range of 150 - 200 metres in the suburbs
and rather more over open terrain. Maximum range is heavily dependent on
antenna efficiency and environmental conditions.
Speed: data is transferred between the transmitter/receiver and the connected device (PC, PICAXE, etc) at a rate of 1200 bps. However, due to the
overheads involved in the radio transmission, actual throughput is slightly
less than half that speed.
Calculated on a maximum payload of 16 bytes per transmission, the radio link
speed is equivalent to about 465 bps. That’s about 343ms per transmission,
plus the time taken to load and unload the data at either end (about 8.33ms
per byte).
Power consumption: with a 9V supply, the receiver consumes about 16mA.
More than 10mA of this is used by the MAX232, so for battery-powered receivers, don’t install this chip if it’s not needed.
When idle, the transmitter requires less than 1mA. During transmission, this
peaks at about 6mA. When plugged into the RS232 board, total consumption
increases to 12mA at idle and about 17mA (peak) when transmitting.
code illustrates how to receive a byte
– see Listing 3.
As you can see from this listing,
it’s simply a matter of listening on
the DATA line for the incoming serial data.
PC Connection
One end of the link can also be
connected to a PC or other computer
system with an RS232-compatible serial port (see Fig.2). The receiver board
includes an RS232 interface, so it’s a
simple plug-n-play proposition.
Alternatively, for remote control
applications, the transmitter end can
have the RS232 connection. A simple
add-on RS232 interface board (is required for the hook-up (see Fig.6 and
the photos).
A PC connected to the receiver
board can display and/or capture
incoming data with a simple serial
terminal program (see the testing procedure below). If the data is in ASCII
format, Windows “HyperTerminal”
will suffice. However, if you want to
see the “raw” binary data, then you’ll
need a program like “RealTerm” instead. RealTerm is available free from
realterm.sourceforge.net
To send data from a PC connected to
the transmitter, you need more than a
simple terminal program. Your application must take control of the SEND
line (RTS), and optionally read the
status of the BUSY line (DSR).
Note: the radio modem is not intended for PC to PC data transfers. Attempting to move “PC-sized” amounts
of data across a 465 bps link would be
pointless.
Transmitter assembly
With only nine parts on the board,
you’ll have the transmitter assembled
in no time at all. Fig.7 shows the component placement.
The three 1kΩ resistors must be
mounted vertically rather than horizontally and note the orientation of the
2.2µF capacitor and microcontroller
(IC1). In addition, make sure that you
have the transmitter module in the
right way around – the SAW resonator
(in the round metal can) must face
towards IC1.
Receiver assembly
Install the single wire link first,
using 0.7mm tinned copper wire. All
components can then be installed in
Listing 3
Symbol RX_DATA = 2
serin RX_DATA,T1200,B2
68 Silicon Chip
'receiver DATA on pin 2
'wait for a byte & store it in variable B2
order of height (see Fig.8).
Again, take care with the orientation
of the polarised components, these
being diode D1, the 22µF capacitors
and the ICs. The receiver module goes
in with its coils facing toward the ICs
(see photos).
If don’t intend connecting the receiver to a PC, you can leave out the
MAX232 receiver/driver (IC2). This
will save power in a battery-powered
setup. However, you may prefer to
socket the chip and remove it later, as
the test procedure (below) requires a
PC connection.
RS232 interface assembly
As before, install the two wire links
first, then all components in order of
height. Take particular care with the
orientation of the four 1µF capacitors,
as they go in different ways around on
the PC board.
The transmitter board mounts vertically near one edge of this board via
90° header pins. Install the 2-way and
3-way SIL header pins on the transmitter board first and then fit this assembly
to the RS232 interface board.
Before soldering into place, check
that the edge of the transmitter PC
board contacts the RS232 PC board
and that the whole arrangement is
sitting “square”.
Antenna
For testing purposes and many
real-world applications, the antenna
can be as simple as a 165mm length
of light-duty hook-up wire. Strip and
tin one end of the wire and solder to
the transmitter’s antenna connection
point. Repeat for the receiver board
(see Figs.7 & 8).
For best results, the antenna wires
should be kept clear of large metal
objects and human bodies!
Testing
Both the receiver and RS232 interface boards can be powered from a 9V
battery or 9V DC plugpack. The battery
clip leads (or flying leads from a panel-mount DC socket) can be soldered
directly to the ‘+V’ and ‘0V’ pads.
Note: 12V DC unregulated plugpacks are not suitable for this project
due to their excessively high output
voltages at light loads.
If you’re not using the RS232 board,
connect a regulated 5V supply to the
transmitter’s ‘+5V’ and ‘GND’ pads.
Next, connect the receiver to a free
www.siliconchip.com.au
Where To Get The Parts
Kits of parts for this project are available from the author. Kits include the PC
board and all on-board components (battery, plugpack, enclosure & antenna
are not supplied). At time of writing, prices are as follows:
Transmitter............................................................................................... $25
Receiver................................................................................................... $40
Transmitter & Receiver pair...................................................................... $60
RS232 Interface....................................................................................... $25
Programmed PICs can also be purchased separately:
PIC12C508A for Transmitter (including 4MHz resonator)........................ $15
PIC12C508A for Receiver (including 4MHz resonator)............................ $15
If you’re interested in a “rubber duck” or other specialised antenna, write and
ask for a current price list. All prices include postage within Australia. To order,
write or email the author at:
Nenad Stojadinovic, PO Box 320, Woden, ACT 2606.
email: vladimir<at>u030.aone.net.au
The Laipac UHF transmitter & receiver modules are
also available from Commlinx Solutions, online at
www.commlinx.com.au
serial port on your PC using a standard
9-way “pin-to-pin” cable (not a “null
modem” type). To be able to “see” the
incoming data, launch your favourite
serial terminal application. HyperTerminal (supplied with Windows)
will do the job. Set the terminal’s
communication parameters to match
the chosen COM port, with a data rate
of 1200 bps, 8 data bits, 1 stop bit and
no parity.
Right, we’re all set. Make sure that
transmitter power is off and place
a jumper shunt across the “TEST”
pins (JP1). Now power up
the transmitter and you
should see the characters
“0123456789:;<=>?” appear
in the terminal window.
A built-in test routine transmits this string of characters
continuously when the SEND
line is held low (0V) at power-up. This, of course, is the
purpose of the “TEST” jumper.
Fault-finding
No go? First, check the supply
This view
shows the
completed
RS232
interface
with the
transmitter
board
mounted in
position.
www.siliconchip.com.au
rails. To do this, use your multimeter
to measure between pins 1 & 8 of IC1
on both the transmitter and receiver
boards. On the receiver, expect close to
5.0V, whereas on the transmitter, your
reading should be about 4.7V.
Next, use a logic probe or oscilloscope to monitor the signal on pin 7 of
the transmitter’s micro (IC1). With the
jumper shunt (JP1) installed at power-up, there should a burst of pulses
each time the 16-character test string
is transmitted.
If that checks OK, then it’s over to
the receiver side. Examine pin 4 of
the receiver’s micro (IC1). Normally,
background noise picked up by the
UHF receiver module appears on this
pin as random “garbage”. However,
you should see a distinctive change
in the pattern whenever the test string
is received.
Assuming that you see signs of activity, then measure at the micro’s serial
data output (pin 7). Again, brief bursts
of pulses should appear here if the test
string is received successfully.
The last link
The last link in the chain is the
MAX232 (IC2) on the receiver. As
shown on the circuit diagram (Fig.6),
serial data from the micro (pin 7) is
applied to the MAX232 on pin 11.
Therefore, it should appear on pin 14
after conversion to the ±10V (nominal) RS232 signal levels. This pin
should sit near -8V when idle and
pulse to about +9V when sending
the test data.
One option is to fit the
transmitter into a small
metal diecast case complete with a “rubberduck” antenna.
November 2003 69
Parts List
Receiver
1 PC board coded 06111031,
63mm x 55mm
1 Laipac RLP-434 transmitter
module
1 PIC12C508A (programmed)
(IC1)
1 MAX232 RS232 receiver/driver
(IC2)
1 78L05 +5V regulator (REG1)
1 1N4004 diode (D1)
1 4MHz 3-pin ceramic resonator
(CR1)
1 D9 female connector, 90° PCmount (CON1)
1 9V battery & battery clip -OR1 9V DC 150mA plugpack &
panel-mount DC socket to suit
Capacitors
2 22µF 25V PC electrolytic
7 100nF 50V monolithic
Resistors (0.25W, 1%)
2 1kΩ
Transmitter
1 PC board coded 06111032,
37mm x 29mm
1 Laipac TLP-434 transmitter
module
1 PIC12C508A (programmed)
(IC1)
1 1N5819 Schottky diode (D1)
1 4MHz 3-pin ceramic resonator
(CR1)
Capacitors
1 2.2µF 16V tantalum
1 100nF 50V monolithic
Resistors (0.25W, 1%)
3 1kΩ
RS232 Interface (optional for
transmitter, see text)
1 PC board coded 06111033,
51mm x 46mm
1 MAX232 RS232 receiver/driver
(IC1)
1 78L05 +5V regulator (REG1)
1 D9 female connector, 90° PCmount (CON1)
1 3-way 2.54mm 90° SIL header
1 2-way 2.54mm 90° SIL header
1 2-way 2.54mm SIL header
(JP1)
1 jumper shunt (JP1)
1 9V battery & battery clip -OR1 9V DC 150mA plugpack &
panel-mount DC socket to suit
Capacitors
4 1µF 16V PC electrolytic
2 100nF 50V monolithic
Resistors (0.25W, 1%)
1 1kΩ
If you’ve successfully traced the test
data from start to finish, then the problem must be related to your computer!
Double-check the terminal program
settings and the cable connection
between the unit and the PC.
A good vintage, indeed
What of the “radio thermometer”
project? Well, I built it into one of
those cheap solar-powered LED garden lights. Using ‘sleep’ mode on the
micro, the device now sends temperature and humidity readings to the
water control unit every minute or
so and is working very nicely after
six months of totally unattended
operation!
More reading
Technical data on the RLP-434 &
TLP-434 UHF modules used in this
project can be downloaded from the
Laipac Technology web site at www.
laipac.com
For details on government regulations regarding LIPD radio communications devices, visit the Australian
Communications Authority web
site at www.aca.gov.au/aca_home/
legislation/radcomm/class_licences/
lipd.htm
A high-performance commercial
radio modem was reviewed in SILICON
CHIP, February 2003. Details on the
WM232-UHF modem featured in the
review can be obtained from http://
SC
www.radiotelemetry.co.uk/
New From
SILICON C
HIP
THE PROJECTS: High-Energy Universal Ignition System; High-Energy
Multispark CDI System; Programmable Ignition Timing Module; Digital
Speed Alarm & Speedometer; Digital Tachometer With LED Display;
Digital Voltmeter (12V or 24V); Blocked Filter Alarm; Simple Mixture
Display For Fuel-Injected Cars; Motorbike Alarm; Headlight Reminder;
Engine Immobiliser Mk.2; Engine Rev Limiter; 4-Channel UHF Remote
Control; LED Lighting For Cars; The Booze Buster Breath Tester; Little
Dynamite Subwoofer; Neon Tube Modulator.
ON SALE AT SELECTED NEWSAGENTS
Mail order prices:
Aust: $14.95 (incl. GST & P&P)
NZ/Asia Pacific: $18.00 via airmail
Rest of World: $21.50 via airmail
Or order by phoning (02) 9979 5644 & quoting your credit card number; or fax the details to (02) 9979 6503; or mail
your order with cheque or credit card details to Silicon Chip Publications, PO Box 139, Collaroy, NSW 2097.
70 Silicon Chip
www.siliconchip.com.au
|