• No results found

A Three-State Digital

Logic Probe

A logic probe circuit can be as quick and easy as an LED and a current-limiting resistor with a wire soldered to each end of the circuit. Simply connect the ground lead to Ground and touch the other lead to the point in a circuit that you want to test. If the LED lights, that point is at a high level; if it doesn’t, the point is not at a high level. However, this approach has two drawbacks—it can’t

distinguish between a point that is low and a point that is entirely disconnected from the circuit, and it draws a fair amount of current, which could affect the circuit’s operation.

Our digital logic probe project employs a simple ADC circuit that solves both these problems. We’re actually going to construct two versions. The first is a breadboard version that we’ll use to test the circuit. Once we’re sure the project is functioning correctly, we’ll build a stripboard version of the circuit and install it in a project case (actually, a plastic test tube). Before we get started, it’s important to note that this probe is only designed for working with digital logic circuits powered by 5V. Connecting the logic probe to voltages greater than 5V will most likely damage or destroy the 08M2 processor.

Breadboard Version

of Digital Logic Probe

The necessary parts for the breadboard version are listed in the Parts Bin; as usual, all the parts are available on my website. The schematic for the

project is presented in Figure 6-4, and the breadboard layout is shown in Figure 6-5. The three diodes in the circuit require a brief explanation. They aren’t really necessary in the breadboard version, but they will be in the final stripboard project; I decided to include them here rather than present two different schematics for the same project. As we’ll soon see, the final project will connect to the power rails of a breadboard, and it would be relatively easy to insert the connector into the rails incorrectly (reversing the 5V and Ground), which would probably damage the 08M2. Diode D1 blocks any current flow in the wrong direction, protecting the 08M2 from

possible damage. Even with both LEDs lit, the project doesn’t draw much more than 30mA. At that level, the BAT85 has a forward voltage drop of approximately 0.5V. Therefore, the probe is

actually powered by +4.5V, which is more than adequate for the 08M2. Diodes D2 and D3 simply ensure that any voltages present at the probe tip also will not exceed 4.5V. As I already mentioned, you don’t really need to include the diodes in the

Chapter 6 ■ Introduction to ADC Inputs on M2-Class Processors 71

Schematic for digital logic probe circuit

breadboard test circuit; just be sure to add them in the final stripboard version.

The software for our logic probe is presented in Listing 6-3. It’s really simple: just two statements executing in an infinite do…loop. Let’s start with

theselect case statement, which is one of my favorites. It performs the same function as a series ofif…thenstatements but it’s much simpler to write and to understand. Essentially, the select case

statement looks at the value of the specified variable (ADCval) and then executes the firstcase

clause that evaluates to true. In our program, if

ADCvalis greater than 190, then the LEDsvariable is configured to light the red LED. If ADCval is not greater than 190, the next case clause is evaluated. There are two points to keep in mind regarding this process. If none of the caseclauses is true, the statement executes the elseclause (if one is stated). If there is no elseclause, the program advances to the next statement without executing any of the

caseclauses. Also, whenever one of the clauses is true (and therefore executed), none of the

subsequent clauses are even evaluated; the program just moves on to the next statement.

The only other aspect of the program that requires explanation is how I arrived at the values

Part Label

Three BAT85 diodes D1, D2, D3 Two resistors, 330

Resistor, 1k — Two resistors, 10k — Three resistors, 100k —

Capacitor, 0.01F C1 LED, red LED1

LED, green LED2 PICAXE-08M2 (or 08M) —

P A R T S B I N

Breadboard layout for digital logic probe circuit

Chapter 6 ■ Introduction to ADC Inputs on M2-Class Processors 73

' =============================== LogicProbe.bas =============================== ' This program runs on a PICAXE-08M2 at 8 MHz.

' It implements a 3-state digital logic probe.

' ==============================================================================

' === Constants ==========

symbol Probe = C.1 ' probe on C.1

symbol Red = %00000001 ' turn on red LED

symbol Green = %00000100 ' turn on grn LED

symbol Blank = %00000000 ' both LEDs off

' ADC input boundaries ' ADC values (Open=134)

' —————————————————————————————————————————————————————————————————————————————

symbol Hi = 190 ' High = 254

symbol Lo = 70 ' Low = 10

' === Variables ===

symbol ADCval = b0 ' ADC measurement

symbol LEDs = outpinsC

' === Directives ===

#com 3 ' specify serial port

#picaxe 08M2 ' specify processor

#terminal off ' disable terminal window

' ============================ Begin Main Program ============================= setfreq m8

dirsC = %00000101 ' LEDs on outputs 2 & 0

do

readadc Probe, ADCval select case ADCval

case > Hi LEDs = Red case < Lo LEDs = Green else LEDs = Blank endselect loop LISTING 6-3

for the HiandLoconstants. (As an aside, I couldn’t use HighandLowas names for these two constants because the compiler reserves those two words for the HighandLowcommands.) In order to understand how the HiandLovalues were determined, let’s consider the three possibilities: the point in the circuit that the probe is touching is either at a digitalhighlevel, a digital lowlevel, or

open(i.e., not connected to any other point in the circuit).

1. Probe is open:In this case, the 1k resistor is effectively disconnected from the circuit, so the two 100k resistors will place the ADC reading near the middle of its range, that is, ADCval 127. (My actual ADC value in this situation was 134).

2. Probe is high:In this case, the 1k resistor is in parallel with the 100k resistor that is connected to the supply voltage, so the total resistance on the upper side of the voltage divider is (1k * 100K)/(1K 100K)990, which will raise the ADC reading close to the top of its range. (My actual ADC reading in this situation was 254.)

3. Probe is low:In this case, the 1k resistor is in parallel with the 100k resistor that is

connected to the Ground, so the total resistance on the lower side of the voltage

divider is 990, which will lower the ADC reading almost to 0. (My actual ADC reading in this situation was 10.)

TheHiconstant is the dividing line between a high input and an open input, so I definedHito be 190, which is approximately halfway between 134 and 254. Similarly, I defined Loto be 70 because that’s roughly halfway between 10 and 134.

Download LogicProbe.bas to your breadboard circuit. For test purposes, you can just use an eight- or ten-inch piece of jumper wire for the probe. When you (carefully) touch the jumper wire to a high point in the circuit (e.g., pin 1 of the 08M2), the red LED should light; when you touch a grounded point (e.g., pin 8 of the 08M2), the green LED should light; whenever the jumper is not touching anything (or touching a point on the breadboard that isn’t connected to anything in the circuit), neither LED should be lit.

Stripboard Version of

Digital Logic Probe

Obviously, a digital logic probe on a breadboard isn’t a convenient test instrument. What we need is a device that’s small enough to be comfortably held in one hand as we use it to examine our experiments and projects. The “case” I chose for

Size comparison of logic probe and mechanical pencil

Chapter 6 ■ Introduction to ADC Inputs on M2-Class Processors 75

this purpose is a small plastic test tube about four inches long and two-thirds of an inch in diameter; it turned out to be comfortable to use, but it was a challenge to squeeze the logic probe circuit into such a small space. To give you a sense of the size of the probe, Figure 6-6 is a photo of the completed project next to a mechanical pencil.

The parts list for the stripboard version of the logic probe circuit are listed in the Parts Bin, and the stripboard layout is presented in Figure 6-7. We’ll discuss the specifics when we actually construct the probe, but there are a couple of points related to the stripboard layout that I want to clarify before we begin. First, in the layout, you might have noticed that there are no holes in column AD. This is because I included the end of the stripboard (which has no holes in it) in this project because I wanted to be able to round the end of the board to match the curve of the bottom of the test tube, and I preferred not having holes in that area. If you look closely at the photo in Figure 6-6, you can see that the end of the board has been rounded.

ID Part

D1, D2, D3 Three BAT85 diodes — Resistor, 1k, 1/6 watt — Two resistors, 10k, 1/6 watt — Three resistors, 100k, 1/6 watt C1 Capacitor, 0.01F

LED1 LED, red, resistorized LED2 LED, green, resistorized — IC socket, 8-pin, machine-pins — PICAXE-08M2 (or 08M) processor H1 Header, male, right angle,

3 pins by 2 rows

— Ribbon cable, 3 feet, 6 conductors — Plastic test tube

— Finishing nail, 2 inches long — Two IDC female connectors,

3 pins by 2 rows

— Two 5-pin straight male header (0.23" and 0.32" mating lengths)

P A R T S B I N

Stripboard layout for logic probe project

I also want to clarify what turned out to be the most difficult aspect of the project. The layout shows the board as having six traces, which makes it 0.6 inches (15.2 mm) wide. The inside diameter of the test tube is also approximately 0.6 inches, so when I first began the project I naively thought everything would fit together perfectly. However, I ran into several problems along the way. Figure 6-8 is a close-up photo of the top of the stripboard that finally worked, and Figure 6-9 shows the bottom of the same board. As you can see from the pattern of partial holes along the top and bottom edges, the board ended up to be far less than 0.6 inches wide; in fact, it tapers from about 0.525 inches (13.3 mm) at the connector end down to 0.475 inches (12.1 mm) at the probe end. This is because the test tube tapers along its length—a fact that I failed to notice before I started!

In addition to the unanticipated taper, the board is narrower than I intended because three factors prevented my placing the board at the midline of the test tube. First, I wanted the “probe” (which is

actually an ordinary finishing nail) to protrude from the center of the bottom of the test tube. In Figure 6-8, you can see that the nail is soldered on top of the board, so the board has to be a little below the midline. Also, I wouldn’t have been able to squeeze the 08M2 into the test tube in that position anyway. For a while, I considered soldering the 08M2 directly to the board, but I finally got it to fit by “lowering” the socket—I’ll explain how in the next section when we actually construct the stripboard.

Constructing the Stripboard

The most important and difficult part of

constructing the logic probe is getting the board to fit all the way down into the tapered test tube. Of course, you can take the easy way out and skip the test tube altogether—the probe should function perfectly without it. But if you’re up for the challenge, I suggest that you read the following procedures fully before you begin; then start by

Close-up view of the top of the completed logic probe

Figure 6-8

Close-up view of the bottom of the completed logic probe

shaping the board to fit in the test tube. As a general guideline, you want to sand or file the taper on the board so that a little more than half the hole remains at positions A1 and A6 and the holes at positions AC1 and AC6 are almost entirely sanded away, as shown earlier in Figure 6-8. Once the board is prepared, you’re ready for the

assembly process.

1. Sever the traces on the bottom of the board as indicated in the layout in Figure 6-7.

2. Round the probe end of the board by sanding or filing it until it matches the curve of the bottom of the test tube.

3 From the bottom of the board, use a 1/16-inch (1.5-mm) drill bit to enlarge the eight holes for the machine pin socket. This will enable the socket to sit low enough for the 08M2 to fit into the test tube. Solder the socket in place.

4. Solder the nail to the stripboard as follows: Use a pair of diagonal cutters to remove the head of the nail so it lies flat on the

stripboard. Cut four bare jumper wires about two inches long, bend each one into a “U” shape, and fit it over the top of the nail and down through the pair of holes on each side of the nail. On the bottom of the board, use a pair of pliers to twist the ends of each jumper together tightly so that the nail is held firmly in place. (Make sure the nail is positioned along the midline of the stripboard.) Solder the jumpers to the topof the nail first. (This produces so much heat that it would melt the solder on the bottom of the board if you did it the other way around.) Let the nail cool; then solder the jumpers to the bottom of the board and snip off the excess leads.

5. Drill a 3/32-inch (2.5-mm) hole in the center of the end of the test tube—there’s a small dot on the tube at just the right place. Make sure the stripboard fits all the way down the tube

and the nail protrudes through the hole. Adjust the width of the board and the size of the hole if necessary.

6. Test-fit the 3 2 right angle male header. If necessary, sand or file the end of the stripboard so that the black plastic of the header just overhangs it, rather than sitting on top of the board (see Figure 6-8). Solder in the header and the jumper wire on the bottom of the board that spans from A2 to A5.

7. Insert one of the 3 2 IDC female

connectors onto the male header pins. Also insert an 08M2 into the socket; then test-fit the board again to be sure everything will fit properly inside the test tube. Make any necessary final adjustments.

8. Solder all the remaining parts (exceptfor the two LEDs) in place. At the six places along the edges of the board where a jumper wire or resistor lead needs to be soldered at a location that has less than a complete hole, crimp the lead around the edge of the board to hold it in place. The three 0.1-inch (2.54-mm) jumper wires are easy because in each case, one lead can be bent to touch the other lead. For the two resistors and the longer jumper wire, make sure the lead at the edge of the board does not come in contact with the adjacent trace on the bottom of the board.

9. Figure 6-10 shows the completed probe being used to test a circuit. I happen to be left- handed (as you can see in the photo), which is why I positioned the red and green LEDs as I did—it just makes more sense to me that the

highLED is above the lowLED. If you’re right-handed and that sort of thing matters to you, you may want to reverse the position of the two LEDs before soldering them in place. (If so, you will also need to reverse constant declarations in the program.) Before soldering each LED in place, bend and snip each

negative lead so that it just contacts the adjacent trace as shown in Figure 6-7 and Figure 6-9.

10. Clean the flux from the bottom of the board and allow it to dry.

11. Inspect the board carefully for accidental solder connections and other problems. Okay, we’re ready for the final step: assembling the ribbon cable and connecting the logic probe. If you don’t have experience with ribbon cable and IDC connectors, take a look at the tutorial on my website (www.jrhackett.net/progcable.shtml). When you’re ready to proceed, just follow these steps.

1. Drill a 5/16-inch (8-mm) hole in the center of the test tube cap.

2. Attach a 3 2 IDC connector to one end of the six-wire ribbon cable.

3. Pass the other end of the cable through the hole in the test tube cap.

4. Attach another 3 2 IDC connector to the other end of the cable. Be sure to orient the connector the same way as the first one. (If you stretch the cable out so that it’s lying flat on one side, both connectors should either point up or point down.)

5. Attach the connector that is on the interior side of the cap to the stripboard connector so that the cable exits from the bottom of the connector. Slide the stripboard fully into the test tube, and insert the cap into the end of the test tube.

To test the logic probe, first program an 08M2 with the LogicProbe.bas software and then install the 08M2 in the socket. Next, connect the ribbon cable to the supply rails of a breadboard. At this point, you may not know which way is the correct

Testing a circuit with the completed logic probe

orientation, but the logic probe is protected from any reverse-polarity damage, so we can figure that one out experimentally. Using two 3-pin sections from the two 5-pin male headers, connect the ribbon cable to the power rails of a breadboard. If the power supply is reversed, the LEDs won’t light, regardless of which point in the circuit is probed. If that’s the case, simply rotate the

Related documents