Lab 11: Bidirectional Shift Register (2024)

*/div.style_following_table_column + table tr td:first-child { background: var(--table_head_color); font-weight: bold;}div.style_following_table_column + table tr td:first-child .katex { font-size: 1em; font-weight: bold;}div.style_following_table_column2 + table tr td:nth-child(-n+2) { background: var(--table_head_color); font-weight: bold;}div.style_following_table_column2 + table tr td:nth-child(-n+2) .katex { font-size: 1em; font-weight: bold;}div.style_following_table + table th .katex { font-size: 1em; font-weight: bold; color: var(--table_even_fontcolor);}div.style_following_table + table td .katex { font-size: 1em;}div.style_following_table + table th,tr:first-child { padding-top: 0; padding-bottom: 0;}div.style_following_table + table tr td { padding-top: 0; padding-bottom: 0;}div.style_following_table + table th { background: var(--table_head_color); font-weight: bold; font-family: TimesNewRoman, Times New Roman, Times;}div.style_following_table + table tr { font-family: TimesNewRoman, Times New Roman, Times;}/*this changes tables following a special_table div*//**/div.style_following_table2 + table tr:nth-child(odd) { background: var(--table_odd_color);}div.style_following_table2 + table tr:first-child { background: var(--table_head_color); border-style: hidden; font-weight: bold; font-family: TimesNewRoman, Times New Roman, Times;}/*avoid 1.21 oversized katex font and make bold to match header rows*/div.style_following_table2 + table tr:nth-child(2n+2) { background: var(--table_odd_color); color: var(--table_even_fontcolor);}div.style_following_table2 + table tr:nth-child(2n+3) { background: var(--table_even_color); color: var(--table_odd_fontcolor);}div.style_following_table2 + table tr:nth-child(1) { border-bottom: 1pt white;}div.style_following_table2 + table th,tr:first-child { padding-top: 0; padding-bottom: 0;}div.style_following_table2 + table tr td { padding-top: 0; padding-bottom: 0;}div.style_following_table2 + table tr:nth-child(1) .katex { font-size: 1em; font-weight: bold;}div.style_following_table2 + table tr:nth-child(n+2) .katex { font-size: 1em;}/*avoid 1.21 oversized katex font*/div.style_following_table2 + table tr { font-family: TimesNewRoman, Times New Roman, Times;}/*this changes tables following a special_table2 div*//**/div.style_following_table3 + table tr:first-child { background: var(--table_head_color); border-style: hidden; font-weight: bold; font-family: TimesNewRoman, Times New Roman, Times;}div.style_following_table3 + table tr:nth-child(2) { background: var(--table_head_color); border-style: hidden; font-weight: bold; font-family: TimesNewRoman, Times New Roman, Times;}div.style_following_table3 + table tr:nth-child(2) { border-bottom: 1pt solid white;}div.style_following_table3 + table th,tr:first-child { padding-top: 0; padding-bottom: 0;}div.style_following_table3 + table tr td { padding-top: 0; padding-bottom: 0;}div.style_following_table3 + table tr:nth-child(2n+3) { background: var(--table_odd_color); color: var(--table_odd_fontcolor);}div.style_following_table3 + table tr:nth-child(2n+4) { background: var(--table_even_color); color: var(--table_even_fontcolor);}div.style_following_table3 + table tr:nth-child(1) .katex { font-size: 1em; font-weight: bold;}/*avoid 1.21 oversized katex font and make bold to match header rows*/div.style_following_table3 + table tr:nth-child(2) .katex { font-size: 1em; font-weight: bold;}div.style_following_table3 + table tr { font-family: TimesNewRoman, Times New Roman, Times;}div.style_following_table3 + table td .katex { font-size: 1em;}.markdown-preview { /* Figure Tables */ /* Hover Zoom Effect for an image in a figure */ /* Figure Class Table */ /* Caption for Non-Figure Tables caption { background-color: black; color: white; font-style: italic; padding: 2px; text-align: center; display: table-caption; caption-side: bottom ; counter-increment: figure; } */}.markdown-preview h1 { text-shadow: 1px 1px 1px #fff; margin: 1em 0 0.5em 0; font-weight: 600; font-family: 'Titillium Web', sans-serif; position: relative; font-size: 36px; line-height: 40px; padding: 15px 15px 15px 15%; color: var(--h1-color); box-shadow: inset 0 0 0 1px rgba(53, 86, 129, 0.4), inset 0 0 5px rgba(53, 86, 129, 0.5); border-radius: 0 10px 0 10px; background-image: linear-gradient(to right, #fafafa, #f0f0f0); counter-reset: h2counter;}.markdown-preview h5 { color: var(--h5-color);}.markdown-preview h6 { color: var(--h6-color);}.markdown-preview h2 { text-shadow: 1px 1px #636466; margin: 1em 0 0.5em 0; font-weight: normal; position: relative; text-shadow: 0 -1px rgba(0, 0, 0, 0.6); font-size: 28px; line-height: 40px; /*background-image: linear-gradient(to right, rgba(61, 92, 133, 0.8), rgba(53,86,129, 0.8));*/ background-image: linear-gradient(to right, var(--h2-bg-color1), var(--h2-bg-color2)); border: 1px solid #fff; padding: 5px 15px; color: var(--h2-color); border-radius: 0 10px 0 10px; box-shadow: inset 0 0 5px rgba(53, 86, 129, 0.5); font-family: 'Muli', sans-serif; clear: both; counter-increment: h2counter; counter-reset: h3counter;}.markdown-preview h2:before { content: counter(h2counter, upper-roman) ".\00202F";}.markdown-preview h3:before { content: counter(h3counter, upper-alpha) ".\00202F\00202F";}.markdown-preview h4:before { content: counter(h4counter) ")\00202F";}.markdown-preview h5:before { content: counter(h5counter, lower-roman) ".\00202F";}.markdown-preview h6:before { content: counter(h6counter) ".\00202F";}.markdown-preview h3 { margin: 1em 0 0.5em 0; font-weight: 600; font-family: 'Titillium Web', sans-serif; position: relative; text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.4); font-size: 22px; line-height: 40px; color: var(--h3-color); text-transform: uppercase; border-bottom: 1px solid rgba(53, 86, 129, 0.3); clear: both; counter-increment: h3counter; counter-reset: h4counter;}.markdown-preview h4 { margin: 1em 0 0.5em 0; font-weight: 600; font-family: 'Titillium Web', sans-serif; position: relative; font-size: 18px; line-height: 20px; color: var(--h4-color); font-family: 'Muli', sans-serif; counter-increment: h4counter; counter-reset: h5counter;}.markdown-preview h5 { counter-increment: h5counter; counter-reset: h6counter;}.markdown-preview h6 { counter-increment: h6counter;}.markdown-preview p { color: #000; text-shadow: none;}.markdown-preview .slide-instructions { display: none;}.markdown-preview .author { font-weight: 600; font-size: 22px;}.markdown-preview .grid { display: flex; justify-content: space between; flex-wrap: wrap; max-width: 800px;}.markdown-preview .left { text-align: left;}.markdown-preview .left2 { text-align: left; max-width: 400px; border: 0px solid #f00;}.markdown-preview .left2z50 { text-align: left; width: 400px; border: 0px solid #f00; transform: scale(0.5); transform-origin: top left;}.markdown-preview .left2_2 { left: -8.33%; text-align: left; width: 50%;}.markdown-preview .left3 { text-align: left; float: left; width: 266px;}.markdown-preview .left_3_2 { left: -8.33%; text-align: left; float: left; width: 66%;}.markdown-preview .right { left: 31.25%; top: 75px; float: right; text-align: right; width: 50%;}.markdown-preview .zoom33 { transform: scale(0.3333); transform-origin: top left;}.markdown-preview .zoom90 { transform: scale(0.9); transform-origin: top left;}.markdown-preview .zoom95 { transform: scale(0.95); transform-origin: top left;}.markdown-preview .zoom80 { transform: scale(0.8); transform-origin: top left;}.markdown-preview .zoom70 { transform: scale(0.7); transform-origin: top left;}.markdown-preview .zoom75 { transform: scale(0.75); transform-origin: top left;}.markdown-preview .zoom60 { transform: scale(0.6); transform-origin: top left;}.markdown-preview .zoom50 { transform: scale(0.5); transform-origin: top left;}.markdown-preview figure { margin: auto; margin-bottom: 12px; border: 1px #cccccc solid; padding: 4px; display: table; min-width: 400px;}.markdown-preview figure figcaption { background-color: var(--fig-caption-bg-color); color: var(--fig-caption-color); font-style: italic; padding: 2px; text-align: center; display: table-caption;}.markdown-preview figure:not(.table) { counter-increment: figure; border-radius: 8px 8px 0px 0px;}.markdown-preview figure figcaption { border-radius: 0px 0px 8px 8px; display: table-caption; caption-side: bottom ;}.markdown-preview figcaption:not(.table):before { content: 'Figure ' counter(figure) ': ';}.markdown-preview figure img { display: block; margin-left: auto; margin-right: auto;}.markdown-preview figure img:hover { -ms-transform: scale(1.5); /* IE 9 */ -webkit-transform: scale(1.5); /* Safari 3-8 */ transform: scale(1.5); background: white; /*border: 5px solid #555;*/ /* box-shadow: 10px 10px 5px grey;*/ box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); position: relative; z-index: 1;}.markdown-preview figure.table { counter-increment: tableCounter; border-radius: 0px 0px 8px 8px;}.markdown-preview figure.table figcaption { caption-side: top ; border-radius: 8px 8px 0px 0px;}.markdown-preview figure.table figcaption:before { content: 'Table ' counter(tableCounter) ': ';}@media print { figure { page-break-inside: avoid; } .markdown-preview h2 { color: black; background-image: none; background-color: var(--h2-bg-color-print); text-shadow: none; } form.no-print { display: none !important; height: 0; color: red; } .no-print, .no-print * { display: none !important; height: 0; color: red; } span.no-print { display: none !important; height: 0; color: red; visibility: hidden; }}Lab 11: Bidirectional Shift Register (1)

Updated Nov 2021 Robucci

Table of Contents

  • Lab 11: Bidirectional Shift Register
    • Table of Contents
    • Objective
    • Required Equipment
    • Theory and Discussion
      • Flip-flops vs Latches with Enable
      • JK Flip-Flop
      • Simulation Models
        • Minimal Functional Model using Behavioral Code
        • Provided UDP-Based Simulation Model for jh flip-flop
      • D flip-flop (DFF) constructed using a JK flip-flop
      • Shift Register
    • Prelab
    • Lab Exercise
    • Lab Report and Grading
    • Appendix

Objective

In this lab, you will be verifying the operation of a 4-bit bi-directional shift register based on a D flip-flop (DFF), which is constructed using a JK flip-flop and an inverter.

Required Equipment

  • 2x 7476: Dual JK Flip Flop with Preset & Clear
  • 2x 7408: Quad 2-input AND
  • 1x 7432: Quad 2-input OR
  • 1x 7404: Hex Inverter
  • 4x LEDs (you can use 7-seg LED also)
  • 1x Switch
  • 4x 330 Ω
  • 3x 10 kΩ

Theory and Discussion

Flip-flops vs Latches with Enable

Latches with an enable signal will have a mode to hold a signal, and another mode where inputs propagate to the output. In the case of D latch (e.g. SR-latch with S=DS=DS=D and R=DR=\overline{D}R=D), when the enable signal is asserted the output follows the input (with some delay) in a so-called transparent mode.

Flip-flops wait for a clock signal transition to propagate any single pending change to the output. There is no transparent mode.

JK Flip-Flop

The JK flip-flop has data inputs J and K with associated effects controlled by the signal clk. A SN74LS76A JK flip-flop also has PRESET and CLEAR signals (active low) that bypass the clk control, and are thus called asynchronous inputs.

Lab 11: Bidirectional Shift Register (2)

The function table show below is taken from http://www.ti.com/lit/ds/symlink/sn5476.pdf. Therein Q0Q_0Q0 is used to represent the value of Q before the condition input condition described.

Lab 11: Bidirectional Shift Register (3)

A reduced version without PRE\overline{\texttt{PRE}}PRE and CLR\overline{\texttt{CLR}}CLR can be considered, which can created using a SN74LS76A by tieing PRE\overline{\texttt{PRE}}PRE and CLR\overline{\texttt{CLR}}CLR to the power supply (high). The effective basic JK flip-flop circuit is shown below.

Lab 11: Bidirectional Shift Register (4)

When the clock signal, CLK\texttt{CLK}CLK, is low, the circuit is an a hold state, sustaining the output {Q=1,Q=0}\{Q=1,\overline Q=0\}{Q=1,Q=0} or {Q=0,Q=1}\{Q=0,\overline Q=1\}{Q=0,Q=1} using positive feedback, a loop of two inversions.

Lab 11: Bidirectional Shift Register (5)

Otherwise, after the falling edge of the clock signal the output changes based on the inputs J and K inputs. The Setup time is the amount of time that J and K must be stable at the desired values while the clock signal is high before the falling edge of the clock signal in order to see consistent behavior as described in the function table.

In your simulations, be sure to change the input signal and let it be stable for sufficient time before the falling edge of the clock.

Simulation Models

While Verilog provides built-in combinational primitives (e.g. not,nand,or), Verilog does not provide built-in sequential primitives. Therefore designers may utilize simulation models based on descriptive procedural code or user-defined primatives. Learning these is outside the scope of this course, so you will be provided a model to use in your design.

Minimal Functional Model using Behavioral Code

Here is one approach for a basic simulation model using procedural code. It could be suitable for functional simulation. You won’t use this model, but it may be of interest to some students for examination. Learning this style of procedural code modeling is outside the scope of this course.

`timescale 1ns/1psmodule jk_ff_for_illustration (q,q_n,j,k,clk); output q; output q_n; input j; input k; input clk; parameter DELAY=1; logic q_int; initial q_int=0; assign #DELAY q=q_int; assign #DELAY q_n=~q_int; always @ (negedge clk) case ({j,k}) 2'b00:q_int<=q_int; 2'b01:q_int<=0; 2'b10:q_int<=1; 2'b11:q_int<=~q_int; default:q_int<= 1'bx; endcasethis line is an intentional syntax error to dissuade useendmodule

Provided UDP-Based Simulation Model for jh flip-flop

Here is the model that you will use for this lab. You will not be required to code a model like this for this course, but at least a cursory examination is useful. You may notice the definition of a Verilog user-defined primitive (UDP) using the keywords primitive and table. The model also includes a specify block to generate a clk-to-q timing delay of 20 ns. specify blocks are processed by Icarus Verilog when the -gspecifiy option is used and ignored otherwise.

//File: jk_ff.sv`timescale 1ns/1psmodule jk_ff (q,q_n,j,k,clk,pre_n,clr_n); input j,k; output q,q_n; input clk; input pre_n,clr_n; logic pre,clr; assign q_n=~q; assign pre=~pre_n; assign clr=~clr_n; jk_ff_prim i0 (q,j,k,clk,pre,clr); specify specparam Tsu=20; specparam Th=0; specparam Tco = 20; (clk => q) = Tco; //enable 20 ns delay with -gspecify option $setup(negedge clk,j,Tsu); //not yet supported by icarus verilog $setup(negedge clk,k,Tsu); //not yet supported by icarus verilog endspecify endmodule // jk_ffprimitive jk_ff_prim (q,j,k,clk,preset,clear); output q; input j,k,clk,preset,clear; reg q; table //for UDP, only one edge is allowed per line //j k clk preset clear : old q : new q ? ? ? 1 0 : ? : 1 ; //individual aync assertions ? ? ? 0 1 : ? : 0 ; ? ? ? R ? : ? : - ; //ignore async rising edges  ? ? ? ? R : ? : - ; ? ? ? F 0 : ? : - ; //ignore single-assertion falling edge ? ? ? 0 F : ? : - ; ? ? ? 1 1 : ? : 0 ; //note that this is metastable and  // persistance after deasserting is // not well-defined  0 0 F 0 0 : ? : - ; //capture on falling edge of clk  1 0 F 0 0 : ? : 1 ; 0 1 F 0 0 : ? : 0 ; 1 1 F 0 0 : 0 : 1 ; 1 1 F 0 0 : 1 : 0 ; ? ? R 0 0 : ? : - ; //ignore rising edge of clk * ? ? 0 0 : ? : - ; // ignore edges on j ? * ? 0 0 : ? : - ; // ignore edges on k endtable endprimitive

The user-defined primative model also includes a specification of setup time violations, but unfortunately these are not implemented by Icarus Verilog at the time of this writing. If you perform the simulations on commercial simulations such as Cadence Xcelium (available via edaplayground.com ) warning can be generated. You will learn to use commercial simulators available at UMBC in later courses.

Here Example Warning Reported by Cadence Xcelium. This is not implemented in Icarus Verilog.

Warning! Timing violation $setup( negedge clk:4 NS, j:5 NS, 20.000 : 20 NS ); File: ./design.sv, line = 48 Scope: test.dut Time: 5 NS

Here is a testbench that you can start with to verify your understanding of the operation of a JK Flip-Flop.

//File: jk_ff_tb.v`timescale 1ns/1psmodule jk_ff_tb; reg q,q_n,w1,w2; logic clk,j,k; logic pre_n; logic clr_n; jk_ff dut (q,q_n,j,k,clk,pre_n,clr_n); initial begin $display("j,k,clk,pre_n,clr_n,q,q_n,time"); $monitor(j,k," ",clk," ",clr_n,pre_n," ",q,q_n,$time); j=0; k=0; clk=0; pre_n=1;clr_n=1; //fill in code here $finish; end endmodule

To compile the design including the specify block, use the sepcify flag by including the option -gspecify. Additionally the option -Wall displays more warnings than the default.

The following generates the executable jk_ff_tb:

iverilog -gspecify -Wall -g2012 jk_ff_tb.v jk_ff.v -o jk_ff_tb

Depending on the platform, you may need to run vvp or just the executable directly.

vvp ./jk_ff_tb

or

./jk_ff_tb

D flip-flop (DFF) constructed using a JK flip-flop

A JK flip-flop can be used to build a 1-bit data storage element by connecting J to an a data signal and K to an inverted version of the signal.

Lab 11: Bidirectional Shift Register (6)

JKQ(next)Q^{(next)}Q(next)
00QQQ
010
101
11Q\overline{Q}Q
inputintermediateoutput
DJKQ(next)Q^{(next)}Q(next)
0010
1101

Shift Register

The term register in digital logic can be used to generalize a collection of flip-flops used to store a digital word. Typically a register and word are distinguished by being associated with more than one bit, though a 1-bit register is conceptually valid.

In this lab you will make a Shift Register. A shift register is a cascade of flip-flops (can be any type; JK, D, T, etc…), where each flip-flop holds one bit of a binary number, and all of the flip-flops share the same clock signal. On every negative clock edge, the values held in the flip-flops will shift over to their neighboring flip-flops. The “Right/Left” wire determines which way they will shift. The value on the “Data In” wire is written to the empty flip-flop on the end.

Lab 11: Bidirectional Shift Register (7)

Here are some example behaviors, assuming that the stored binary number is denoted by Q[3,2,1,0].

  • Right Shift
    • If Q[3,2,1,0] == 0110, DataIn=0, R/L_n=1, the next value of Q[3,2,1,0] will be 0011.
    • If Q[3,2,1,0] == 0110, DataIn=1, R/L_n=1, the next value of Q[3,2,1,0] will be 1011.
  • Left Shift
    • If Q[3,2,1,0] == 0110, DataIn=0, R/L_n=0, the next value of Q[3,2,1,0] will be 1100.
    • If Q[3,2,1,0] == 0110, DataIn=1, R/L_n=0, the next value of Q[3,2,1,0] will be 1101.

Notice that we are wiring the K’s so that they are always the inverse of the J’s. When JK flip-flops are wired this way, they are synthesizing (or acting like) a D flip-flop.

Lab 11: Bidirectional Shift Register (8)

Next, notice how the combinational logic gates control the bit shifts.
With attention to the 2nd circle, observe that both Q3 and Q1 are fed into the AND gates.
If R/L_n = 0 (left shift), then Q1 is chosen to fill the F2 flip-flop.
If R/L_n = 1, then Q3 is chosen.

Lab 11: Bidirectional Shift Register (9)

When a shift register can either shift left or right (ability to perform both operations), it’s called a bidirectional shift register.

Prelab

  1. Complete the testbench, jk_ff_tb.sv, demonstrating behavior the behavior of the provided JK Flip-Flop. Perform the simulation and provide the results.
  2. Create a new module called d_ff, which uses the provided jf_ff and an inverter (inv) together to contruct a D Flip-Flop. Complete a new testbench d_ff_tb.sv demonstrating the behavior of the d_ff module. Perform the simulation and provide the results.

Lab Exercise

Build and demontrate the 4-bit bidirectional shift register.

  1. For both the 74LS76 ICs, Pin# 2, 3, 5, 7, 8 have to be connected to Vcc and Pin #13 has to be connected to Ground. Note that the Vcc and GND pins are different from the normal ICs.
  2. Build the above circuit taking pin #15 and pin #11 of the first IC (7476) as Q0 and Q1, respectively and pin #15 and pin #11 of the second IC (7476) as Q2 and Q3, respectively.
  3. There are 3 inputs to the circuit, namely, DataIn, Right/Left_n (Direction), CLK. All of them should be connected to a switch.
  4. Pins #1 and #6 for both 74LS76 ICs should be connected to the CLK input.
  5. A single CLK pulse is triggered by changing from HI to LO (Since the FF is negative edge triggered). Make sure to bring the CLK to HI before triggering the second pulse.
  6. At every clock pulse triggered, the data will be shifted according to the Direction bit value. Refer to the following table for some examples.
  7. The shift register is set to 0000 by having DataIn set to 0 and giving 4 CLK pulses.
  8. See the Logic symbol and Pin diagram for the J and K inputs for the flip flops in the Appendix.
CLKDirectionDataInData Out (Current)Data Out (New)
LO–>HIXX11001100
HI–>LO1 (Right)111001110
HI–>LO1 (Right)011000110
HI–>LO1 (Right)110101101
HI–>LO1 (Right)011110111
HI–>LO0 (Left)101101101
HI–>LO0 (Left)011111110
HI–>LO0 (Left)100000001
HI–>LO0 (Left)010100100

Lab Report and Grading

  • The prelab will be worth 20%
    • Submit Verilog Code, including completed Testbench code, and simulation output results
  • Lab Exercise 60%
  • Lab Report 20%

Appendix

Lab 11: Bidirectional Shift Register (10)
Lab 11: Bidirectional Shift Register (11)Lab 11: Bidirectional Shift Register (12)

Lab 11: Bidirectional Shift Register (13)

Lab 11: Bidirectional Shift Register (14)

  • Lab 11: Bidirectional Shift Register
    • Table of Contents
    • Objective
    • Required Equipment
    • Theory and Discussion
      • Flip-flops vs Latches with Enable
      • JK Flip-Flop
      • Simulation Models
        • Minimal Functional Model using Behavioral Code
        • Provided UDP-Based Simulation Model for jh flip-flop
      • D flip-flop (DFF) constructed using a JK flip-flop
      • Shift Register
    • Prelab
    • Lab Exercise
    • Lab Report and Grading
    • Appendix
Lab 11: Bidirectional Shift Register (2024)

References

Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 5635

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.