+ All Categories
Home > Documents > Lab 16/D3: Counters Contents - Harvard...

Lab 16/D3: Counters Contents - Harvard...

Date post: 23-Mar-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
19
Chapter 16L Lab 16/D3: Counters Contents 16LLab 16/D3: Counters 1 16L.1Two Paths into Microcontrollers ................................................ 2 16L.2Small Board: Counter on a single Breadboard Strip ...................................... 2 16L.3Big Board: PC for Microcomputer Breadboarding ....................................... 2 16L.3.1 A Preview of the Setup ................................................. 3 16L.416-bit Counter ......................................................... 4 16L.4.1Pinout and Wiring of this Counter ........................................... 5 16L.4.2Single Breadboard Option ............................................... 5 16L.4.3Big Board Option ................................................... 6 16L.4.4Wiring the PAL .................................................... 7 16L.4.5Add the Display Board ................................................. 10 16L.4.6Attach the Keypad ................................................... 12 16L.5Try the Counter at higher speed ................................................ 12 16L.6Make Horrible Music ...................................................... 13 16L.6.1Hearing the effect of Load*: strange modulus counter ................................. 13 16L.6.2Fixing an Interesting Flaw in this Circuit ........................................ 14 16L.7Counter Applications: “Stopwatch” .............................................. 15 16L.7.1Stage One: Simple Stopwatch ............................................. 16 16L.7.2Stage Two: Automatic Period Meter .......................................... 16 REV 1 1 ; October 11, 2014. Today you move up from the modest “divide-by-four” of last time to a 16-bit “fully synchronous” counter. 1 Revisions: insert Ray redrawings (10/14); add headerle (6/14); correct size of pinout label, last page (3/14); replace overview photo to show plug-in display; slightly tidy counter schematic (2/14); add subsection making explicit the wiring of KD to parallel-input lines, after students missed that, recently (10/13); add gure showing counter and its signals (6/13); re-order PAL-wiring so it applies to both versions; add single-strip switch images to gures for DIP and Load switches (5/13); add option of building counter on single strip (1/13); add references to 16-bit data display on LCD board (3/12); pinout of PLCC altered to accommodate newer breadboard (3/09); pinout of PLCC and connector altered to move clock to Global-clock position; data-input labels changed from “Dx” to “Px,” to avoid confusion with Data bus (2/09); counter-connector corrected (syncld, reset); div-by-2 diagram inserted (Nov16 08) 1
Transcript
Page 1: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Chapter 16L

Lab 16/D3: Counters

Contents

16LLab 16/D3: Counters 116L.1Two Paths into Microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216L.2Small Board: Counter on a single Breadboard Strip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216L.3Big Board: PC for Microcomputer Breadboarding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

16L.3.1A Preview of the Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316L.416-bit Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

16L.4.1Pinout and Wiring of this Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516L.4.2Single Breadboard Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516L.4.3Big Board Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616L.4.4Wiring the PAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716L.4.5Add the Display Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016L.4.6Attach the Keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

16L.5Try the Counter at higher speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1216L.6Make Horrible Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

16L.6.1Hearing the effect of Load*: strange modulus counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1316L.6.2Fixing an Interesting Flaw in this Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

16L.7Counter Applications: “Stopwatch” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1516L.7.1Stage One: Simple Stopwatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1616L.7.2Stage Two: Automatic Period Meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

REV 11; October 11, 2014.

Today you move up from the modest “divide-by-four” of last time to a 16-bit “fully synchronous” counter.

1Revisions: insert Ray redrawings (10/14); add headerfile (6/14); correct size of pinout label, last page (3/14); replace overviewphoto to show plug-in display; slightly tidy counter schematic (2/14); add subsection making explicit the wiring of KD to parallel-inputlines, after students missed that, recently (10/13); add figure showing counter and its signals (6/13); re-order PAL-wiring so it applies toboth versions; add single-strip switch images to figures for DIP and Load switches (5/13); add option of building counter on single strip(1/13); add references to 16-bit data display on LCD board (3/12); pinout of PLCC altered to accommodate newer breadboard (3/09);pinout of PLCC and connector altered to move clock to Global-clock position; data-input labels changed from “Dx” to “Px,” to avoidconfusion with Data bus (2/09); counter-connector corrected (syncld, reset); div-by-2 diagram inserted (Nov16 08)

1

Page 2: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

2 Lab 16/D3: Counters

We will let it show off some of its agreeable features, notably its synchronous load, and then we will put itto use in two circuits: a programmable divide-by-n machine, then a period-measurer, which can operate as acapacitance meter, with just a little help.

At first you will use only scope and logic probe to watch the counter’s performance; then you will add ahexadecimal display that should make the counter’s behavior easier to follow. A keypad will let you controlthe counter and load it.

Note:• The keypad is not a standard commercial part. It can be made up from the schematic attached to these Lab notes, or it can be ordered

in complete form. See Parts List for ordering information.• The display board that we use also is a custom-made circuit, using an LCD display to show 16 lines of address, and 8 or 16 of data.

16L.1 Two Paths into Microcontrollers

A separate note sketches the alternative ways you may choose to use the microcontroller, and this is the timeto look at that note and decide which path you mean to take: to build up the “big board” computer using partsplugged into breadboard strips, or instead to use a single-chip controller without external buses or peripherals.

Next time, people who have chosen to build the “big board” computer (let’s call this option “BIG,” for short;see note A Fork in the Road) will use this counter and display to provide an address to a memory. The keypadwill let you write 8-bit values into any memory location. In a later lab, counter and memory will serve asfoundation of the microcomputer. So, today big board people are beginning to build the little computer.

16L.2 Small Board: Counter on a single Breadboard Strip

If you will not be building the BIG version, then you can build today’s counter in a single strip. Thatarrangement is described in § 16L.4.2 on page 5.

16L.3 Big Board: PC for Microcomputer Breadboarding

Note: If you choose the “Big” computer option, you will build today’s circuits on your own private breadboard: a printed circuit holding severalbreadboard strips mounted together. This breadboardwill become the foundation of the microcomputer that you soon will be putting together.

If you don’t have this printed-circuit board you can, of course, build the “Big” computer on four or fivebreadboard strips. The printed circuit only eases the wiring somewhat.

In an effort to make the Big Board task less daunting than it might otherwise be, we have laid out a printed-circuit board that defines buses for the computer, though leaving to you the connections between these busesand your circuitry. The benefits of these ready-made buses are two:

1. First, we hope they will make the concept of a bus less abstract than if you were to see it only as“whatever lines go to many places.” The buses are labelled, and defined by the traces that run thelength of the board.

2. Second, the buses allow (as in any computer) tidy wiring among circuit elements. You should seldomfind the need to run long wires about your circuit. The bus lines run close to a ground plane, and are

Page 3: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 3

less vulnerable to cross-talk than long, wandering wires (and they’re less ugly).2

Here is what the buses look like, on the board’s top and bottom layers (it is a two-layer printed circuit).

Figure 1: Buses defined by printed circuit that underlies the usual breadboard strips

The right-hand image is included to remind you that some of the external connections are already wired tothe dedicated buses:

• a display board is wired to the 16-line address bus and to the 8-line data bus;

• a keypad is wired to the 8-line “keypad data bus” (which is not the same as the general data bus; thisdifference, obscure now, will make sense soon, once the data bus has begun to function, in Lab D4).

16L.3.1 A Preview of the Setup

And here is a glimpse of the way the breadboard will connect to display and keypad:

Figure 2: Display and Keypad connected to the breadboard

2You may be inclined to protest that traces that run close to other traces for eighteen inches are more likely to cause crosstalk thanspaghetti wires wandering above the board. You have a point—but we anticipated this problem and placed a ground trace betweenadjacent signal lines on the buses of the pc board. These ground traces should minimize crosstalk.

Page 4: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

4 Lab 16/D3: Counters

16L.4 16-bit Counter

The counter you install today is a versatile 16-bit device, designed to define the address in our lab microcom-puter, whenever we want to determine this address manually. It is made from a PAL much like the PAL youwill design and perhaps program to implement the “glue” logic that links the processor to the remainder ofthe computer circuitry3. Here are its features:

• It counts up or down—and this behavior is handy for our purposes: soon (in Lab D4) you will use thecounter to take you to a particular memory location or address;

• it includes three-state outputs: this feature will let us tie the counter outputs directly to the computerbus (specifically, to the address bus.);

• it can be “loaded” with an initial value. Today, we will use Load* to let us make a divide-by-strange-number counter; later, in the micro labs, we will use Load* to let us hop to a particular starting pointin the memory’s address space.

The load function is implemented in two alternative ways, available through use of two control pins:

– asynchronous load: this takes effect as soon as the signal is asserted (here, that occurs when youpress a pushbutton). This is the form that will be convenient for your use in forcing the counterto a particular starting address, when you want to access a chosen region of memory. The pin isnamed “LOAD*”.

– synchronous load: this takes effect only on the next clock following assertion of this signal.This form works better than asynchronous when it implements an automatic re-load in a countingloop. We will use it that way in an exercise early in today’s lab (§ 16L.6) to make a programmable“divide-by-n” counter, with “n” determined by a value entered on a keypad. The pin is named”SYNC LD*”.

• it includes carry-in* and carry-out* pins that normally would be used to allow “cascading” several ofthese units, so as to form a bigger counter. We will not use carry-out* for this purpose, but will takeadvantage of the carry-in function.

This pin can be used to tell the counter to count or, instead, to hold its present value despite clocking.(You may recognize carry-in as just equivalent—on the counter-wide scale—to the “T” input that con-trols a single flop: the T-type flip-flop that you built in Lab D2 from a D flop and an XOR gate.) Wewill take advantage of this carry-in function—which can also be described as an enable—in formingthe stopwatch and then period-meter of §§ 16L.7.1 and 16L.7.2, near the end of this lab.

• it includes a RESET* that is synchronous, like one of the two LOAD functions.

3More specifically, the counter is made from a Xilinx XC9572 (5V supply) or XC9572XL (3.3V supply).

Page 5: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 5

16L.4.0.1 A Preview of the Counter and Its Signals

Here is a sketch of the counter as a fragment of the Big Board schematic. Exactly the same signals are usedwhether the counter is wired in the Big Board or on a single breadboard.

Figure 3: 16-bit PAL counter and its control

16L.4.1 Pinout and Wiring of this Counter

This counter is one of the first parts you have met, in this course, that is not offered in the package called“DIP.”4 This counter has no legs to plug into a breadboard. So, we are obliged to put it into a socket that fitsits PLCC5 form. On the Big Board, that socket is mounted near the center of the printed circuit; on a singlebreadboard, the PLCC socket is on an adapter or “carrier” that provides DIP pins that can be plugged into aordinary breadboard.

16L.4.2 Single Breadboard OptionHere’s what our breadboard looked like, when we eschewed the BIG board, using just a socket and singlebreadboard strip:

Figure 4: Counter on a single breadboard

The counter, in a 44-pin PLCC package, is mounted on a DIP adapter.6 Fig. 4 shows only the input controllines wired, along with parallel-input lines P9, P8, shown grounded by the DIP switch. Later, data input

4“DIP” is Dual Inline Package”—the sort that plugs into our solderless breadboards. Our op amps and other analog parts have beenDIP’s, as have all our digital parts, to this point.

5“PLCC” is Plastic Leaded Chip Carrier.6Ez-Prototype 02-AK44D900-PLCC or ProtoAdvantage PA0107SOCKET or Aries 44-653000-11-RC [pricey]

Page 6: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

6 Lab 16/D3: Counters

lines P7. . . P0 will be fed by the keypad’s 8 output lines (see § 16L.6 on page 13). The 16 output lines (thecounter’s Q15 . . .Q0, labelled “A15 . . .A0” in fig. 4 on the previous page) will be fed to the 16 address lineson the LCD card.

16L.4.2.1 PinoutHere are pin assignments for the single-strip version of the counter:

Figure 5: Pinout of counter, for use in single-breadboard strip

Most of the pin assignments are made simply to provide locations convenient for breadboard wiring. Someof the pin assignments, however, are constrained: clock is placed at pin 5 because this is a preferred locationfor any common clock; pin assignments for power, ground and JTAG connections are entirely fixed.7

16L.4.3 Big Board Option

The micro breadboard offers four PLCC sockets (each of 44 pins). The counter can go in any of these, butthe most convenient is the one at top center. That socket sits close to the address buses that the counter willdrive, and because its pins are brought out on both sides of the package its signals can be connected withoutcrossing over wires as is necessary for the sockets on the end of the board.

Before you begin to wire the counter, we hope you will cut out and paste in place the pinout labels that appearat the end of these lab notes.

Fig. 6 shows, as well, the pinout of the PLCC itself. Occasionally, this may become useful: if you begin todoubt the integrity of a connection from the PAL to the breadboard you may want to probe the PAL’s pins.For the most part, however, you can ignore the PLCC and probe just the labelled PLCC connectors, alongwith the address and keypad buses. The buses carry their own permanent labels on the micro breadboard.

7One of the pins that we have labelled “Vcc” , pin 32, differs from the others: it defines the I/O level, and could be set to 2.5V ratherthan to 3.3V. We tie it to 3.3V, so have not labelled it differently from the other two Vcc pins.

Page 7: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 7

Here is the empty PLCC socket with labels attached alongside.

Figure 6: Pinout of breadboard PAL connectors, and PLCC of PAL

16L.4.4 Wiring the PAL

16L.4.4.1 Wire Power and Ground First

The PAL uses 6 lines for power and ground, 3 for each. We suggest that you wire all of these initially.Everyone tends to find wiring power and ground tiresome—labor worthy of a lab partner but not of oneself.But try to get the habit of doing these first.8 If your counter is a 3.3V part—XC9572XL—make sure to takepower from the 3.3V supply rather than 5V.

Since your PLCC is likely to take ground and perhaps also V+ from the white breadboard strips, don’t omitor postpone making the necessary connections to the strips’ vertical power and ground buses, from the “Vcc”and ‘G” points available at both ends of each white breadboard. The positive supply is 5V, even if you areusing a 3.3V counter, since these strips will power 5-volt logic.

We suggest that you invest 5 minutes now, to make all those connections to the breadboard strips—and tobridge the midpoint of each of the ten power buses. If you postpone that little chore, you will save a fewminutes now, and probably will suffer a longer stretch of frustration later on, when some part of your circuitmisbehaves for lack of power or ground.

16L.4.4.2 Control Lines

Next, we suggest that Big Board users should wire the counter’s control lines from the PAL’s PLCC connectorto some free bus lines on the breadboard. You will find these uncommitted bus lines—labelled “free buses”in fig. 1 on page 3—near the top and bottom of the pc board. There are enough of these lines so that you mayfind it worthwhile to write or print labels, attaching labels either to the wires or to the breadboard itself.

8Omitting power and ground sounds unlikely—but it is an error so common that in one term the teaching assistants offered candy asa reward to the students who did not forget. We doubt that you need such babying.

Page 8: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

8 Lab 16/D3: Counters

The following are these control signals:

• clk (rising edge, as usual)

• cin* (carry in, or enable)

• cout* (carry out, asserted on FFFFh for up count, on 0000h for down count)

• oe* (3-state control)

• ld* (asynchronous load: on assertion of this signal, counter is loaded with 00 in top 2 bits, 2 bits from DIP switch that you must wire, 8 bits from keypad, and 0000into lowest-order bits)

• sync load* (synchronous load: on next clock, counter is loaded as for async load)

• reset* (synchronous reset: forces counter to all zeroes)

• up*/d (up/down control: low causes counter to increment on next clock, high to decrement)

16L.4.4.3 DIP switch controls four inputs. . .

We used a 4-position DIP switch to control 2 of the lines, SYNC LOAD* and RESET*, and a momentarypushbutton to drive the asynchronous LOAD* pin. (Two other positions of this DIP switch drive the top 2bits of data into the counter: P9, P8.) Here is the DIP switch, controlling its four signals:

Big Board… …single strip

sync_LD*reset*

+5V

10k

P9P8

Figure 7: DIP switch used to control four counter signals: Big Board and single-strip versions

The same sort of DIP switch controls these four lines also in the single-breadboard version of this circuit,illustrated in fig. 7 on the right, and also in fig. 4 on page 5.

16L.4.4.4 . . . Pushbutton controls Load function

A pushbutton drives the counter’s asynchronous load function—which transfers a value into the counter inparallel (doing this, the counter is behaving like a register of flip-flops, not like a usual counter). The valuecomes from the keypad (8 bits), plus another two bits controlled by the DIP switch described in fig.7. (Weseldom change those DIP switch settings on the “P9, P8” bits, incidentally. We leave them low.)

The pushbutton, with its four legs connected to just two terminals, can be puzzling, so below we’ve sketchedthe way it works. We have also tried, here, to remind you to flatten and rotate the switch’s legs. If not rotated,they are too wide for the breadboard.

Figure 8: Pushbutton details

And here is what it looks like, wired to drive the LD* terminal of the counter:

Page 9: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 9

Figure 9: Pushbutton wired to drive LD*

16L.4.4.5 Counter Output Lines and Inputs

The counter’s 16 output lines—A0. . .A15—run to the 16 lines of the address bus. If you are using the counteron a single strip, then the 16 lines go directly to the LCD card (see fig. 12 on page 11).

16L.4.4.6 . . .Keypad feeds Counter’s Parallel Inputs

Another eight lines feed the counter from the keypad. Note that these lines from the keypad DIP connector areinternallywired, on the micro breadboard, to the bus labelled “KD0. . .KD7.” Note also that these keypad datalines—labelled “KD0. . .KD7”—are not the same as the main data lines—labelled “D0. . .D7.” That principaldata bus is not to be wired until next time, when memory arrives.

On the single-strip, those 8 keypad lines feed P0. . . P7, as we noted back in § 16L.4.2 on page 5.

16L.4.4.7 . . .Control Inputs

Take care of the counter’s several control inputs. Specifically. . .

• drive CLK with the keypad’s ADR CLK line

• drive the PAL’s U*/D line with the keypad’s signal of the same name

• set the DIP switch so as to disassert RESET* and SYNC LD*, while tying P9 and P8 low

• wire CIN* (an enable) and OE* (the three-state control) so as to assert these signals continuously

• leave COUT* open, for the present

Counter as Wired on Big Board Here is what the wiring of the PLCC may look like, once address, keypadand the several control lines have been connected. We tried to keep the wiring low, so that no wire is likely toget knocked out in the coming weeks. The boards will be stored and brought out many times. We like wiringthat can stand this travel. You will, too.

Page 10: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

10 Lab 16/D3: Counters

Figure 10: All necessary lines connected to PAL Counter

16L.4.5 Add the Display Board

We’ll soon be watching the counter on an oscilloscope, but let’s set up the other way of watching it, beforeproceeding further:

16L.4.5.1 Counter Display as Wired on Big Board

The LCD card plugs into a DIN connector9 on the big green breadboard pcb. This connector provides. . .

• power: slide the LCD power select switch on top right to “external” so as to take 5-volt power from thebig green board.

• address: the DIN connector links these 16 display inputs to the pcb’s 16 lines of the pcb address bus.Those lines are driven by the Q’s of the counter’s 16 flip-flops.

• data: either 8 or 16 lines can be displayed. Today, we have no data to show, but the LCD will displaythese floating inputs nevertheless. Next time, they will carry data stored in RAM; today they carrynothing.

9“DIN” is “Deutsches Institut fr Normung,”German Institute for Standardization. It has defined thousands of technological standardsfor the Europe. This 48-pin connector is just one such standard.

Page 11: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 11

Figure 11: LCD can show counter output

The counter output can be displayed in either hexadecimal or binary format. Fig. 11 on the preceding pageshows hexadecimal; fig. 12 demonstrates both formats. Hex is much better to let one recognize a number’svalue at a glance. But as you begin to play with the counter, we’d suggest that it’s better to start with a binarydisplay: especially when the counter is clocked slowly, the binary display lets you recognize the countingpattern.

16L.4.5.2 Counter Display as Wired on Single Strip

Attach the counter’s 16 Q’s to the two 8-bit address connectors on the LCD card.

The figure shows the counter board inverted. This is not necessary, but allows us to avoid putting a half-twistinto the flexible cables that carry the 16 signals.

Figure 12: Display of counter output, using LCD card tied to single-breadboard

The blurred images of the lower-order bits in fig. 12 reflect the quick counting and slow shutter speed of the

Page 12: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

12 Lab 16/D3: Counters

camera.

16L.4.6 Attach the Keypad

16L.4.6.1 Big Board

Attach the keypad, using its 16-line DIP cable. Once plugged into the DIP socket, the keypad’s KD0 . . .KD7lines drive the counter’s parallel input lines P0 . . . P7, lines that you earlier connected to the micro breadboardKD0 . . .KD7 bus.

16L.4.6.2 Single Strip

Plug the keypad into the breadboard strip and feed its 8 data lines to inputs P0. . . P7 of the counter.

Those 8 lines drive the middle eight lines of the counter’s 16 data input lines.10 These eight lines becomesignificant only when the counter does a Load operation.

16L.4.6.3 Does the Counter Count?

We hope so. You’ll find out if you push the keypad’s INC button. The counter should increment its value. Ifyou press the DN button, the counter should decrement its value. The RPT key clocks the counter at about20Hz, with direction UP by default, but DOWN if you press DN and RPT together.

16L.4.6.4 Try Loading and Reset*

Try the LOAD* pushbutton. It should make the keypad value appear on the middle two digits of the hexdisplay.11 Now try the synchronous load: flip the DIP switch to drive SYNC LOAD* low (doing this shows noimmediate effect), and then clock the counter from the keypad’s ADCLK* line. After testing SYNC LOAD*,disassert that signal.

Try RESET*, using the DIP switch: note whether its behavior is synchronous or asynchronous.12

16L.5 Try the Counter at higher speed

Now replace the keypad’s ADR CLK* signal, which was clocking the counter, with a logic-level signal fromthe function generator. Try fclock of a few kHz.

Watch clock and Q0, then clock and Q5 (triggering in both cases on the Q—and the slowest Q when watchingmore than one).

10This is a bit strange. But the keypad provides only 8 lines,and placing these in the counter’s middle—to feed Q4. . .Q11—strikes acompromise. The counter can load a value that is on a 16-count boundary (soon to mean a “16-address” boundary). From that point youhave to walk up or down, to get to any particular address. You can never be farther than an 8-step walk from your destination.

At the same time, the keypad cannot carry out very large hops in address space, since it does not control the counter’s high 8 lines.(The DIP switch’s P9 and P8 lines can help.) But we don’t think you’ll find the limitations of the counter’s LOAD function troublesome.

11The display can show you binary or hex, as we said back in § 16L.4.5 on page 10. A slide switch on the display board, lower left,selects the display format.

12Like all the counter’s functions except LOAD*, it is synchronous: it waits for the clock.

Page 13: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 13

In the unlikely event that your counter’s behavior is erratic, you may want to clean up the clock, by passingthe function generator’s TTL signal through a local logic gate that has hysteresis:

74HC14“TTL” fromgenerator

local clock source”to counter clock

Figure 13: HC14 can clean up a messy clock

Then watch Q0 and Q15: do you see any delay of the higher-order Q relative to the lower-order, as you did ineven the small ripple counter you built in Lab D2?13 Now take a look at COUT*.14 You will need to triggeron the carry—and note that it is only one clock wide, so may look very narrow indeed, if your scope screen’ssweep covers many clocks.

If you use a couple of spare scope channels to watch Q0 and Q1, you can see the difference between carryon an UP count and carry on a DOWN count. If you feel like playing with the LCD display again, drop theclock rate way down, so that you can see individual states. Check that UP and DOWN behave as advertised.

16L.6 Make Horrible Music

If you let the counter’s COUT* line drive its SYNC LOAD* pin, then it will reload itself each time it over-flows. It will load itself with a 16-bit value formed from 2 lines of the DIP switch (P9 and P8: let’s set theseboth low), 8 lines from the keypad, and 4 LSB’s set to constant zeroes within the counter’s innards. So, thekeypad value can determine where the counting starts.

If you count DOWN, the pattern is pretty straightforward, so we suggest you temporarily tie UP*/D to +5, asyou do this section.

SYNC Load* is driven by COUT*, so these signals are asserted only when the counter is about to ‘roll over;’since the counter is set to count down, it reloads each time it hits zero. So, this circuit lets the keypad set thenumber of counts that occur between loads; thus the keypad sets period and frequency of the COUT* pulsewaveform.

Watch COUT* and Q3 of the low-order counter as you vary the keypad input value. Does the response fitwhat you expect? The keypad value is 8 bits, and a single keystroke updates only the lowest 4 bits. You maywant to keep the high nybble at zero, as you experiment. You could temporarily tie those 4 lines to ground,so that the keypad feeds only P0. . . P3 to the counter; that would make your instrument behave more like amusical keyboard—as we’re about to ask it to do.

16L.6.1 Hearing the effect of Load*: strange modulus counter

To make more vivid the power of this loadable counter to vary its modulus–the number of states it stepsthrough—let’s listen to the counter’s output frequency. Let Cout drive a transistor switch (a power MOSFETis easiest), which in turn drives the breadboard’s speaker, as shown in the figure above. If you want to annoyyour neighbors with a louder tone, let COUT* drive a togglingflip-flop: the 50%-duty-cycle signal that comesout of the flop makes more noise than the narrow COUT* pulse does. Without this flop, the low duty-cycle ofthe COUT* pulse can make it barely audible for some count-lengths.

13We hope not.14In an UP/DOWN counter like this one, this carry sometimes is called “borrow” on the down count, by analogy to subtraction. We’ll

call it just “Carry.”

Page 14: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

14 Lab 16/D3: Counters

Figure 14: Music maker: divide-by-two makes output volume greater, and independent of frequency

16L.6.2 Fixing an Interesting Flaw in this Circuit

16L.6.2.1 The Problem: Glitches on COUT*

When we tried this, we were surprised to find that the COUT* signal—which detects the counter’s state zero,during down counting—carried nasty glitches, glitches substantial enough to clock the divide-by-two flip-flopthat we were using to provide a 50:50 duty cycle. The glitches made nonsense of our music machine.

Figure 15: Glitches on Carry can cause disaster when COUT* drives a clock

16L.6.2.2 The Remedy: Synchronize the COUT* Signal with a Flop

You’ll notice that the glitches in fig. 15 occur after the clock edge. This is the usual case, since it is thechanging signals, brought about by clocking, that trigger the glitches. Such glitches are entirely harmless toa flip-flop clocked by the signal that evoked the glitches—in this case, the clock of the main counter.

So, here’s a remedy for these bad carries: a synchronizing circuit that blocks the glitches:

(counter’s) clk

glitchy COUT*OUT* clean COUT*OUT*

V

D Q

Figure 16: Synchronizer flop can clean up COUT*

The glitches will not pass through the flop, because they occur after the edge that updates this synchronizingflip-flop.

Page 15: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 15

Include such a synchronizer upstream of the divide-by-two that is to drive the speaker, in your music machine.Please sketch your clean divide-by-two (so that if you look back at these notes in a month or so, you’llrediscover how clever you were).

Your Design for a Clean Divide-by-TwoCircuit

We hope you will also have the nerve to try the effect of omitting (or bypassing) the synchronizer. We hope,also, that your music sounds as disorderly as it did for us. We want this ugly result because we want you toappreciate the power of synchrony in digital designs. You will appreciate that if you find the synchronizingflop tidily solving this messy problem.

Once things are working right, the keypad should act like the keyboard of a crude musical instrument.

Do you hear the pitch fall by an octave when you change from key X to key 2X?

Out of Tune because of the Zero State For very low keypad values, your instrument goes out of tune,because of the extra state zero included in each down-count cycle.

For example, if you load a 1 from the keypad, the counter receives a 1610 because of the constant zeroes inthe LSB positions. It counts down from 16 to zero, then reloads 16. So, it goes through 17 states, not 16.When you load a 2 from the keypad you might expect a doubling of period—but a 2 evokes 33 states—notquite an octave different from 17. In fact, that small difference amounts to almost exactly a half-tone, as yourear may confirm for you.

16L.7 Counter Applications: “Stopwatch”

We know this is a long lab. We offer these exercises because we think you’ll find them fun, and instructive.Do what you can. Don’t feel guilty if you don’t build the stopwatch. You may get a chance to build it (andapply it as a capacitance meter) in a later project lab.

A very slight alteration of the 16-bit counter will allow you start and stop the counter: you need only add amanual switch to control the level of the Carry in*. So altered, your counter would be a primitive stopwatch.The addition of a few flip-flops and two NAND gates can make this stopwatch more convenient: first byletting you latch the counter output into the displays (that way you need not watch the counting-up process),then by clearing the counter automatically after the result has been latched.

That circuit can measure the length of time a signal spends low (as we have wired it). This period-measuringcircuit then could be put to any of a number of uses. In the later project lab, for example, we propose thatyou might use it to measure the period (or half-period, to be a little more accurate) of the waveform comingfrom a 555 RC oscillator. If you then hold the “R” constant and plug in various C’s, you will find that youhave built a capacitance meter. You might find this a satisfying payback for about a half-hour’s wiring.

When you have had some fun with the circuit, we ask you to restore your counter and RAM to their earlierform: so, flag the changes you make to the circuit as you go along–you may want to plug in odd-lookingwires at the points where you remove a wire. (There are only a few of these points.)

Page 16: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

16 Lab 16/D3: Counters

16L.7.1 Stage One: Simple Stopwatch

Remove the lines that now drive Clock and SYNC LD* ; remove the line that grounds Cin*.

Drive Clock with a TTL signal from the function generator (not the breadboard generator; you will soonneed a frequency higher than its 100 kHz); temporarily tie SYNC LD* high.

clk

hold/count

(from functiongenerator)

+5

+5

+5V

CIN

reset syncLd

Q1515

display

16

Figure 17: Stopwatch block diagram

Confirm, first, that you can start and stop the counter by taking Cin* low, then high, using a manual switch.You can clear the counter, as you confirmed earlier in this lab, by pressing the RESET* pushbutton. You nowhave a clumsy stopwatch.

16L.7.2 Stage Two: Automatic Period Meter

The stopwatch becomes a period meter if we add the automatic output-latching and counter-clearing men-tioned above. Here’s a sketch of the scheme:

clk

count

V

CIN Q1515

reset*

one-shot

latch_en

QØ16

8Q7 7 …QØ

data

counter display

Figure 18: Period meter block diagram

To save the result and then clear the counter for next pass we need a circuit that will generate pulses timedthus:

Figure 19: Save then Clear signals needed

The save pulse comes earlier than the clear—so as not to allow clear to clobber the data we’re trying to catch.You may recognize this pair of pulses, evoked by the rise of Count* (here shown as “trig,” so named for the

Page 17: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Lab 16/D3: Counters 17

terminal on the one-shot) as precisely the output of the digitally-timed one-shot that you built in Lab D2.We hope you saved that circuit. If you didn’t, you can rebuild it in about five minutes. § 16L.7.2.1 offers areminder of the circuit.

The first pulse—labelled “LatchEn*” in fig. 18 on the facing page, “save” in fig. 19 on the preceding page—will update the display. It drives the terminals labelled “Latch En*” on the LCD board (two enables*, eachcontrolling an 8-bit latch). You should join the two Latch En*’s for a 16-bit update. You should also makethe appropriate display choices:

• no labels

• 16-bit display

• two-line display

• the 8-position DIP switch on top right of the LCD board should be set to 16 (not ‘Mux’)

The transparent latch will take in new information when En* is low, then will hold this information after En*goes high.

Notice that because the display uses transparent latches rather than edge-triggered registers we need to gen-erate a pulse, not the usual edge. This example illustrates the clumsiness of such pseudo-clocking. Edge-triggering is much neater. (Then ‘Why didn’t we design it in?,’ you may ask.15)

The second pulse clears the counter when the count has been safely stored in the latches.

16L.7.2.1 Generating the required pulses: double-barreled One-Shot

Here is the one-shot that you built in Lab 14:

Figure 20: Double-barrelled one-shot: built in lab D2, we hope

Use the signal called latchen* to drive the LATCH En* of the displays.

Set the keypad value to zero, so as to load zero’s, then let Clear* drive LD*. LD*, you will recall, is theasynchronous Load. Here, we use it as an async clear: this is slightly preferable to using the synchronousRESET*, since LD* doesn’t require a clock to effectuate this version of clear.

Use a single signal from the function generator clock both one-shot and counter. (The frequency now may beas high as you like. Try 1 MHz).

Drive the one-shot input (Trig, above) and the counter’s Cin* with the manual switch. You should find thatthe circuit measures the duration of the time you hold Cin* low. (If you clock at 1 MHz, then the duration ismeasured in microseconds, of course.) Note that the count you see is in hexadecimal—a little unfamiliar tomost of us ten-fingered creatures.

When you have had enough of your period-meter, restore the counter and display connections to their former

15And you probably recall the answer: we use a transparent latch because when we want a ‘live’ display of the input levels we needonly ground EN*, and this is our usual preference. In order to produce an almost-live display using edge-triggering, we would need todrive Clock with a fast square wave. That would be a nuisance, since transparency is the usual case.

Page 18: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

18 Lab 16/D3: Counters

state, so that we can use the counter next time for its usual purpose: to provide an address for the memorythat you will install in the next lab.

lab d3 headerfile june14.tex: October 11, 2014

Here are the pin labels that we hope you will cut out and paste alongside the PAL counter’s connectors, if youare building the big-board version. (For the single-strip version we prefer to use a label-maker, instead.)

Figure 21: PAL Counter’s connector labels

Page 19: Lab 16/D3: Counters Contents - Harvard Universitysites.fas.harvard.edu/~phys123/digital_labs_premicro/lab... · 2014-10-18 · Lab 16/D3: Counters 5 16L.4.0.1 A Preview of the Counter

Index

breadboard printed-circuit, microcomputer (lab), 2–3

carrycounter carry-out glitch (lab), 14–15

counter16-bit

async load (lab), 4, 8reset, sync (lab), 4sync load (lab), 4

16-bit (lab), 4–10application

stopwatch (lab), 15–17carry-out glitch (lab), 14–15

display board (lab), 10

flip-flopone-shot, synchronous (lab) , 17

keypad (lab), 12

one-shot, synchronous (lab), 17

single-breadboard counter lab, 2stopwatch (lab), 15–17

19


Recommended