Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

PIC TAPE MEASURE by JOHN BECKER

Microcontrolled ultrasonic distance calculator with The pulses are accurately


data recording and foreground masking. generated in software at a rate
determined by the controller's
Quite naturally, many of you memory), a data store and operating frequency (4MHz as
will be wondering how PIC recall facility have been set by crystal X1) and the
devices can be used to update programmed in as well. There is number of commands that are
some of your favorite designs. also a masking option that processed between each phase
PICs are, as we are proving on allows foreground echoes to be of the output signal.
frequent occasions, extremely ignored. PIC output pins RA0 and
versatile devices and can be The device can record and RA1 are used as the push-pull
used in many circuits to replace recall 30 or 32 (see later) source which drives the
quite a few conventional logic distance measurements, transmitter transducer. One pin
chips. allowing several readings to be alternates between high and
Recently, the author's eye taken before copying them to low, while the other alternates
fell on his earlier Ultrasonic paper − ideal when taking between low and high.
Tape Measure (EPE hard copy measurements in difficult to Solid objects within the path
magazine Sept 92) and began access locations! of this signal reflect it back to
to speculate about how it too There is a choice of two the ultrasonic receiving
could be simplified using a PIC. software programs for the unit. transducer, RX1. The echo
The result (after about an hour The Standard program requires signals are at a considerably
with a soldering iron and many no adjustment to the timing and lower amplitude than those
hours at the computer), is calculation factors and assumes transmitted and require a fair
before you now − a PIC16C84- a rigidly fixed speed of sound. amount of amplification in order
controlled ultrasonic tape The Extended program allows to be recognizable by the PIC
measure. fine tuning of the calculation as logic signals.
values and requires a small
amount of setting up to
be done via the software AMPLIFICATION
and the panel function The 40kHz echo signals
switches. The receive two stages of a.c.
electronics hardware is amplification. A gain of 100 is
identical for both programs. provided by opamp IC1a, as set
by resistors R1 and R4. Opamp
CIRCUIT DIAGRAM IC1b provides a further gain of
The complete circuit about 47, as set by R5 and R6.
diagram for the PIC Tape Capacitor C6 then feeds the
Measure is shown in Fig.1. amplified signal to transistor
In a nutshell, the PIC TR1, whose purpose is to
microcontroller (IC2) is the provide logic-level pulses to the
mastermind that controls the PIC at pin RB7. Between them,
Not only is it an update on
whole operation. When resistor R7 and preset VR1 set
the previous design, it is a quite
prompted by the pressing of a basic d.c. bias on the base (b)
significantly more advanced
Send switch S2, the PIC of TR1, determining the
instrument. Taking advantage
transmits a series of 40kHz response sensitivity.
of the PIC16C84's internal
EEPROM (electrically erasable pulses via the ultrasonic The output from TR1's
programmable read only transmitting transducer TX1. collector normally rests at 5V,
Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 5
Maxfield & Montrose Interactive Inc
but swings between 5V and 0V are shown top left, followed by
in the presence of suitably letters “mt”. Feet and inches
strong echo signals. Immedi- are shown bottom left, complete
ately the PIC has finished with letters of “ft” and “in” (see
transmitting the brief chain of photographs).
40kHz pulses, it starts a 2-byte The transmission and echo
counter (16-bits) which incre- conversion process continues
ments at a known rate. When for as long as the Send button Front panel display window and
the PIC recognizes that pin RB7 remains pressed. You can, function buttons. A recalled
has changed its logic state from therefore, pan around a room
high to low in response to an measurement is shown.
and just generally view its dim-
output from TR1, the counter ensions until you are ready to
is stopped. accept a measurement. At this
moment, releasing the switch will
MEASUREMENT
cause the last measurement read RECORDING
CALCULATIONS to stay on the LCD screen. It will The measurement shown
The software now goes into remain there until Send is on the display is not yet
its calculation routine, in which pressed again, or Recall switch recorded in the PIC's EEPROM
it converts the count value into S5 is pressed, or the unit is memory. That action occurs
two distance values, one in switched off. when Store switch S3 is
metric (meters to three decimal While Send is pressed, the pressed. Since the switch status
places) and one in imperial (feet sampling rate is normally a little is only read by the PIC when it
and inches). These measure- under once per second − has finished its calculation and
ments are displayed on the X2 depending on the mask and display, the measurement
16-character 2-line LCD (liquid distance values. recorded is always the one just
crystal display module). Meters completed. This ensures that an

R4
1M R6
R2 470k R7 R8
C3 R1 100k 100k 10k
22n 10k
2 - C5 R5
22n 10k 8 C6
IC1a 1 6 -
22n
3 LM358
+ IC1b 7
TRANSMIT
5 LM358
+
TX1 RX1 TR1
40kHz 40kHz RECEIVE 4
BC549
c
C4 R3 VR1 b
BIAS
100n 100k 20k
e

SEND STORE MASK


IN IC3 OUT
78L05
S2 S3 S4
COM
14
+
C1 C2 +VE 2
22 u 100n 17
RA0 +VE
IC2 18 7
RA1 NC D0
PIC16C84 1 8
4 RA2 NC D1
MCLR 2 9
RA3 NC D2
S1 3 10
ON/OFF TOCKI/RA4 NC D3
C8 6 11 X2
INT/RB0 D4
10p 7 12 L.C.D.
16 RB1 D5 MODULE
OSC1/CLK IN 8 13
RB2 D6
9 14
C7 X1 RB3 D7
4MHz 10 4
10p RB4 RS
15 11 6 3
B1 OSC2/CLK OUT RB5 E CONTRAST
12 5
9V CLK/RB6 R/W
13 GND
DIO/RB7
GND
1
5 CONTRA ST
S5
R9 R10 R11
10k 10k 10k VR2
RECALL
10k

0V

Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 6
Maxfield & Montrose Interactive Inc
incomplete measurement is
never stored (i.e. one caught in
the middle of transmission).
The information is stored as
the count value achieved, not in
meters or feet. Consequently,
only two bytes of EEPROM
memory are used. The PIC has
64 bytes of this memory available
and up to 32 measurements can
be recorded with the Standard
program.
With the Extended program,
30 measurements can be stored,
the other bytes being reserved for Prototype PCB mounted “below” the display module.
timing and counting values.
Each time a measurement is EEPROM RESET MASKING
stored, a record counter is
incremented. This is displayed on A facility to reset the Record The masking facility allows
the top right of the LCD so that and Recall counters to zero foreground echoes to be
you know how many readings you during normal use has not been ignored within a timing/distance
have taken. Immediately in front included. With the Standard range set via the Mask switch
of this value the message program, they are automatically S4. This allows you, for
“SAVED” appears. reset at the moment of switching example, to read the distance of
on the unit. With the Extended a far wall when a clutter of
It is not possible to step the program, the Recall counter is furniture is between you and the
counter back in order to store reset at each switch on, but the wall. Without this facility, the
another measurement at this Record counter is only reset when echoes from the furniture would
count location. Thus, if you make the full EEPROM measurement be those read by the “tape
a recording in error, you must data contents are reset. The measure.”
remember that the value at this EEPROM measurement data
location is to be disregarded To an extent, however, this
remains intact until intentionally facility has to be used with
when you examine the record- reset. This can be done at switch-
ings later. discretion, since it is possible
on. If the Store button is pressed that too long a masking distance
and held down immediately prior could allow multiple reflections
to and during switching on, all
PLAYBACK stored measurements are
to be read, i.e. those that
ricochet around the room before
To play back the stored cleared, and the Record and returning to the unit.
recordings, the Recall switch is Recall counters set to zero.
used. Each time it is Inclusion of a gain
pressed, a Recall counter control was considered in
is incremented. The 2-byte order to reduce this
data from the EEPROM at possibility, but it was
the equivalent address to concluded that having both
the count (count × 2) is a mask and a gain control
read and converted to might be confusing to use
metric and imperial as in practice, and the idea
before. was dropped. If you would
like an external sensitivity
The Recall counter control, replace VR1 with a
value is also displayed at case mounted potentio-
the top right in place of the meter of the same value
Record counter value. (you may need a bit bigger
Immediately in front of it Screen photo 1. Without masking, the
case, though).
the message “SHOW=” center line “echoes” could be interpreted as
appears. measurement signals. The software is written
so that the masking
Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 7
Maxfield & Montrose Interactive Inc
COMPONENTS
14 1 X2 L.C.D. MODULE Resistors
R1, R5, R8 to R11 10k (6 off)
R2, R3, R7 100k (3 off)
R4 1M
14 1 R6 470k
VR2
C2 C3
All 0.25W 5% carbon film or better
R R R
11 10 9 R RX1
C4 1 R Potentiometers
C
TR1 R3 4
5 VR1 20k miniature round preset
R2
b VR1 VR2 10k miniature round preset
R R R
8 c e 5 6
IC2 IC1 Capacitors
C1 22u radial electrolytic, 16V
C6
R
TX1 C2, C4 100n ceramic disc
X1 IC3
C7 7 0V (0.2in spacing – 2 off)
BLACK
C8 COM C1 C3, C5, C6 22n polystyrene (3 off)
OUT IN + +VE RED C7, C8 10p polystyrene (2 off)
Semiconductors
TR1 BC549 npn transistor
TO IC1 LM358 dual opamp
BATTERY B1
IC2 PIC16C84 (or PIC16F84)
S5 S4 S3 S2 S1
pre-programmed microcontroller –
RECALL MASK STORE SEND ON/OFF
see text
IC3 78L05 +5V 100mA voltage
regulator
Miscellaneous
S1 miniature s.p.s.t toggle switch
S2 to S5 miniature push-to-make
switch (4 off)
RX1 miniature 40kHz ultrasonic
receiver
TX1 miniature 40kHz ultrasonic
transmitter
X1 4MHz crystal
X2 16-character 2-line alphanumeric
LCD display
B1 9V PP3 battery and clip

Printed circuit board available from


the EPE Online PCB Service, code
Fig.2. PIC Tape Measure PCB topside component layout, 207; plastic case, 120mm x 64mm x
40mm; 8-pin DIL socket; 18-pin DIL
interwiring, and copper foil master pattern. socket; self-adhesive rubber feet (3
off) (see text); nuts and bolts, M3 x
12mm (2 off) (see text); connecting
distance progressively increa- per second, The rate may be wire, solder, etc.
ses while Mask is pressed, slower when the value is greater See also the
ranging (in steps of one) from than zero and the Send button is SHOP TALK Page!
zero to nine with the Standard pressed at the same time. In this
program and one to nine with situation, if an echo is not being Approx. Cost
the Extended program, rolling received the software waits until a Guidance Only $53
over to zero again following time-out occurs before it again
nine. The mask value is dis- examines the switch. It is normally are seen at different amplitudes.
played at the bottom right of the better to press Mask when Send is The first echo is (normally) too
screen, prefixed by the word not pressed. small to be accepted as a valid
Mask. It represents an approxi- echo. The second echo, though,
mate (but not precise) distance is large enough for the software
in meters. If the value shown is MASQUERADE to accept it as the trigger signal,
above zero, it is followed by the Screen photo 1 illustrates why reacting to it about half way
letter “m” for meters. a mask is useful. The final pulse of above its central (d.c.) position,
Switch S4 increments the the transmission signal is seen top and it will do so if no response
mask value at about two digits left, and centrally five echo signals delay is included.

Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 8
Maxfield & Montrose Interactive Inc
By inserting a suitable delay transducer and the output of wires (20 s.w.g. tinned copper
in the software before it starts opamp IC1b. For the sake of wire − although resistor offcuts
looking for echoes, the second illustration, the conditions were might be suitable), or short
echo can be ignored, with the set up slightly unnaturally in that lengths of flexible insulated
third echo being the one that is the echoes are those from small connecting wire may be used.
accepted. Extending the delay a items deliberately placed only a Using rigid wires, the LCD
bit further, the response can be few inches in front of the trans- can be mounted above the rear
timed to only accept the fifth ducers. The data was recorded of the PCB at a height of about
echo. on disk some months before 7mm, i.e. clear of any danger of
being recalled to the soldered joints and trimmed
the screen for component leads touching any
photography. part of the LCD. To ensure this
Although the could not happen if the two units
pulses have a were squeezed, two rubber
40kHz content, the spacers (self-adhesive feet)
frequency shown at were inserted between them.
the bottom right of The viewing window slot for
the screen the LCD is in the base of the
(2979⋅27Hz) has plastic case. It can be cut in the
resulted because time-honored method of drilling
the transmission a series of holes and then filing
and return pulses down to the correct size to
are not continuous, accept the friction-fitting of the
the V-Scope ass- LCD's metal frame. Ensure that
essing frequency the positioning of the LCD and
PCB folded back to reveal the layout, from the number of PCB allows room for the battery
interwiring and full size copper foil pulses occurring in at one end, yet does not allow
one second. the corner pillars in the case to
master pattern.
interfere with the mounting of
the assembly.
As illustrated, the fourth POWER SUPPLY
echo is too small to be recogn- Drill two holes in the case
The PIC Tape Measure runs to allow the LCD to be secured
ized. However, if the bias level from a 9V PP3 battery. Current
on transistor TR1 were to be with two nuts and bolts via its
drawn is normally about 6mA, own mounting holes (those
suitably increased, effectively rising to about 7mA (average)
increasing the gain, both the furthest away from the LCD/
during transmission. PCB connections).
first and fourth echoes could be
responded to if the delay was Regulator IC3 drops the 9V It is preferable to insert thin
set appropriately. supply down to 5V to suit the spacers between the case and
PIC and the LCD. LCD (another nut on each bolt),
Note, though, that the first
echo is probably the residual so that the ends of the soldered
ringing of the receiving trans- connecting wires do not prevent
CONSTRUCTION the LCD from sitting comfort-
ducer rather than a true echo.
Without any response delay, Details of the printed circuit ably against the case. Any
this undesirable signal would board (PCB) component layout distortion of the LCD module
trigger the unit, preventing it and tracking are shown in Fig.2. could prevent it from working.
from responding to any of the The board is available from the Once the display slot has
subsequent pulses. This is why EPE Online PCB Service, been completed, and before the
a minimum masking value of code 207. It is essential to use a LCD is mounted in the case,
one (about one meter) is socket for IC2, and recommen- drill holes alongside and above
necessary with higher bias ded for IC1. Fit the on-board the slot for the five switches.
settings. link wires first, then assemble Also drill holes in the end of the
the board in any order you find case for the ultrasonic trans-
The display seen in Photo 1 convenient.
was created by coupling the ducer pins. Use a drill bit of
EPE Virtual Scope (Jan/Sept The LCD module may be about the same size as the
'98) to the transmitting connected to the PCB by rigid transducer pins so that a friction
Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 9
Maxfield & Montrose Interactive Inc
fit occurs. Wire-up the switches EPE PIC TAPE BOX TX1 is one factor. This is likely
as shown in Fig.2, and in the PRESS SEND KEY to vary between different units
order seen in the photographs, of the same type, due to
using ordinary multistrand You may need to adjust the manufacturing tolerances.
connecting wire. The trans- Contrast preset VR2 to make Similarly, the sensitivity of the
ducers should be connected the message visible. receiving transducer (RX1) is
with solid wire, to secure them equally likely to vary between
rigidly in the case. Ensure that units. The relative alignment
the transducers are in good ALIGNMENT ROUTINES accuracy of the two transducers
alignment with each other, to At this point with the also plays a part.
optimize the signal transmission Extended program version, Another factor is the nature
and return paths. there are some alignment of the surface from which the
It is imperative to ensure routines to be performed
that there is no chance of the via the switches. These
9V power connection on the will be discussed later
PCB (or the 9V track at the section headed
“Extended Program
underneath) coming into
Version.” Until then,
contact with the tags of the
the following paragraphs
switches. Such an
refer to both versions.
occurrence could kill the PIC Typical screen display in the
and the LCD. Use two or three In normal use, when
the unit is first switched on Mask set-up mode
layers of insulating tape on
the switch tags and rear of the opening message is
displayed and the soft-ware ultrasonic beam is being
the PCB.
goes into a loop in which it waits reflected. Hard surfaces will
Another self-adhesive for any of the function switches provide stronger echoes than
rubber spacer may be attached S2 to S5 to be pressed. soft ones.
to the inside of the lid to prevent
Point the PIC Tape Additionally, if the unit is
the battery from rattling when
Measure at a nearby wall, being used outside (don't let it
the unit is fully enclosed.
without any other object in the get wet) the wind may deflect or
signal path. Press the Send impede the transmitted and
FIRST TESTS switch S2. The distance that the reflected signals, reducing the
wall is away from the front of echo signal amplitude received
Having thoroughly checked the unit should be displayed on by the unit.
the completed assembly for the LCD in meters and feet plus
shorts etc., plug in opamp IC1, inches.
but not microcontroller IC2.
The words LIVE and Mask,
BIAS LEVEL
Switch on the battery supply
plus the mask value will also The most crucial factor,
and check that the output from
be shown. Keep Send pressed though, is the bias level on TR1.
regulator IC3 is at 5V.
and move backwards and With the bias set at 0⋅3V, a
Adjust preset VR1 so that forwards with respect to the maximum measuring distance
the bias on the base of trans- wall, observing the change in of about six meters is a reason-
istor TR1 is about 0⋅3V. distance readings. Ensure that able expectation. Increasing the
If all is well, switch off the signal is not reflected off the bias to about 5⋅5V (using preset
and plug in the PIC16C84 (or hand pressing the switch. VR1), distances in excess of 10
PIC16F84), which must be meters should be achievable.
preprogrammed (see later). The bias could, perhaps, be
Switching on again (without
DISTANCE EXTREMES raised to about 0⋅6V, allowing
any of switches S2 to S5 being The minimum distance really low amplitude echo
pressed), the PIC will start readable with a mask value of signals to trigger transistor TR1.
running. The first thing it does is zero and transistor TR1's bias at The danger of making it too
to initialize the LCD, setting it to 0⋅3V, is about 55mm (2in). The sensitive, though, is that multi-
4-bit control mode and then, on maximum depends on a ple echoes from around the
two lines, displays the number of factors. The trans- room will be picked up, resulting
opening message: mission power of transducer in false readings.

Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 10
Maxfield & Montrose Interactive Inc
Also, increased sensitivity DATA RECORDING memory even when the power
makes the system susceptible is switched off, remaining there
to being triggered by the “ring- To record a displayed until overwritten (be aware of
ing” of the receiving transducer, reading, press Store switch S3. this in other situations if you use
caused by its proximity to the Note that the reading displayed a previously programmed PIC
transmitter. The mask facility, must be one that has just been '84 for another program).
though, will usually allow this acquired by taking a measure-
ment. A reading which has been As stated earlier, the data
effect to be ignored, except at can be overwritten by zeros
excessively sensitive settings of recalled for display will not be
re-recorded over itself. when the Store switch is held
VR1/TR1. down while switching on.
Use discretion and ensure So that you know whether
you are looking at a real or With the Standard software
that the triggering is always program, note that each time
reliable in normal measuring recalled reading, the messages
“LIVE” and “SHOW” are disp- you switch on the unit, the Store
situations, at the expense of (Record) counter is reset to one,
its long distance abilities. layed accordingly. You can only
record if “LIVE” is showing. The consequently you should not
record number of the newly switch off during a sequence of
measurements.
MASK TESTING stored measurement is
displayed on the top right of the However, the Extended
To test the masking facility LCD. Separate EEPROM program records both the
(initially with a bias of about address pairs are used in measurement data and the
0⋅3V), place the unit on the ascending order each time counter value in the EEPROM,
edge of a table facing a wall Store is pressed. When roll-over and with this version you may
and place a dining chair (with a beyond the maximum count switch off between readings.
normally-high back) slightly in permissible occurs, the counter
the signal path. With the Send is reset and recorded data now
button pressed, position the overwrites that previously COMMENTS
chair until its distance is disp- recorded at the same ensuing
layed rather than the wall's. Of likely interest to PIC
addresses. programming readers is the way
Now press Mask while still
holding Send pressed. in which the ultrasonic
transmitter (TX1) is driven in
When the masking distance DATA RECALL push-pull mode by Port A pins
is equivalent to that just beyond Data recall occurs when the RA0 and RA1 (see Listing 1).
the chair back, the chair echo Recall button is pressed. A
should cease and the wall value In the general initialization
separate counter is used for this routine at the start of the
become that displayed. The routine, incrementing each time
mask can be used on any program, Port A is set with
Recall is pressed. Again, when these two pins as outputs, and
occasion that foreground items roll-over beyond the maximum
interfere with the desired target with RA2 to RA4 as inputs.
count occurs, the counter is Port A is then cleared.
reading, as long as a good reset. Note that the record
strength of signal still reaches displayed is not normally that On entry into the
the target. which has just been recorded. transmission routine (at label
In normal use, without To view the latest record, the TXIT), a loop value is set at ten,
foreground echoes and with the recall counter number has to a 2-byte counter is cleared, and
bias below about 0⋅4V, keep the match the stored counter RA0 is set high, so setting one
mask value at zero. With higher number. side of TX1 high. There is then
bias levels on transistor TR1, it a pause as set by eight NOP
In a practical situation both (no operation) commands.
is likely to be preferable to counters should be set to zero
normally use the mask value set prior to taking a series of Then the command COMF
to one. (In normal use of the measurements (see “EEPROM PORTA,F is given. This inverts
Extended version, the minimum Reset'' earlier). (complements) the value on
mask value is automatically set Port A from binary 00001 to
to one.) It is suggested that you binary 11110 (Port A only has
experiment to find the best bias PERMANENCE five usable pins). Pin RA0 is
level that suits your own thus set low and RA1 set high,
assembly. Recorded data remains in an action which reverses the
the PIC's EEPROM data
Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 11
Maxfield & Montrose Interactive Inc
current flow through TX1. The in it the 2-byte timing counter is integer 102) to obtain an inches
other three pins (RA2 to RA4) repeatedly incremented until a value. This, in turn, is converted
are of no interest since they are change in the status of Port B to feet with the remainder in
set as inputs. pin RB7 is detected (from high inches. Both are decimalised
A further delay now occurs, to low), at which point the and displayed on the LCD.
of 12 NOP commands, after count stops.
which COMF PORTA,F is again
given, returning Port A to the EXTENDED
first value, 00001. The loop DISTANCE PROGRAM VERSION
value is decremented and if it is CALCULATION The original program for
not yet zero, the routine jumps Sound travels through air at a this PIC Tape measure was
back to the first of the eight called TAPE99, but several
rate of 331⋅4 meters per second
NOPs (at label BEAMIT) and months elapsed between
(at standard temperature and
the process is repeated.
pressure − s.t.p.), so say the text designing the project and writing
At the end of the loop, books. In other conditions its this text.
transmission ceases and Port A velocity varies accordingly. Over During the writing of this
is cleared. Consequently, 10 short distances, though, such article, the author decided that
pulses are transmitted and the changes are negligible as far as the addition of fine “tuning”
time taken to transmit them is this unit is concerned. Conseq- options would be beneficial,
equivalent to a frequency uently, they are ignored (making allowing minor corrections to be
of 40kHz. this a far simpler and cheaper made to the values used for
The transmission routine is device to design and build). calculating distance and the
shown in abridged form in The speed of sound is thus masking offset.
Listing 1 (the BSF SAVE,0 taken as a constant − that The following paragraphs
command sets a flag which encountered in the author's discuss how these adjustments
allows the measurement to be workshop during prototyping! are made. The software prog-
recorded if required). Tests and measurements ram to which they refer is coded
revealed that a reception count TAPE100. How to obtain it is
Listing 1 value of 618 represented a target detailed at the end of the article.
distance of 1000mm i.e. one
TXIT: MOVLW 10 meter (the value is adjustable in
MOVWF LOOPB
CLRF COUNT0 the Extended version). Dividing TIMING
CLRF COUNT1 1000 by 618 equals 1⋅6181229, ADJUSTMENTS
BSF PORTA,0 and so it seemed reasonable to
BSF SAVE,0 multiply the count value by 1⋅618 In most instances, it is unlik-
BEAMIT: NOP (by 8) ely that any further adjustment
COMF PORTA,F to convert it into a meters value.
NOP (by 12)
to the default timing values will
Two bytes are used to be necessary, and will only be
COMF PORTA,F represent 1⋅618 as a binary
DECFSZ LOOPB,F minor if they are needed. The
GOTO BEAMIT value, the MSB holds the value of first stage of alignment, though,
CLRF PORTA 1 and the LSB holds a value of must always be carried out on a
CALL RECEIVE 158 (256 × 0⋅618 = integer 158). newly assembled unit.
An additive technique is then
used to divide the count by this
Whilst there may appear to binary value. Stage 1
be a significant imbalance in the
mark-space ratio of the output The answer is decimalised When the LCD contrast
pulses, the presence of other and output to the LCD as a has been set and the opening
commands in the loop evens meters reading. (Although the message is clearly seen (as
out the timing. Do not change answer is to three decimal places, described in “First Tests”
the commands in this loop — the accuracy is realistically only section earlier), switch off.
to do so would upset the within a centimeter or so.) With Recall pressed, switch
40kHz frequency and the The binary meters value is on again and then release
duration of transmission. also divided by the binary Recall. At the top right of the
The RECEIVE routine is too representation of 25⋅4 (MSB 25, opening message, “BOX” will be
lengthy to reproduce here, but LSB 102 − because 256 × 0⋅4 = replaced by “CLR.” This action

Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 12
Maxfield & Montrose Interactive Inc
clears the entire contents of the Stage 3 EEPROM during the process and
EEPROM data memory and will be those used for future
With Mask pressed, switch
places the timing default LSB measurements. You may change
on again and release Mask. The
values into the final two bytes. them at a later date if you wish to,
LCD screen will change from
The default values are 158 using the same techniques.
the opening message to the
for Basic timing at EEPROM distance display with the top line
byte 62, and 234 for Mask showing “TEST234” preceded
timing at EEPROM byte 63.
SWITCHES SUMMARY
by a flashing “M''. In this mode
the ultrasonic pulses are again In summary, during the
repeatedly transmitted and the alignment procedures the
Stage 2 target distance displayed. The switches have the following roles:
The bias on TR1 must be Mask value, though, is Switch pressed while
about 0⋅3V for the second stage automatically set to one. switching on:
of alignment, to minimize the Adjust the bias on transistor • Send − Basic correction
echo sensitivity.
TR1 to about 5⋅5V, giving mode
Switch off, and with the greater echo sensitivity.The
Send button pressed, switch on • Store − EEPROM
value of 234 can now be
again and release Send. The measurement clear (timing
changed upwards or downwards
screen will change from the factors untouched)
by pressing the Store or Recall
opening message to the buttons, respectively. The rate • Mask − Mask correction
distance display with the top line of change is still about one digit mode
showing “TEST158” preceded per second. • Recall − Clear entire
by a flashing “S”. In this mode EEPROM data and set
Place the unit a few meters
the ultrasonic pulses are default timing factors
away from a wall, without
repeatedly transmitted and the
intervening furniture in the way. While in Basic and Mask
target distance displayed. Mask
is automatically set to correction modes:
a value of zero. • Store increases displayed
The value of 158 timing value
can now be changed • Recall decreases displayed
upwards or down- timing value
wards by pressing the
Store or Recall
buttons respectively. SOFTWARE SOURCING
The rate of change is The source code text files
about one digit per (.ASM) show all the routines, with
second. comments where appropriate.
They were written in TASM.
Place the unit Typical screen display during normal
The files for TAPE99
facing a wall at exactly measurement mode. (Standard program) and
one meter distance from TAPE100 (Extended program)
the front of the transducers. are available for free download
Press Store or Recall until the Note the distance reading. Now
repeatedly press Mask and note from the EPE Online Web Site at
displayed meters reading shows www.epemag.com
1000 meters. Store increases the reading at each mask sett-
the LSB value and the distance ing. If the Mask alignment value The pre-programmed PIC,
shown; Recall decreases them. is correct, the readings should available from Magenta
The change of the distance be just about identical. If nec- Electronics, contains the
value is much slower than that essary, use Store or Recall to TAPE100 program.
of the LSB. change the value accordingly. For more information about
The Basic timing is now set. That completes the obtaining the software and pre-
Switch off. alignment. The new values are programmed chip, also see the
automatically stored in the Shop Talk page in this issue.

Copyright © 1998 Wimborne Publishing Ltd and EPE Online, November 1998 - www.epemag.com - 13
Maxfield & Montrose Interactive Inc

You might also like