Vous êtes sur la page 1sur 10

Copyright 2008, Wimborne Publishing Ltd

(Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK)
and TechBites Interactive Inc.,
(PO Box 857, Madison, Alabama 35758, USA)

All rights reserved.














Visual signal monitoring with frills! www.epemag.com, Ed.)

He had already designed
and published a similar purpose
It is astonishing what audio, but frequencies well to unit based on multiplexed LED
opportunities are continuing to be either side of this range can be (light emitting diode) displays. In
revealed for the recently traced. that unit (PE June 92), an
introduced PIC16F87x series of Several ranges of control LM3914 bargraph IC was used

microcontrollers. This Micro- are offered by switch selection, in conjunction with shift registers
PICscope is a prime example of a covering the sampling rate, and and digital multiplexers to
design idea whose synchronization on/off for the portray a waveform across four
implementation was greatly scope display. The signal input 5 x 7 bit matrixed LEDs. It was

simplified by using one of these is switchable to provide different very effective, although
devices. maximum peak voltage
ag somewhat power hungry.
The Micro-PICscope is a monitoring ranges. Selection of At the time though,
handy little item of test gear and AC or DC input is provided. microcontrollers were an
of benefit to anyones workshop. The entire design requires unknown to the author and a
Using an alphanumeric liquid only two ICs, a PIC micro and method by which an LCD screen
crystal display (LCD), it is an opamp, plus a 2-line by 16- could be similarly used eluded
basically a signal tracer, but one character LCD. An optional third

him. Whereas LED matrices

with the great advantage that it IC provides power regulation if require only logic control,
shows a representation of the required. alphanumeric displays require a
signal waveform that is being variety of data commands to be

A typical example of the

traced. This is shown across eight LCD screen display is shown provided under program control.
of the LCD character cells and is below. For some simple operations

a real-time trace of the monitored LCD commands can be

waveform. generated using codes pre-

Not only that, the display also programmed into an EPROM

shows the frequency of the signal Some 12 or more years (electrically programmable read

being monitored, and its peak-to-ago, when the author first only memory). This technique
peak voltage. The frequency became familiar with intelligent had already been successfully
range covered is basically for alphanumeric LCDs, it became used by the author in a real-time
apparent that by Morse Code Decoder (EE Jan
using the internal 87), but did not lend itself to
programmable circuit board signal tracing and
character generator, monitoring.
their screens might The introduction of the
be capable of versatile PIC16x84
displaying a simple microcontroller re-sparked
representation of a interest in the idea, and it could
signal being have been done using that PIC
monitored. (There is with a separate analogue-to-
a GREAT article on digital converter (ADC). Then
these displays in the along comes the PIC16F87x
Example of the screen display obtainable EPE Online Library family with built-in ADC. Bingo,
on the LCD module. at the idea was now as good as

Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 263
Maxfield & Montrose Interactive Inc
Constructional Project
constructed to full workshop
working order as a single chip
design apart from writing the
command program, of course!

In fact, as you will see from
the complete circuit diagram for
the Micro-PICscope in Fig.1, the
practical implementation of the
idea has been expanded a bit to
use more than just a
microcontroller (IC2). A buffering
and gain setting opamp (IC1a) Completed Micro-PICscope showing
has been included as well. So general layout of display and controls.
too has a 5V regulator (IC3),

gain can be selected by switch 1/10.
allowing the unit to be powered S1 to be x1 (unity via R2) or
from 9V or 12V supplies. If you Switch S2 provides selection
x10 (via R1). Other gain-setting of AC or DC signal coupling,
have an existing well-stabilized values could be chosen instead.
5V supply, IC3 may be omitted. switching capacitor C1 in and out

For example, a 10kW resistor of circuit. The output from IC1 to
The signal being monitored could be used for R3 instead of the microcontroller is DC coupled.
is brought into opamp IC1a. As a 100kW. This would provide
ag You will spot that the opamp is
set by resistors R1 to R3, the switchable gains of unity and
COM 100n
6 2
*+IC1b 7 +VE

N.C. 7
AC/DC N.C. 8
X10 TB1 9
S1 *R2
10 *R3
20 +VE 10

2 21 D4 11
X1 3 22 D5 12 X2
*IC1 MAX492 4
23 D6 13 MODULE

*+IC1a 1
24 D7 14
6 25 RS 4
4 R4 RB4 RS

7 26 E 6
27 5
28 0V GND CX

C3 IC2 1 3
PIC16F876-20P * 11
5MHz 13
S6 ON/OFF 10 15
10k 16
D1 R6
1N4148 1k 17
a k S5 FREQ
C6 C5 C2
9V 22 22 8 19
R7 VR1
10k 10k



Fig.1. Complete circuit diagram for the Micro-PICscope. The voltage regulator IC3
is optional see text.
Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 264
Maxfield & Montrose Interactive Inc
Constructional Project
used in inversion configuration. when the input to RA0 is at the all his future PIC designs to use
Software ensures that the signal positive supply line level of 5V. A this same pin configuration for
is seen the right way up! result of zero occurs when the LCD and programming
A MAX492 dual opamp is RA0 input is at 0V. connections.)
used for IC1, with the second Output to the LCD (X2) is via
half ignored. This device is part PORTB, using lines RB0 to RB5 CONSTRUCTION
of the authors stock library to control the display in
and has proved itself for its conventional 4-bit mode. Details of the PCB
nearly rail-to-rail output swing. Connections to the LCD are via component and track layouts
The circuit has also been used the terminal pin block TB1. The are shown in Fig.2. This board is
with a TL082 device, which order of the pins, both physically available from the EPE Online
provides good frequency range, on the printed circuit board (PCB) Store (code 7000259) at
although does not offer full rail- and in terms of program control, www.epemag.com
to-rail output (typically more like is identical to that used by the Regular readers will know
4V swing for a 5V split supply as author in many of his recently this authors preferred
used here split by resistors R4 published designs. Display constructional order: wire links,
and R5). contrast of the LCD screen is set

resistors, diodes, small
by preset VR1. capacitors, IC sockets and then
on upwards in order of
MICROCONTROLLER component size.

Microcontroller IC2 is a Dual-in-line sockets should
PIC16F876 device, operated at External control of the PICs be used for IC1 and IC2. Note
a clock rate of 5MHz, as set by monitoring and timing functions is
ag that microcontroller IC2 is the
crystal X1. Because of this clock actioned via PORTC, through pins narrow version (03in width
rate, the 20MHz version of the RC0 to RC2. The functions
between pin rows, as opposed
PIC should be used. The controlled are the ADC sampling
to 06in).
standard version has a rate (via S3), waveform
maximum guaranteed clock rate synchronization on/off (S4), and Details of the switch and

limit of 4MHz. However, you frequency counter display on/off signal input connections are also
may find it interesting to note (S5). These will be discussed shown in Fig.2. Socket SK1 may
that the author has successfully later. be a different type to that shown
used the 4MHz version at rates if preferred.

Pins RB6 and RB7, whilst not

well in excess of 5MHz. actively used by the design itself, The LCD module might
The PIC16F87x family has can be used to program the PIC have one of two possible pin

been discussed at length in via a suitable programmer, such connection arrangements. They
previous issues of EPE and the as PIC Toolkit Mk2 (May-June are shown in Fig.3.

876 will not be described in 99). The MCLR pin (master reset) As always, do a thorough
detail here. Suffice to say that it is normally powered at 43V (5V check of the component

has three input/output (I/O) 07V) via diode D1 and buffering positioning, orientation and
ports, one of which, PORTA, resistor R6. This allows solder joint integrity before
can be used for analog-to-digital programming voltage control applying power. Do not insert
conversion via five of its pins without disturbing the normal 5V IC1, IC2 or the LCD until the
(RA0 to RA3, plus RA5). In this supply rail from voltage regulator output from regulator IC3 has
design, only RA0 (pin 2) is used, IC3. been validated, exactly 5V
its input being taken directly (within a few millivolts) for a
Terminal pin block TB2
from the output of opamp IC1a supply between 7V and 12V.
provides access to MCLR, RB6,
at pin 1.
RB7 and the 0V common line. An output voltage from IC3
Internally, the PIC is The pin order on the PCB is the other than 5V will usually
programmed by the software so also same as that used by the indicate a fault in construction
that the voltage reference for the author in previous designs. This too high and IC3 is wrongly
ADC is taken as 0V to 5V (the will be welcomed by those who inserted, too low and there may
power line voltage range). have established a plug-in link be a short circuit somewhere on
Consequently, an A-D between Toolkit Mk2 and such the board.
conversion value of 255 results designs! (The author intends for
Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 265
Maxfield & Montrose Interactive Inc
Constructional Project
When happy about the
power supply, test the circuit
with IC1, IC2 and the LCD DATA RB7
plugged in (correctly!). Set CLK RB6
switch S4 (Sync) off and S5 TB1
(Frequency) on. When power is CX
+ VE
applied, the PIC first goes into 0V

an LCD initialization routine, in AC/DC C1 R3
which it sets the LCD for 2-line 6
4-bit mode. 1 2
X10 D7
Following this, text D1
S1 a
messages similar to those in the R4 D5
R5 D4
photographs should appear. The

signal trace display in the top left C2 C4 X1
LCD character cells should SK1 C6
+ C 7
5 IN
show as a straight line about 0V IC3 OUT

half way up the screen. Adjust S1 C7

preset VR1 to set the screen +9V

contrast (you may see nothing at ON/OFF S6
all until you have adjusted it).

Having read the sections all
about the control program, you ag
can then feed in an audio signal,
play with the switches, and see S3
the results on screen. The input
signal amplitude should be S5 S4
selected so that the majority of
the LCD vertical pixel range is



A small plastic box was

used to house the prototype.

The PCB has been designed so

that the LCD can be mounted

above it using stand-off pillars,

although the prototype did not

use this option.

The rectangular viewing slot
was cut by first drilling small
perimeter holes and using a file
to smooth the edges to shape
and size. Holes must also be
drilled to suit the switches and
input socket. The prototype
used a 35mm jack socket for
the power input, but other
techniques, such as a battery
connector, can be used.

Fig.2. Printed circuit board component layout, wiring to the

A-TO-D off-board components and (approximately) full-size copper
CONVERSION foil master for the Micro-PICscope.

Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 266
Maxfield & Montrose Interactive Inc
Constructional Project
not quite instantaneous and the Normally, the LCD module
program repeatedly polls the GO places pre-programmed (as part
bit until it goes low, signifying an of the modules control chip
end to the conversion process. manufacturing process)
There are several subroutines alphanumeric data into these
which are used in the program cells according to command
to perform this task, one of them codes from an external source,
being: a PIC in this case.
WAITS1: BTFSC However, the module has
ADCON0,GO the facility to allow eight
characters to be designed by
GOTO WAITS1 the user and called as well as
MOVF ADRESH,W the standard alphanumeric set.
These characters are stored at
When the GO bit is clear,
module address locations 0 to 7.
Fig.3. Pinout arrangement of the command MOVF
ADRESH,W retrieves the high At first sight, when
the two basic LCD formats.

byte of the 2-byte conversion examining the LCD data sheet,
Basic A-to-D conversion result. Because the display is it might appear that address
using a PIC was discussed in only eight pixels high, the low locations 8 to 15 can also be
the Mini PIC16F87x Tutorial of byte is not needed (see the Mini used to hold custom characters

Oct 99. A simplified version of Tutorial, or the PIC16F87x data as well. Regrettably for an
the routine described there is book, for details of the application such as this
used here:
conversion result format
PICscope, addresses 8 to 15
only hold repeats of the data at
In the START routine while addresses 0 to 7. Thus only
in PAGE1, register ADCON1 is The value held in ADRESH eight addresses can be used for
set with the binary value of (and now also in W) is that alternative character data,
%00000101, which tells the PIC which represents the voltage hence the PICscope only having

that the 2-byte ADC register is to level of the signal being eight cells for waveform display.
be justified left, with RA0 as an sampled. It cannot yet, however,
analog input referenced to +VE be put out to the LCD screen, Eight cells each having five
and 0V. theres a great deal of work to pixels horizontally allows 40

be done first! For the moment, waveform samples to have their

Then, back in PAGE0, by values plotted at eight vertical
loading register ADCON0 with a this value is simply stored in one

of a set of temporary memory pixel levels.

binary value of %010000001,
ADC conversion is activated at locations. The conversion and The reason that 128

an oscillator rate of one-eighth storage is performed 128 times samples are taken even though
of the clock rate (Fosc/8). before further action is needed. only 40 will be displayed from

each block is to allow for

(Readers who write their frequency and amplitude values
own PIC software should note DISPLAY PRINCIPLE to be more readily established.
that in order for PAGE Before that further action
commands to be used with the is described, it is first necessary
Toolkit programmer and the to understand the concept CHARACTER
PIC16F87x family, bit RP1 of the
PICs STATUS register must be
behind the way in which a GENERATOR
waveform can be displayed on
set to 0 as it is in the START The way in which data for a
the LCD by making use of its
routine of the Micro-PICscope character cell is evaluated is
character generator.
source code.) illustrated in Fig.4b. Each of the
You already know that the seven rows making up the cell
A single ADC sample is LCD used here has two display display are treated individually.
taken when the command BSF lines each having 16 character The five pixels of each row are
ADCON,GO is issued, where cells. Each of these 32 cells numbered from 4 to 0, allowing
the quaint GO term (Microchips consists of a matrix of LCD a 5-bit binary number to be
description!) refers to bit 2. pixels, arranged as five across compiled. Logic 1 in a bit
Sampling and conversion are by eight down (see Fig.4a).

Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 267
Maxfield & Montrose Interactive Inc
Constructional Project
position turns on the equivalent
pixel, while logic 0 turns it off. COMPONENTS
Having established which Resistors Miscellaneous
bits are to be active, the 5-bit R1, R4, R5, R7 10k (4 off) S1, S2, S4, S5 miniature s.p.d.t.
binary number for each row R2, R3 100k (2 off) toggle switches (4 off)
R6 1k S3 miniature push-to-make switch
(expanded to 8-bit with zero in All 0.25W 5% carbon film S6 miniature s.p.s.t. (or s.p.d.t.)
bits 7 to 5) is sent to the toggle switch
required character generator Potentiometer SK1 BNC socket (see text)
address, of between 0 and 7. VR1 10k miniature round preset X1 5MHz crystal
The same procedure can be X2 2 line x 16 characters per line
used for the other seven alphanumeric crystal display
C1 radial electrolytic, 16V
possible addresses, each of C2, C6 22u radial electrolytic,
Printed circuit board available from
them storing different data, as 25V (2 off)
the EPE Online Store (code 7000259)
appropriate. C3, C4 10p ceramic, 5mm pin
www.epemag.com; powere supply
spacing (2 off)
connector (see text); plastic case,
When character data is C5, C7 100n ceramic, 5mm pin
150mm x 80mm x 50mm; 8-pin DIL
being generated in this way, the spacing (2 off)
socket; 28-pin DIL socket; 1mm

LCD is first told that the data Semiconductors terminal
about to arrive is destined for D1 1N4148 signal diode pins (or strips) for TB1 and TB2; PCB
the character generator rather IC1 MAX492 dual opamp and LCD supports (8 off); connecting
IC2 PIC16F876-20P microcontroller wire; cable ties; solder, etc.
than for the screen display. In

(20MHz version, 0.3-inch width)
the program the initial command preprogrammed See also the
is given by: IC3 78L05 +5V 100mA voltage
ag SHOP TALK Page!
regulator (see text)
MOVLW %01000000
Approx. Cost
Guidance Only $31
which sets the character designed data is to be stored, LCD. The LCDLIN call is to one
the address incrementing each of several standard routines,

generator to address 0 from

which address onwards the time a data byte is written to the which the author wrote some
years ago to send various
commands and data to an LCD

For all eight character cells

to be fully programmed, 8 x 8 =
64 bytes of data are written to

the character generator.

Once the character

generator has been

programmed, the data held at
each of the eight address blocks
can be called to the screen by
simply accessing that address in
the same way that normal
alphanumeric data is accessed.
For example, to display
letter A on screen you might
use either MOVLW A, CALL
LCDOUT, the value of 65 being
the ASCII value for capital letter
A. In both cases the character
held at character generator
Completed unit showing the LCD module mounted on the lid of address decimal 65 would be
the case and wiring to the PCB. displayed on screen, which,
Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 268
Maxfield & Montrose Interactive Inc
Constructional Project

FIg.3(a). LCD character cell matrix with all

pixels on, (b) example of waveform represen-
fortunately for us all is indeed tation across two character cells.
the letter A.
Similarly, to show the a continuous line as possible. PIC (or buy a ready-
programmed PIC see later).

character newly programmed For instance, suppose the
into address 3, the commands waveform is alternating rapidly Although there is a great
would be MOVLW 3, CALL between high and low levels at a deal of processing being carried
LCDOUT. rate faster than the sampling out, each batch of sampled data
can keep pace with. Without is displayed in rapid succession

The data held at character
corrective action, you might only and really does give a real-
generator addresses 0 to 7 can
see pixels on the upper and
ag time display of what is
be changed as often as
lower lines, those between happening in a monitored circuit.
required. In this design it is
remaining blank.
typically changed about twice
per second (faster with S4 and The corrective action fills in FREQUENCY AND
S5 off). All data at these those blank pixels so that they
addresses is lost when power is AMPLITUDE

switched off. Each batch of data is also

analyzed for waveform
frequency and peak-to-peak

amplitude values.
CHARACTERS Amplitude is easily

When a full block of determined by simply looking for

samples has been converted the maximum and minimum

and stored, the data is then conversion values and then

analyzed for amplitude and relating them to the maximum
Close-up of typical screen dis-

compiled into 64 bytes for possible sample level of 255.

sending to the character play. There are three rates, The latter, as said earlier,
generator. Row 8 is the top row the maximum counting fre- represents the positive line level,
and (naturally) represents the quency is about 17kHz. which has been assumed to be
highest voltage range that can exactly 5V. If you need greater
be displayed. The display is, of appear as though they naturally accuracy for signal level
course, compressed to one- follow on from each other. This voltages use your multimeter to
eighth of the conversion value was an extremely difficult read them! The PICscope is
received. process to write the program for! only intended for providing an
Even experienced programmers approximate value (but its still
The analysis procedure is
might have difficulty analyzing pretty accurate).
far more complex than can be
described here. It is not just a the way in which the source Note that the PIC does not
matter of ascertaining which row code has been written be monitor which gain setting has
a value should be allocated to. warned! been selected. It simply reports
The result also has to be However, you dont need to the voltage it finds on its RA0
doctored so that the active understand the program in order pin. You must mentally adjust
pixels are seen to be as close to to use it. Just load it into your the value shown if the gain is

Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 269
Maxfield & Montrose Interactive Inc
Constructional Project
other than unity.
Frequency is assessed by
counting the number of times
the voltage level crosses a
preset threshold value. The
result is then divided by two to
obtain the equivalent number of
cycles per batch, the rate of data
acquisition being pre-
determined by the sampling
rate, which in turn is relative to
the master clock rate.
Much effort went into writing
the software so that relative
timings were maintained
consistently, irrespective of

conditional branch timings in the
sampling routines.
There are three rates at
Completed circuit board mounted on self-adhesive
which the ADC can be set to plastic stand-off pillars.

sample waveforms, selectable readily calculated (friend and Most and Least Significant
by pressing switch S3. The rates EPE author Andy Flind has
ag Bytes, respectively.)
cycle as a repeating group of researched heavily into this we
three, numbered from 0 to 2. During prototype testing, the
hope hell one day share it with unit was fed with a frequency of
The number of the selected rate us all!). 4000Hz and the fraction values
is shown at the top right of the
screen. It is not a representation The solution here was to repeatedly adjusted by trial and
of the frequency range covered. count the swings above and error until the LCD also showed

below the threshold level and a value of 4000Hz.

The rates are set according then divide the answer by a
to the value by which the master Having established the
conversion factor, with a values for the three ranges, the
clock oscillator is divided via the

separate factor for each of the input frequency was raised to

ADCON0 prescaler. This value three sampling rates.
is set by bits 6 and 7 in the see how far accuracy was

ADCON0 register. Rate 0 sets Using a subtractive maintained, the results were:
Fosc/2, rate 1 sets Fosc/8, rate technique, the conversion
Rate Generator Display

2 sets Fosc/32. The routine involves fractions, which are

which reads S3 and sets the bits fixed in the software as two-byte 0 17007Hz 16984Hz

commences at label TESTIT, binary numbers. 1 17007Hz 16998Hz

following on into GETRATE, For example, for Rate 0, the 2 5827Hz 5812Hz
near the end of the source code MSB is set at decimal 85 and
listing. the LSB at 70, which has an Beyond those frequencies,
equivalent decimal value of the unit began to display
21830 (256 x 85 + 70). From harmonic frequency values
FREQUENCY this value is repeatedly because the generator rate
exceeded the rate at which the
CALCULATION subtracted the count value
waveform could be sampled.
determined when counting the
Relating the ADCON0 swing changes, each successful The values programmed
sample rate to the actual subtraction incrementing a into the unit depend, of course,
frequency of the signal has to counter. Thus the cycle count is on the exact frequency at which
take into account the time taken divided into the conversion the crystal controlled oscillator
for all the commands in the factor, the secondary counter functions. However, crystal
sampling routine to be providing the answer. The result controlled oscillators, while not
performed. As experienced is remarkably accurate. (MSB being perfectly tuned to a given
programmers will acknowledge, and LSB, incidentally, mean frequency, do stick closely to it.
such matters are not always
Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 270
Maxfield & Montrose Interactive Inc
Constructional Project
Consequently, other units a repetitive waveform. of LCD graphics displays comes
should achieve results that are Inevitably, the process increases down greatly!
not too different from the the wait period before each new What is in the pipeline,
authors. display is shown. There is a however, is the Virtual PICscope
Those who which to time-out counter, which prevents in which one of the PIC16F87x
experiment are referred to the the system from locking-up family is used to sample two
sub-routines at GETFREQ0, should the waveform not cross waveforms simultaneously and
GETFREQ1 and GETFREQ2, the sync thresholds. output the data to a PC
where the preset values can be It is best to start off computer for display on its
changed. The program will sampling any new signal with screen.
naturally need to be re- sync off, only turning it on once Finally, if you have any
assembled and reprogrammed adequate signal levels are being ideas for PIC-based workshop
into the PIC. received. The source routines, designs (or any other type of
Analysis of the peak-to-peak which control sync start at label design, of any sort), please let
and frequency values can be WAITS1. The full batch us know.
switched off using S5. This sampling routine commences at

speeds up the rate at which the WAITAD0.
screen is fed with a fresh
waveform display. IN THE PIPELINE

That, in a nutshell, is really
SYNCHRONISATION all there is to tell about this
Switch S4 turns the astonishingly simple signal
waveform synchronization monitor (simple in hardware
facility on and off. When terms but certainly not
regarding software writing!).
synchronization is on, before
each sampling batch is started Designing it has fulfilled one of
the software waits until the the authors ambitions. Software

waveform voltage has twice is in TASM.

passed through a preset trigger Another yet to be fulfilled is
level. Only then does it start to design a more advanced LCD

sampling the rest of that batch. based scope, which will give far
This facility allows the greater resolution to the

waveform display to start about waveform shapes displayed.

half-way up the screen, Such a design, though will have
to wait until the exorbitant cost

providing a degree of stability to


Copyright 2000 Wimborne Publishing Ltd and EPE Online, April 2000 - www.epemag.com - 271
Maxfield & Montrose Interactive Inc