0700 - PIC-Gen Frequency Generator
0700 - PIC-Gen Frequency Generator
(Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK)
and TechBites Interactive Inc.,
(PO Box 857, Madison, Alabama 35758, USA)
The materials and works contained within EPE Online — which are made available by
Wimborne Publishing Ltd and TechBites Interactive Inc — are copyrighted.
TechBites Interactive Inc and Wimborne Publishing Ltd have used their best efforts in preparing these materials and works. However, TechBites
Interactive Inc and Wimborne Publishing Ltd make no warranties of any kind, expressed or implied, with regard to the documentation or data
contained herein, and specifically disclaim, without limitation, any implied warranties of merchantability and fitness for a particular purpose.
Because of possible variances in the quality and condition of materials and workmanship used by readers, EPE Online, its publishers and agents
disclaim any responsibility for the safe and proper functioning of reader‐constructed projects based on or from information published in these
materials and works.
om
In no event shall TechBites Interactive Inc or Wimborne Publishing Ltd be responsible or liable for any loss of profit or any other commercial
damages, including but not limited to special, incidental, consequential, or any other damages in connection with or arising out of furnishing,
performance, or use of these materials and works.
.c
READERS’ TECHNICAL ENQUIRIES
ag
We are unable to offer any advice on the use, purchase, repair or modification of commercial equipment or the incorporation
or modification of designs published in the magazine. We regret that we cannot provide data or answer queries on articles or
projects that are more than five years’ old. We are not able to answer technical queries on the phone.
m
PROJECTS AND CIRCUITS
pe
All reasonable precautions are taken to ensure that the advice and data given to readers is reliable. We cannot, however,
guarantee it and we cannot accept legal responsibility for it. A number of projects and circuits published in EPE employ voltages
.e
that can be lethal. You should not build, test, modify or renovate any item of mains‐powered equipment unless you fully
understand the safety aspects involved and you use an RCD adaptor.
w
COMPONENT SUPPLIES
w
We do not supply electronic components or kits for building the projects featured; these can be supplied by advertisers in our
publication Practical Everyday Electronics. Our web site is located at www.epemag.com
w
We advise readers to check that all parts are still available before commencing any project.
To order you copy for only $18.95 for 12 issues go to www.epemag.com
PIC-GEN FREQUENCY GENERATOR/
COUNTER by JOHN BECKER
Add even more versatility to your workshop facilities. Prior to the introduction of
the MAX038, arguably the main
contender for the most widely
Combining the sophisticated The PIC is also used as a used function generator was the
features of a Maxim MAX038 frequency counter, switch 8038, manufactured by various
waveform generator and a selectable to monitor the companies under different prefix
PIC16F877 microcontroller has frequency generated by the codings, such as ICL8038 and
om
resulted in a highly versatile and MAX038, or from an external XR8038, for instance.
inexpensive workshop tool whose source in conjunction with a pre- The 8038 is still widely used
facilities have hitherto been conditioning waveform shaper but it has limitations in the
unattainable without considerable and frequency divider. Two maximum frequency that can be
.c
design complexity. external signal inputs are generated. The range is typically
provided: one for 0V to 5V logic 0××001Hz to 100kHz.
The MAX038 is a high-
frequency precision function
ag
level waveforms, the other for
AC waveforms having a peak- The MAX038, however, is
generator whose output is to-peak swing of between about stated to have an upper
selectable to produce triangle, frequency limit of at least
m
2V to 5V. The prototype can
sine and square waveforms, monitor frequencies in excess of 20MHz, and possibly around
within a wide operating frequency 40MHz. 40MHz. It has to be said,
pe
span of 0××1Hz to over 10MHz, split though, that attaining such high
in the PIC-Gen as eight frequencies requires printed
overlapping frequency ranges. MAX038 FUNCTION circuit board design and
.e
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 518
Maxfield & Montrose Interactive Inc
Constructional Project
specified upper frequency limit Sept/Oct ’96 articles. 10pF will be seen by the MAX038
is achieved when the timing In the PIC-Gen design, the as a value higher than this due to
capacitance is less than or controls used are those that set the (unpredictable) capacitance of
equal to 15pF and the control frequency and waveform shape. the circuit in proximity to the C
current is 500uA. The eight frequency ranges are OSC pin. Capacitor C11 could be
set according to the capacitance omitted if you want to try
Unfortunately, on a PCB
value connected to the device’s increasing the maximum
designed for successful
C OSC pin. Fine tuning of the frequency attainable.
assembly by the average
hobbyist, the capacitance frequency is performed by Pushbutton switches S1 and
between the MAX038, other varying the current provided by S2 cause the PIC to step the
components and the tracks is potentiometer VR1 to the I IN frequency range down or up
likely to prevent the maximum pin. (respectively) on a continuous 8-
frequency from being reached. Resistor R2 limits the step loop.
The prototype PIC-Gen maximum current that can flow, Nominally, the capacitor
described here achieves a while R1 sets the minimum values have been chosen to
maximum of just over 10MHz. current. provide a factor of ten difference
om
between each step. Normal
manufacturing tolerances apply to
PIC-GEN CONCEPT FREQUENCY these values, especially with the
Considering how the SELECTION electrolytic capacitors.
.c
MAX038 might be put under Potentiometer VR1 provides a
semi-automatic control as part Eight capacitors are used to
set the frequency ranges, C11 to frequency control range of about 1
of a frequency generator and ag to 50. For example, if the
counter system, the author C18. These are commonly
connected at one end to the C minimum current flow through
recognized that a PIC16F877 VR1 and R2 causes a frequency
microcontroller might provide OSC pin (5). Capacitors C12 to
of 1kHz, then maximum current
m
the key. This device has five C18 have their other ends
connected individually to port flow will cause 50kHz to be
input-output ports which, it generated. The range may be
pins of the PIC microcontroller,
pe
0V line.
crystal display. WAVEFORM
Normally, the above seven
Doing a basic mock-up on SELECTION
w
the bare essentials proved the effectively held in an open-circuit three waveform shapes, Sine,
viability of the idea. The concept state, the PIC inputs having a Triangle and Square.
was then given full flesh and very high impedance. As such, Selection is made according
bones to become the design the MAX038 ignores those to the binary code placed on the
whose circuit diagram is given in capacitors. MAX038’s A0 and A1 inputs. The
Fig.1. To bring one of the seven code is controlled by the PIC, via
The MAX038 function port controlled capacitors into its RB6 and RB7 pins, as follows:
generator is shown as IC2. It will circuit, the PIC has the
appropriate pin set as an output A1 A0 WAVEFORM
be seen that half the pins are 0 0 Square
grounded and from some of held at logic 0 (0V). With a
higher capacitance value 0 1 Triangle
their notations it will probably be 1 x Sine
(correctly) deduced that the selected, so the lower the output
device has more functions than frequency from IC2. where x = don’t care
are used here. For information For the highest frequency Pushbutton switch S4 causes
about the device’s full range of range, capacitor C11 is the the PIC to step through the three
functions, see its data sheet controlling component. Note, waveform codes on a repeating
(details later) or Andy Flind’s though, that its nominal value of
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 519
Maxfield & Montrose Interactive Inc
Constructional Project
Note that IC6’s Q12 output
is the final one in its counting
sequence. This changes state at
1/4096 of the input frequency
and even at high input rates the
PIC is able to monitor this pin.
Each time the pin changes
state, the PIC registers the fact
Typical LCD display showing that a square and increments an internal
wave is being generated and that a frequency counter.
count of 3,706,286Hz has been read on range
At regular intervals,
7 during the normal 1-second sampling period. selectable for one or ten
cycle. seconds by switch S3 (Sample
FREQUENCY Time), the full 12-pin sequence
The selected waveform is
output at IC2 pin OUT and has a
COUNTER of IC6’s outputs is read and a
frequency value calculated
fixed amplitude of ±1V, Whilst a PIC can be
according to this value and that
om
symmetrical about 0V. The programmed to act as a
of the internal counter. Once the
output has a very low frequency counter simply by
reading has been taken, the
impedance (typically 0××1W) and monitoring one input pin, the
internal and IC6 counters are
can be used directly via socket maximum frequency that can be
reset (the latter via PIC pin RD4)
.c
SK5. monitored by this method is
prior to the next batch of
severely limited. To enable very
The same waveform is counting.
high frequency signals to be
amplified by the non-inverting
ag
counted by the PIC-Gen, a pre- Frequencies in excess of
opamp circuit around IC3a. The counter is used and the output 40MHz have been recorded on
gain is set at x2, resulting in an from that is monitored at regular, the author’s prototype.
m
output swing of ±2V. Capacitor but slower intervals.
C3 provides DC isolation of the
The pre-counter is IC6, a FREQUENCY INPUT
pe
output. In the prototype, a PCB design, allowing software reading the contents of IC6, the
maximum of about 1MHz is to interpret the input values as PIC sets pin RD5 low, so turning
w
experienced, after which the correct binary numbers. off gate IC7a and preventing
amplitude progressively falls. further input signals from
Other opamps which have
higher frequency capabilities are
available but no
recommendation is offered on
this point.
Readers should be aware
that whilst some opamps may
seem to offer very high
frequency capabilities according
their data sheets, other factors
(also quoted) can affect the
range and must be taken into
account. PIC-Gen front panel. The waveform button is bottom far right.
The switch marked “pulse” (top right) is the on/off switch in the
final model.
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 520
Maxfield & Montrose Interactive Inc
Constructional Project
reaching the counter. This Logic level signals either above or below the 0V/5V
allows the ripple-nature of the (nominally 0V to 5V) are input to range should not be input to
counter to stabilize (ripple the PIC-Gen via socket SK1 socket SK1. Those having
through) at the correct count (Logic Input), switch S5 lesser swings may not trigger
value. Software introduces a selecting their routing to gate gate IC7a, those having swings
slight delay between closing the IC7a and the counter. Signals greater than about 6V could kill
gate and taking the reading. having other voltage ranges, it.
om
.c
ag
m
pe
.e
w
w
w
Fig.1. Full circuit diagram for the PIC-Gen Frequency generator and Counter.
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 521
Maxfield & Montrose Interactive Inc
Constructional Project
Signals which are analog or
digital and have a swing range
less than 5V, but greater than
about 2V to 2××5V, are input via
socket SK2 (AC Input). Switch
S6 selects their routing to the
pre-conditioning circuit around
IC7c. This is another Schmitt
trigger NAND gate, having one This display shows a sine wave is being generated and a
input (pin 13) held biassed at a frequency of 25,124Hz has been registered via range 4.
mid-power line level (2××5V) by
the potential divider formed by instability occurred when this selected (sine, triangle or
resistors R8 and R9. The other was generated (as cautioned in square).
input (pin 12) is held at +5V. Maxim’s data sheet). o) Line 1 mid/right:
Consequently, the option to use frequency value.
The input signal is AC this output has been dropped
coupled via C10 to the biased from the published PIC-Gen o) Line 2 left: frequency
om
input of the gate. Providing the (although the connection tracks range selected (8
input signal’s peak-to-peak on the PCB have been choices).
range is greater than the gate’s retained). o) Line 2 mid/right:
hysteresis value (which varies
sampling range selected
.c
slightly between individual
(2 choices).
devices), so the gate will be 3·2768MHz OUTPUT
triggered. The LCD is shown as X2 in
The output of this gate is
ag
The PIC is run at a
frequency of 3××2768MHz, as set Fig.1. It is under standard 4-bit
also fed to switch S5, which control, but whereas many PIC
by crystal X1. Although this
routes it to the counter via IC7a projects control it via PIC Port B,
m
frequency can be tapped directly
when selected. here it is controlled via Port A
from PIC pin OSC2, it was
(RA0 to RA5). Apart from the
Because the main output deemed better to buffer it via
pe
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 522
Maxfield & Montrose Interactive Inc
Constructional Project
COMPONENTS
Resistors See also the
R1 470 ohms
R2, R4, R5, R7, R10 to R13 10k (8 off) SHOP TALK Page!
R3 10 ohms
R6 1k
R8, R9 100k (2 off)
Potentiometers
VR1 10k panel mounting rotary
or multi-turn linear (see text)
VR2 10k panel mounting rotary lin.
VR3 10k miniature preset, round
Capacitors
C1 to C3, C18 to C24 100u radial
electrolytic, 16V (5 off)
C4, C10 22u radial electrolytic, 10V (2
off)
om
C5, C7, C15, C19 to C23 100n
ceramic disk, 5mm pitch (8 off)
C6, C16 1u radial electrolytic, 10V (2 off)
C8, C9, C11 10p ceramic disk,
5mm pitch (3 off)
.c
C12 100p ceramic disk, 5mm pitch
C13 1n ceramic disk, 5mm pitch ag
C14 10n ceramic disk, 5mm pitch
C17 10u radial electrolytic, 10V
Semiconductors
D1 1N4148 signal diode
m
IC1 MAX660 DC-to-DC converter
IC2 MAX038 function generator
IC3 TL082 dual opamp Completed prototype PCB. Differs
pe
X2 2-line 16-character (per line) LCD module (see text) (and similar) devices, typically
about 100mA as compared with
20mA. ONLY the MAX660
w
PCB available from the EPE Online Store (code 7000268) at www.epemag.com.
knob (2 off); 8-pin DIL socket (2 off); 14-pin DIL socket; 16-pin DIL socket; 20-pin should be used in the PIC-Gen.
DIL socket; 40-pin DIL socket; 1mm pin header strips (see text); 1mm terminal
pins; It had been expected that
2mm socket (7 off, various colors) (or sockets to suit other equipment); plastic the MAX660 could have been
case, powered by the 5V regulated
205mm x 108mm x 57mm; plastic feet for case (4 off); PCB mounting supports
supply from IC4, producing –5V
(4 off); PP3 battery and clip, or socket to suit external power supply (see text);
as a result. However, the first
Approx.
connecting Cost
Guidance Only
wire; cable ties; solder, etc. case, batts)
(Excluding $90 test model of the PIC-Gen
showed significant instability in
within the PIC-Gen circuit at any the frequency generated when
around IC1 and IC8.
other voltages (normal power this method was used.
supply tolerances apply). IC1 is a MAX660 voltage Investigation showed that the
converter, used here to ripple frequency output by the
The 5V supply is also used generate a negative voltage of MAX660 could not be
by the MAX038, but this device the same (inverse) magnitude dampened sufficiently to prevent
additionally requires a supply of as the voltage at which it is it from modulating the MAX038
–5V. A double-staged circuit is powered. In this instance, the 9V frequency output.
used for this purpose, based
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 523
Maxfield & Montrose Interactive Inc
Constructional Project
Consequently, it was found
necessary to first generate –9V
and then to regulate and
stabilize it down to –5V using
IC8, a negative voltage
regulator. Further smoothing is
given by the use of resistor R3
and capacitors C23 and C24.
A small instability remains,
believed to be due to the
MAX066’s square wave
oscillator radiating into other
parts of the circuit (an
oscilloscope probe on a range of
10mV just picks up the signal
when held near to the device).
The instability is principally
om
noticeable at higher MAX038
frequencies.
.c
PROGRAMMING
CONNECTIONS ag
As is customary with the
author’s recent PIC projects, the
PIC device used in this circuit
m
can be programmed in-situ on
the printed circuit board. The
pe
programmer to use.
MISCELLANY
Resistors R10 to R13 are
pull-down resistors to
appropriately bias the respective
PIC input pins when switches S1
to S4 are not pressed. NAND Fig.2. PIC-Gen PCB component layout and (approximately)
gate IC7d has its inputs biassed full-size copper foil master pattern. The numbers at the ends of
to a power line (+5V in this the lead-off wires should terminate at identical points on the
case) as is required for unused front panel (Fig.3).
CMOS gates. Opamp IC3b had
been intended for use as an provided cleaner signal control, count signals having a peak-to-
external analog input amplifier, and at a far higher frequency. peak value less than about 2V,
but it was decided that the they should pre-amplify them
If users need to frequency-
configuration around IC7c first.
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 524
Maxfield & Montrose Interactive Inc
Constructional Project
Fig.3. Layout and wiring to the front panel (full size) mounted components. The inset panels
show wiring to a multiturn pot and suggested wire groupings.
om
Only the HC versions of IC6 of a 74LS132 should allow capacitors are used throughout
and IC7 should be used lesser amplitude external the circuit at strategic points on
(74HC4040 and 74HC132). signals to be input to the the PCB.
These are typically capable of frequency counter, typically
.c
handling signals in excess of having a peak-to-peak swing of
40MHz. The “standard” CMOS about 0××8V, although this has not
ag CONSTRUCTION
4040 counter is far too slow to been tried. Details of the component
be usable in this circuit. The use and track layouts for the PIC-
Numerous smoothing
m
pe
.e
w
w
w
Layout of components and wiring inside the case of the completed prototype PIC-Gen.
There are very minor differences between this and the final wiring diagrams.
Note the various wiring “looms”.
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 525
Maxfield & Montrose Interactive Inc
Constructional Project
Gen PCB are shown in Fig.2.
This board is available from the
EPE Online Store (code
7000268) at www.epemag.com
The author’s preferred
assembly is in order of link wires
(some go under IC positions), IC When the sampling rate change switch is pressed,
sockets, resistors, diode, small the word “counting” is displayed until the first new
capacitors, and remaining count has been completed. In this instance a 10-
components in ascending order
second sampling rate has been selected.
of size. Do not insert the DIL
(dual-in-line) ICs at this stage. Table 1: PIC16F877 configuration bits.
Ensure that all polarized
components are orientated as CP1 CP0 DBG NIL WRT CPD LVP BOR CP1 CP0 POR WDT OS1 OS0
1 1 1 1 1 1 0 0 1 1 0 0 0 1
shown in Fig.2.
Pin-header strips were used
om
for terminal groups TB1 and of signals interacting with each converter IC1 and check that a
TB2. The order of these other through the interwiring, negative voltage equivalent to
connections is identical to that several “harness” groups were the applied power supply is
used in the author’s recent PIC used, keeping potentially present at it’s output (i.e. –9V for
.c
projects. Details of the source interactive signal paths apart as a +9V supply). Check that –5V
for the LCD module complete seemed reasonable. The groups
ag is present at the output of
with matching connector are can be seen in the photograph, regulator IC8 and at the pin 20
given on this month’s Shoptalk and they are itemized by position of the socket for IC2.
page. connection number in the If all is satisfactory, the
second insert of Fig.3.
m
The prototype PIC-Gen is remaining ICs and the LCD can
housed in a plastic case Several cable ties are used be inserted. Only one LCD line
to keep each group separately will be active until the PIC is
pe
(Note that the photographs show the circuit, power should always If not already programmed,
slightly different panel wiring to be switched off before inserting the PIC can have its program
w
control potentiometer is offered. circuit does not behave as programmer, connecting the
The illustration in Fig.3 shows expected, rechecking your programmer via pin header TB2.
the connections for VR1 as a assembly for errors.
The PIC configuration
standard single-turn carbon Assuming that you have (initialization) required is the PIC
rotary potentiometer. The inset thoroughly checked that you Toolkit Mk2 default as shown in
shows the typical connections have not made assembly or Table 1.
for a multiturn (10-turn in the soldering errors, the first check
should be with the LCD and all Once programmed, the PIC
prototype) wirewound
ICs omitted except the two should immediately start running
potentiometer.
regulators IC4 and IC8. and a set of data similar to that
The standard pot is the least previously discussed should be
expensive choice but does not With power applied, check seen. Set switches S5 and S6
allow the same degree of that +5V is present at the output so that the frequency being
frequency setting precision as of IC4 and at strategic points generated by IC2 is being
the more-expensive multiturn around the PCB (referring to monitored. Observe the results
pot. both Fig.1 and Fig.2). when different waveforms,
To minimize the possibility Insert the negative voltage frequency ranges and sampling
rates are selected using
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 526
Maxfield & Montrose Interactive Inc
Constructional Project
switches S1 to S4 and with the and switch S5 to minimize the Data sheets for the MAX038
frequency control potentiometer risk of IC7a becoming and MAX660 can be
VR1 at various settings. distressed by negative-going or downloaded from Maxim’s web
If you have an oscilloscope, over-voltage signals.) site at www.maxim-ic.com
monitor the waveforms output at Once fully checked, the PIC- Data sheets for the
all settings and from all panel Gen is ready to be put into PIC16F877 (and other PIC
outputs. Additionally check the general workshop use. products) can be downloaded
two inputs, using an external from Microchip’s web site at
signal generator. Outputs Out www.microchip.com
Direct and AC Out should only RESOURCES
be fed into the AC Input (do not The software for the PIC-
feed them into the Logic Input Gen is available for free
because of their negative-going downloaded from the EPE
content). Obline library at
(You may prefer to insert a www.epemag.com. The
1k resistor between socket SK1 program is written in TASM.
om
.c
ag
m
pe
.e
w
w
w
Copyright © 2000 Wimborne Publishing Ltd and EPE Online, July 2000 - www.epemag.com - 527
Maxfield & Montrose Interactive Inc