Now that you have built the LoPIC (Logic Probe with Pulser), you may want to
go further and add more features.
This is the advantage of a microprocessor-based design. It is very easy to
add features by simply adding lines of code to the program and you can go to
this new section of program by carrying out a sequence of events
with items already on the project. In this case you can use the earth
clip and probe tip as a switch, as explained below.
The LoPIC project already has three main features:
1. As a Logic Probe to detect HIGH, LOW and PULSE waveforms.
2. As a Logic Pulser to check the operation of LEDs, speakers and Piezo's.
3. As a 25mA current source for injecting into a project. It is very handy to have a low current source
that will not damage anything. You can see if a LED or piezo is connected
to a particular line or operate a speaker without damaging the output of a chip.
A handy additional feature is a set of Sounds and tones to
test different audio circuits.
We have provided a number of sounds and tones in our Library
of Routines section and it is handy to be able to hear each of them, if you are designing an alarm system, for instance.
One of the Sounds, Siren-Up can also be used to test the output of a
If you want to get the maximum output from a piezo diaphragm, it must be
connected in parallel with a choke. These two devices make up a circuit know
as a parallel
tuned circuit very similar to that covered in the Basic Electronics
Basically the energy delivered to the circuit is fed into the coil to
produce magnetic flux. This flux collapses and produces a voltage in the
opposite direction that is generally higher than the applied voltage. This
voltage is then passed to the piezo diaphragm. The piezo is effectively a
capacitor and it responds to the voltage by deforming the shape of the diaphragm
and also storing some of the energy. It then delivers this energy to coil and if the
incoming energy arrives at exactly the same time as required by the coil,
they add together without conflict. The result
is the output from the diaphragm is greater than expected. This is called
the resonant frequency
of the circuit. The piezo diaphragm, by itself, does not have a resonant
frequency however some types do have a range where their output is greater. This varies
for each device and if you have a gliding tone, you can very easily see how
each device performs.
The Probe and Pulser routines occupy less than half the memory of a
'508A and we can use the remaining locations for additional routines. To get
to these routines without adding any additional hardware (switches) to the
project, we can introduce a "series of events."
the probe tip to earth and turning ON the power switch. The Start-Up program
can be designed to detect the LOW input and count a number of cycles to make sure the input is
LOW, then go to the new section of sub-routines. To get back to the Probe/Pulser
section, simply turn the power OFF and switch ON again
without the probe tip connected to earth.
When we are in the new section, we can create any number of sounds suitable
for testing piezo's and amplifiers etc.
The sounds we have placed in this area are:
1. Siren - A siren-Up sound suitable for a car or house alarm
2. AckAck - An alarm sound similar to an anti-aircraft gun.
3. Hee Haw - Standard Hee Haw sound for an alarm.
4. 500Hz tone - to check the output of a piezo/speaker etc.
5. 750Hz tone
6. 1,000Hz tone
7. 1,250Hz tone
8. 1,500Hz tone 9. 2,000Hz tone
10. 2,500Hz tone 11. 3,000Hz tone 12. 3,500Hz tone
13. 4,000Hz tone 14. 4,500Hz tone 15. 5,000Hz tone 16. 6,000Hz tone
17. 7,000Hz tone 18. 8,000Hz tone 19. 9,000Hz tone 20. 10,000Hz tone
You can cycle around these sounds and tones (from 1 to 20) by placing the probe on the earth clip
and waiting for the end of the sound to be recognised by the program. Remove
the clip for at least one repetition of the sound and replace it again on
the probe tip to hear the next sound.
The Sounds program is separate to the Logic Probe/Pulser program. The micro
enters the Sounds section when it detects a low on the Logic Probe at Start-Up.
The Start-Up routine must detect a long period of time (in computer terms)
for a LOW to be present on the input of the Logic Probe. This is a form of
very heavy debounce to make sure the project only goes into the Sounds
section when a DEFINITE LOW is detected.
PRODUCING A TONE
To produce a tone such as
500Hz, the length of the HIGH and LOW must be 1,000uS (each). If the clock frequency is
4MHz, (the RC components: 4k7 and 22p for the PICF84 create a clock frequency
of 4MHz while the internal oscillator in the '508A is 4MHz), the chip divides
the clock frequency by 4 making the length of each instruction 1uS. The length of the HIGH and LOW is
called a Delay period and it requires exactly 1,000
instructions for each period - making 2,000 instructions for each cycle of
To produce a frequency of 10,000Hz, each cycle requires 100 instructions,
with each HIGH and LOW requiring 50 instructions.
These values can be placed in a table with a Tone routine calling the necessary
delay value for each tone.
When the frequency is low (500Hz), the number of microseconds for each delay period
is large and it does not matter if the delay is one or two microseconds
longer or shorter than needed. But when the frequency gets higher, the
length of each delay period is very critical and a single microsecond can
alter the final frequency by a noticeable amount. To produce frequencies as
close as possible to the required frequency we have had to introduce two
loops, a main loop and a trimming loop. One loop takes 4 instructions to execute
and the other takes 3 instructions. By adjusting the loading of each loop we
can create a delay that is accurate to 1 microsecond for all frequencies.
The only varying factor is the frequency of the chip. Since we
are using a resistor and capacitor for the PICF84, we can trim the resistor
to produce very near to 4MHz and thus get a very accurate scale. The
following values are those taken from our prototype:
The 6,000 Hz
frequency is slightly off target because the delay periods require a
fraction of a microsecond more and this is not possible with 1 microsecond
To work out a delay period you have to know exactly how many microseconds it
takes to decrement a file in a loop. If we take Loop1, for example, and load
the decrementing file with 08. This will produce 7 loops of 4 microseconds
and a final loop of 3 microseconds. For Loop2, it takes 3 instructions per
loop and a final loop of 2 instructions. If a file is loaded with 1, the delay
time is 2 microseconds for Loop2. There is only one delay in the Tone
Routine, made up of two loops and "setting up" instructions.
Within the delay time is an instruction to toggle the output and this is how
the HIGH and LOW is produced.
It is important to take into account the number of
instructions at the end of each HIGH or LOW, for setting up the files and
checking to see if the earth clip is touching the probe tip (this is called
the "look" feature). These
instructions take 14 microseconds are are a constant for each tone. The instructions
consist of the following lines:
line 23 (1uS), Line 24 (1), Line 25 (1), Line 26 (1), Line 27 (1), Line 28
(2), Line 38 (1), Line 39 (2),
Line 14 (1), Line 15 (1), Line 16 (1), and Line 17 (1).
The Tone Routine:
1 Tones CLRF 0C
;Clear the Table-jump1 file
2 MOVLW 01
MOVWF 0F ;Put 01 into Table-jump2 file
4 Tones1 BSF 1F,0 ;Set the debounce flag
MOVF 0C,0 ;Move jump1 value into W for table CALL
;File 0D is holding file1
;Ex-OR W with FF for end of table
;Look at zero flag in Status file
10 GOTO Siren
;End of table found
11 MOVF 0F,0
;Move jump2 value into W for Table CALL
12 CALL Table1
13 MOVWF 10h
;File 10h is holding file2
14 Tones2 MOVF 0D,0 ;Move file 0D into W
15 MOVWF 0E
;File 0E is decrementing file1
16 MOVF 10h,0
;Move file 10h into W
17 MOVWF 11h
;11h is decrementing file 2
18 Loop1 NOP
19 DECFSZ 0E,1
;Create HIGH and LOW values
20 GOTO Loop1
21 Loop2 DECFSZ 11h,1
22 GOTO Loop2
23 MOVLW 20h
24 XORWF 06,1
;Toggle piezo line
25 MOVLW 04
26 XORWF 06,1
;Toggle Pulser line
27 BTFSC 06,3
;Is Probe touching earth?
28 GOTO Tones3
29 BTFSC 1F,0
;Yes. See if Probe has been lifted
30 GOTO Tones2
31 DECFSZ 1A,1
;Yes. 256 loop debounce
32 GOTO Tones2
33 INCF 0C,1
;Increment the table-jump value1
34 INCF 0C,1
;Increment the table-jump value1
35 INCF 0F,1
;Increment the table-jump value2
36 INCF 0F,1
;Increment the table-jump value2
37 GOTO Tones1
;Go to next tone
38 Tones3 BCF 1F,0
;Clear the debounce flag
39 GOTO Tones2
"look" feature can also be called debounce. A very long
debounce is needed with any mechanical switch to make sure that only one
registration is recorded each time the switch is opened or closed. Each loop
of the routine above produces only half a cycle of the frequency and thus it
is executed very quickly. The routine above detects when the
probe is touching earth and looks at the "debounce-flag" to see if
it has been lifted. If so, it decrements file 1A, 256 times before
incrementing the table-pointer files so that the next tone will be
Inserting the instructions for the debounce feature, into the program,
at the correct places, is very important.
(file 1F) is set before the micro enters the Tone Routine (at line
4) and the routine is executed. At line 27, the probe tip is checked to see if it is still touching
earth. Obviously it will be, as the user has touched earth to get the
micro to advance to this routine and it will only take a few
milliseconds to execute one complete cycle. When the probe tip is lifted,
the debounce flag is cleared (at line 38). The next time the probe tip is
checked, and it is touching earth, a 256 loop debounce feature is executed
before the program increments the table-pointers for the next tone.
The purpose of this debounce is to prevent to micro skipping past a routine.
If the 256 cycles of debounce were not present, the action of removing the
probe would be detected by the micro as a removal and re-connection due to
the scraping nature of the clip on the probe. It would be impossible to
increment the Tones feature without a long debounce feature.
PROBE with Pulser
Program & .hex file with tones for 16F84:
The block of numbers
below is the HEX file for Logic Probe with Pulser for 16F84 with
Tones. Copy and paste it into a
text program such as TEXTPAD or NOTEPAD and call it: LoPIC84T.hex