Docsity

Logic Circuit Lab: Exploring Flip-Flops and Counters in ECE241, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE241
Logic Circuit Lab Lab #6; Page 1/5
Spring 2004
Circuits with Feedback
Due: By 6:00pm on Wednesday April 28.
So far, all our circuits have been purely combinational. The outputs are only a function of the current
inputs. If we can define a problem in terms of truth-tables, we can build a combinational circuit that will
implement it.
However, there are many problems of interest that require that we solve them by completing several
steps, one step at a time in a sequential manner. The next step taken may well depend not only on the
current inputs to the circuit, but also on which step was just completed. Circuits that operate this way are
referred to as sequential circuits or state machines. Sequential circuits differ from purely combinational
circuits in that the current outputs of a sequential circuit may not only be a function of present inputs,
but also of past inputs.
The objective of this lab is to explore options for implementing flip-flops and to characterize their
behavior. You will also combine several flip-flops to create a binary counter.
1 Implementing Latches and Flip-Flops
1.1 Schematic Entry
First, you can implement the circuit directly, using NAND gates and inverters using the schematic entry
program. However, you can also take advantage of the built-in flip-flop components in schematic entry.
For example, the component FD is a D-flip-flop and FD 1is a D-flip flop with a negative edge triggered
clock. There also components for other types of flip-flops, and ones with enable, preset and clear inputs.
1.2 Hardware Description Languages
Flip-flops and latches can also be implemented using a hardware description language such as VHDL or
Verilog. If we wanted to implement a S-R latch in VHDL we could use the following code:
library IEEE;
use IEEE.std_logic_1164.all;
entity srlat is
port (
sb: in STD_LOGIC; --active low set input
rb: in STD_LOGIC; --active low reset input
q: buffer STD_LOGIC; --data output
qb: buffer STD_LOGIC; --inverted data output
);
end srlat;
pf3
pf4
pf5

Partial preview of the text

Download Logic Circuit Lab: Exploring Flip-Flops and Counters in ECE241 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

Logic Circuit Lab Spring 2004

Circuits with Feedback

Due: By 6:00pm on Wednesday April 28. So far, all our circuits have been purely combinational. The outputs are only a function of the current inputs. If we can define a problem in terms of truth-tables, we can build a combinational circuit that will implement it. However, there are many problems of interest that require that we solve them by completing several steps, one step at a time in a sequential manner. The next step taken may well depend not only on the current inputs to the circuit, but also on which step was just completed. Circuits that operate this way are referred to as sequential circuits or state machines. Sequential circuits differ from purely combinational circuits in that the current outputs of a sequential circuit may not only be a function of present inputs, but also of past inputs. The objective of this lab is to explore options for implementing flip-flops and to characterize their behavior. You will also combine several flip-flops to create a binary counter.

1 Implementing Latches and Flip-Flops

1.1 Schematic Entry

First, you can implement the circuit directly, using NAND gates and inverters using the schematic entry program. However, you can also take advantage of the built-in flip-flop components in schematic entry. For example, the component FD is a D-flip-flop and FD 1 is a D-flip flop with a negative edge triggered clock. There also components for other types of flip-flops, and ones with enable, preset and clear inputs.

1.2 Hardware Description Languages

Flip-flops and latches can also be implemented using a hardware description language such as VHDL or Verilog. If we wanted to implement a S-R latch in VHDL we could use the following code:

library IEEE; use IEEE.std_logic_1164.all;

entity srlat is port ( sb: in STD_LOGIC; --active low set input rb: in STD_LOGIC; --active low reset input q: buffer STD_LOGIC; --data output qb: buffer STD_LOGIC; --inverted data output ); end srlat;

Logic Circuit Lab Spring 2004

architecture srlat_arch of srlat is begin q <= NOT(sb and qb); --cross-coupled NAND gates qb <= NOT(rb and q); end srlat_arch;

However, we can also create a behavioral model. In this case, we’ll look at a SR flip-flop with a clock input. The key to the behavior model is the PROCESS function. This is only entered when one of the parameters passed with the statement changes.

library IEEE; use IEEE.std_logic_1164.all;

entity srff is port ( c: in STD_LOGIC; --clock sb: in STD_LOGIC; --active low set input rb: in STD_LOGIC; --active low reset input q: buffer STD_LOGIC; --data output qb: OUT STD_LOGIC; --inverted data output ); end srff;

architecture srff_arch of srff is begin PROCESS (c,sb,rb) --entered only when c, sb, rb changes BEGIN IF c=’1’ THEN --change state only when the clock is high IF (sb=’0’) THEN q <=’1’; ELSIF (rb=’0’) THEN q <=’0’; END IF; END IF; END PROCESS; qb <= NOT(q); --generate the inverted output end srff_arch;

Logic Circuit Lab Spring 2004

2 Preliminary Questions

T here are no preliminary questions for this lab

  1. Implement the negative edge triggered D flip-flip shown below using the following methods. Run a timing simulation on each and comment on the differences you see (if any) and suggest possible causes. Make sure you use the correct FPGA. Step the inputs using a master clock for the clock input and a switch for the D input. Turn in the appropriate circuit schematics, timing results, and VHDL code.

/P /R

/S Q

/Q

D

C

/R

/S P

a Implement directly using NAND gates and inverters in schematic entry. b Implement using the negative edge triggered flip-flop component in the Xilinx software c Implement using a VHDL behavioral model, create a symbol for this, simulate, and compare to parts a and b.

  1. Perform a timing simulation using the built-in T flip-flop component in the schematic entry. Also implement a T flip-flop using a D flip-flop as shown in the figure. Compare the timing simulation results. Turn in circuit schematics and timing plots.

D Q

T=CLK

  1. Implement a 3 bit binary up and down counter using 3 D flip-flops as shown in the figure. Use appropriate multiplexers and decoders that would allow you to display the count value on one of the seven segment displays. Use a switch to control the direction of count, up or down. Step through the entire count sequence and show on a timing plot. Turn in the schematic and timing diagram.

Logic Circuit Lab Spring 2004

D D

Q1 Q

Binary Value = (Q2 Q1 Q0)

D

Q

CLK

3 The Lab

  1. Implement part ( a ) of Preliminary Question 1 in TTL on the breadboard as you did in lab one and have the TA pass the circuit off. Use a switch for the input D, an LED for Q, and a function generator for the clock.
  2. Pass off your counter circuit from Preliminary Question 3 by showing the TA the timing simulation.
  3. Download your counter from Preliminary Question 3 to the digilab board. You will need to use the function generator on the lab bench as your clock input and a switch for the control of the up or down count. Also, the function generator needs to be about 1 Hz. Use the seven segment display to show the count. Have the TA pass off on the design. The TA can help connecting the function generator.
  4. Implement the counter using 3 D flip-flops as in part 3 using TTL IC’s on a breadboard. For this, use a function generator as the clock input, and display the up count with three LEDs on the breadboard. Have the TA pass off on the circuit.