1 / 29

Review: Counters and Registers

Review: Counters and Registers. CS 231 Review October 26, 2007. Please note the NOTES in the PPT file for help with the examples. By Joshua Smith. Announcements. HW 7 Due at 5:00pm on 10/29/2007 (Mon) Contains one LogicWorks problem Midterm Exam 2 Monday, November 5, 7-9pm 1404 SC

teal
Télécharger la présentation

Review: Counters and Registers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Review: Counters and Registers CS 231 Review October 26, 2007 Please note the NOTES in the PPT file for help with the examples By Joshua Smith

  2. Announcements • HW 7 • Due at 5:00pm on 10/29/2007 (Mon) • Contains one LogicWorks problem • Midterm Exam 2 • Monday, November 5, 7-9pm • 1404 SC • ~10 days from today • Cover ALU through PLA’s • HW 8 • Not due until November 12 • 1 week after Midterm 2

  3. Agenda • Counters • Registers

  4. 1 10 00 1 1 01 11 1 Introducing counters • Counters are a specific type of sequential circuit. • The state, or the flip-flop values themselves, serves as the “output.” • The output value increases by one on each clock cycle. • After the largest value, the output “wraps around” back to 0. • Using two bits, we’d get something like this: • We’ll soon look at some extensions to this basic idea.

  5. What good are counters? • Counters can act as simple clocks to keep track of “time.” • You may need to record how many times something has happened. • How many bits have been sent or received? • How many steps have been performed in some computation? • All processors contain a program counter, or PC. • Programs consist of a list of instructions that are to be executed one after another (for the most part). • The PC keeps track of the instruction currently being executed. • The PC increments once on each clock cycle, and the next program instruction is then executed.

  6. 000 001 011 101 010 100 Unused states • The examples shown so far have all had 2n states, and used n flip-flops. But sometimes you may have unused, leftover states. • For example, here is a state table and diagram for a counter that repeatedly counts from 0 (000) to 5 (101). • What should we put in the table for the two unused states?

  7. 000 001 011 101 010 100 Unused states can be don’t cares… • To get the simplest possible circuit, you can fill in don’t cares for the next states. This will also result in don’t cares for the flip-flop inputs, which can simplify the hardware. • If the circuit somehow ends up in one of the unused states (110 or 111), its behavior will depend on exactly what the don’t cares were filled in with.

  8. 000 001 011 101 110 010 111 100 …or maybe you do care • To get the safest possible circuit, you can explicitly fill in next states for the unused states 110 and 111. • This guarantees that even if the circuit somehow enters an unused state, it will eventually end up in a valid state. • This is called a self-starting counter.

  9. LogicWorks counters • There are a couple of different counters available in LogicWorks. • The simplest one, the Counter-4 Min, just increments once on each clock cycle. • This is a four-bit counter, with values ranging from 0000 to 1111. • The only “input” is the clock signal.

  10. More complex counters • More complex counters are also possible. The full-featured LogicWorks Counter-4 device below has several functions. • It can increment or decrement, by setting the UP input to 1 or 0. • You can immediately (asynchronously) clear the counter to 0000 by setting CLR = 1. • You can specify the counter’s next output by setting D3-D0 to any four-bit value and clearing LD. • The active-low EN input enables or disables the counter. • When the counter is disabled, it continues to output the same value without incrementing, decrementing, loading, or clearing. • The “counter out” CO is normally 1, but becomes 0 when the counter reaches its maximum value, 1111.

  11. An 8-bit counter • As you might expect by now, we can use these general counters to build other counters. • Here is an 8-bit counter made from two 4-bit counters. • The bottom device represents the least significant four bits, while the top counter represents the most significant four bits. • When the bottom counter reaches 1111 (i.e., when CO = 0), it enables the top counter for one cycle. • Other implementation notes: • The counters share clock and clear signals. • Hex displays are used here.

  12. A restricted 4-bit counter • We can also make a counter that “starts” at some value besides 0000. • In the diagram below, when CO=0 the LD signal forces the next state to be loaded from D3-D0. • The result is this counter wraps from 1111 to 0110 (instead of 0000).

  13. Another restricted counter • We can also make a circuit that counts up to only 1100, instead of 1111. • Here, when the counter value reaches 1100, the NAND gate forces the counter to load, so the next state becomes 0000.

  14. Example Below is a Counter-4 from LogicWorks. The possible operations on every positive clock edge are summarized in the abbreviated table.

  15. Example Also, the output CO is 0 only when the counter’s current state is 1111 and UP=1, or when the current state is 0000 and UP=0: CO = ( Q3Q2Q1Q0UP + Q3’Q2’Q1’Q0’UP’ )’

  16. Example Show how you can add primitive gates only to make Q3Q2Q1Q0 count in the following repeating sequence. 7, 6, 5, 4, 3, 2, 1, 0, 8, 9, 10, 11, 12, 13, 14, 15, …

  17. Example Show how you can add primitive gates only to make Q3Q2Q1Q0 count in the following repeating sequence. 7, 6, 5, 4, 3, 2, 1, 0, 8, 9, 10, 11, 12, 13, 14, 15, …

  18. Example UP = Q3 LD = Q3’Q2’Q1’Q0’ + Q3Q2Q1Q0 D3 = Q3’ D2 = Q2 D1 = Q1 D0 = Q0

  19. Example UP = Q3 LD = Q3’Q2’Q1’Q0’ + Q3Q2Q1Q0 = CO D3 = Q3’ D2 = Q2 D1 = Q1 D0 = Q0

  20. Agenda • Counters • Registers

  21. What good are registers? • Flip-flops are limited because they can store only one bit. • We had to use two flip-flops for our two-bit counter examples. • Most computers work with integers and single-precision floating-point numbers that are 32-bits long. • A register is an extension of a flip-flop that can store multiple bits. • Registers are commonly used as temporary storage in a processor. • They are faster and more convenient than main memory. • More registers can help speed up complex calculations. • We’ll discuss RAM next time, and later we’ll also see how registers are used in designing and programming CPUs.

  22. A better parallel load • Another idea is to modify the flip-flop D inputs and not the clock signal. • When LD = 0, the flip-flop inputs are Q3-Q0, so each flip-flop just keeps its current value. • When LD = 1, the flip-flop inputs are D3-D0, and this new value is “loaded” into the register.

  23. Shift registers • A shift register “shifts” its output once every clock cycle. • SI is an input that supplies a new bit to shift “into”the register. • For example, if on some positive clock edge we have: SI = 1 Q0-Q3 = 0110 then the next state will be: Q0-Q3 = 1011 • The current Q3 (0 in this example) will be lost on the next cycle. Q0(t+1) = SI Q1(t+1) = Q0(t) Q2(t+1) = Q1(t) Q3(t+1) = Q2(t)

  24. Shift direction • The circuit and example make it look like the register shifts “right.” • But it really depends on your interpretation of the bits. If you consider Q3 to be the most significant bit instead, then the register is shifting in the opposite direction! Q0(t+1) = SI Q1(t+1) = Q0(t) Q2(t+1) = Q1(t) Q3(t+1) = Q2(t)

  25. Shift registers with parallel load • We can add a parallel load, just like we did for regular registers. • When LD = 0, the flip-flop inputs will be SIQ0Q1Q2, so the register shifts on the next positive clock edge. • When LD = 1, the flip-flop inputs are D0-D3, and a new value is loaded into the shift register, on the next positive clock edge.

  26. Shift registers in LogicWorks • Here is a block symbol for the Shift Reg-4 from LogicWorks. The implementation is shown on the previous page, except the LD input here is active-low instead.

  27. Other types of shift registers • Logical shifts – Standard shifts like we just saw. In the absence of a SI input, 0 occupies the vacant position. • Left: 0110 -> 1100 • Right: 0110 -> 0011 • Circular shifts (also called ring counters or rotates) – The shifted out bit wraps around to the vacant position. • Left: 1001 -> 0011 • Right: 1001 -> 1100 • Switch-tail ring counter (aka Johnson counter) – Similar to the ring counter, but the serial input is the complement of the serial output. • Left: 1001 -> 0010 • Right: 1001 -> 0100 • Arithmetical shifts – Left shifting is the same as a logical shift. Right shifting however maintains the MSB. • Left: 0110 -> 1100 • Right: 0110 -> 0011; 1011 -> 1101

  28. Arithmetic Shift Left Shift

  29. Arithmetic Shift Right Shift

More Related