Latches and Flip-Flops Discussion D7.1
Latches and Flip-Flops SR Latch D Latch Flip-Flops D Flip-Flop JK Flip-Flop T Flip-Flop
Sequential Logic Combinational Logic Sequential Logic Output depends only on current input Sequential Logic Output depends not only on current input but also on past input values Need some type of memory to remember the past input values
Cross-coupled Inverters State 1 State 2
Latches and Flip-Flops SR Latch D Latch Flip-Flops D Flip-Flop JK Flip-Flop T Flip-Flop
SR Latch S' R' Q Q' 1 0 0 0 1 1 0 1 1 1 1 0 1 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 0 0 0 1 1 0 1 1 1 1 0 1 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 0 0 0 1 1 0 1 1 1 1 0 1 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 0 0 0 1 1 0 1 1 1 0 Set 1 0 1 X Y nand 0 0 1 1 0 0 0 1 1 0 1 1 1 0 Set 1 0 1 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 1 0 0 0 1 1 0 1 1 1 0 Set 1 0 1 Store 1 0 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 1 0 0 0 1 1 0 1 0 Set 1 1 0 1 Store 1 0 X Y nand 0 0 0 1 1 0 1 1 1 0 Set 0 1 Store 1 0 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 1 0 0 0 1 1 0 1 1 1 0 Set 1 0 1 Store 1 0 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 0 0 0 1 1 0 1 0 Set 1 1 0 1 Reset 1 0 1 Store 0 0 0 1 1 0 1 1 1 0 Set 0 1 Reset 1 0 1 Store 1 0 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 0 0 0 1 1 0 1 1 1 0 Set 0 1 Reset 1 1 0 1 Store 0 0 0 1 1 0 1 1 1 0 Set 0 1 Reset 1 1 0 1 Store 1 0 X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 0 0 1 1 Disallowed 0 1 1 0 1 0 Set 1 1 0 1 Reset 1 0 0 0 1 1 0 1 1 1 1 Disallowed 1 0 Set 0 1 Reset 1 0 1 Store 1 0 Q0 Q0' X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
SR Latch S' R' Q Q' 1 0 0 0 1 1 0 1 1 1 1 Disallowed 1 0 Set 0 1 Reset 0 0 0 1 1 0 1 1 1 1 Disallowed 1 0 Set 0 1 Reset 1 1 0 1 Store 1 0 Q0 Q0' X Y nand 0 0 1 0 1 1 1 0 1 1 1 0 To close or lock with or as if with a latch, To catch or fasten
SR Latch with Enable S R EN S' R' Q Q' 0 0 1 1 1 Q0 Q0' Store 0 1 1 1 0 0 1 Reset 1 0 1 0 1 1 0 Set 1 1 1 0 0 1 1 Disallowed X X 0 1 1 Q0 Q0' Store
RS Latch RS Latch R S Q Q is set to 1 when S is asserted, and remains unchanged when S is disasserted. Q is reset to 0 when R is asserted, and remains unchanged when R is disasserted. Assertions can be active HIGH or active LOW
R Q RS Latch S Active HIGH library IEEE; use IEEE.STD_LOGIC_1164.all; entity rslatch is port( R : in STD_LOGIC; S : in STD_LOGIC; Q : out STD_LOGIC ); end rslatch; architecture rslatch of rslatch is begin process(R,S) if S = '1' and R = '0' then Q <= '1'; elsif S = '0' and R = '1' then Q <= '0'; end if; end process; RS Latch R S Q Active HIGH
RS Latch -- Active High
R Q RS Latch S Active LOW library IEEE; use IEEE.STD_LOGIC_1164.all; entity rslatch is port( R : in STD_LOGIC; S : in STD_LOGIC; Q : out STD_LOGIC ); end rslatch; architecture rslatch of rslatch is begin process(R,S) if S = '0' and R = '1' then Q <= '1'; elsif S = '1' and R = '0' then Q <= '0'; end if; end process; RS Latch R S Q Active LOW
RS Latch -- Active Low
How can you make this RS latch from gates? Q Q is set to 1 when S is asserted, and remains unchanged when S is disasserted. Q is reset to 0 when R is asserted, and remains unchanged when R is disasserted. Assertions can be active HIGH or active LOW
Q is set to 1 when S is asserted (1), and remains unchanged when S is disasserted (0). Q is reset to 0 when R is asserted (1), and remains unchanged when R is disasserted (0). R S Q Q 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 R SQ 00 01 11 10 1 store 1 1 1 set 1 reset store Q = R'Q + R'S + SQ RS Latch R S Q
RS Latch Q = R'Q + R'S + SQ R S Q Q 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 store set reset store RS Latch R S Q Q = R'Q + R'S + SQ
use IEEE.STD_LOGIC_1164.all; entity rslatchgates is port( library IEEE; use IEEE.STD_LOGIC_1164.all; entity rslatchgates is port( R : in STD_LOGIC; S : in STD_LOGIC; Q : out STD_LOGIC ); end rslatchgates; architecture rslatchgates of rslatchgates is signal Q1: std_logic; begin Q1 <= (not R and Q1) or (not R and S) or (S and Q1); Q <= Q1; Q1
Latches and Flip-Flops SR Latch D Latch Flip-Flops D Flip-Flop JK Flip-Flop T Flip-Flop
D Latch D Latch D EN Q Q follows D when EN is high, and remains unchanged when EN is low..
D Q D Latch EN library IEEE; use IEEE.STD_LOGIC_1164.all; entity dlatch is port( D : in STD_LOGIC; EN : in STD_LOGIC; Q : out STD_LOGIC ); end dlatch; architecture dlatch of dlatch is begin process(D,EN) if EN = '1' then Q <= D; end if; end process; D Latch D EN Q
D Latch
D Latch S S' R' R S R EN Q Q' D EN Q Q' 0 0 1 Q0 Q0' Store 0 1 0 1 0 1 1 0 1 Reset 1 0 1 1 0 Set 1 1 1 1 1 Disallowed X X 0 Q0 Q0' Store 0 1 0 1 1 1 1 0 X 0 Q0 Q0' D EN Q Q'
D Latch S S' R' R D EN Q Q' Note that Q follows D when EN in high, 0 1 0 1 1 1 1 0 X 0 Q0 Q0' D EN Q Q' Note that Q follows D when EN in high, and is latched when EN goes to zero.
Latches and Flip-Flops SR Latch D Latch Flip-Flops D Flip-Flop JK Flip-Flop T Flip-Flop
D Flip-Flop D gets latched to Q on the rising edge of the clock. clk D Q Q' 0 0 1 1 1 0 X 0 Q0 Q0' D clk Q Q' Positive edge triggered D gets latched to Q on the rising edge of the clock. Behavior if rising_edge(clk) then Q <= D; end if;
D Q clk Q' library IEEE; use IEEE.STD_LOGIC_1164.all; entity dflipflop is port( D : in STD_LOGIC; clk : in STD_LOGIC; Q : out STD_LOGIC; NotQ : out STD_LOGIC ); end dflipflop; architecture dflipflop of dflipflop is signal QS: STD_LOGIC; begin process(D,clk) if rising_edge(clk) then QS <= D; end if; end process; Q <= QS; NotQ <= not QS; clk D Q Q'
D Flip-Flop
D Q clk Q' library IEEE; use IEEE.STD_LOGIC_1164.all; entity dflipflop is port( D : in STD_LOGIC; clk : in STD_LOGIC; Q : out STD_LOGIC; NotQ : out STD_LOGIC ); end dflipflop; architecture dflipflop of dflipflop is signal QS: STD_LOGIC; begin process(D,clk) if clk'event and clk = '1' then QS <= D; end if; end process; Q <= QS; NotQ <= not QS; clk D Q Q'
D Flip-Flop
Master-Slave D Flip-Flop
Master-Slave D Flip-Flop
Recall the SR Latch S' R' Q Q' 1 0 0 1 1 Disallowed 0 1 1 0 1 0 Set 1 0 0 0 1 1 0 1 1 1 1 Disallowed 1 0 Set 0 1 Reset 1 0 1 Store 1 0 Q0 Q0' X Y nand 0 0 1 0 1 1 1 0 1 1 1 0
Edge-triggered D Flip-flop 1 1 1 1
Edge-triggered D Flip-flop 1 1 1 1 1
Edge-triggered D Flip-flop 1 1 1 1 1
Edge-triggered D Flip-flop 1 1 1 1
Edge-triggered D Flip-flop 1 1 1 1
Edge-triggered D Flip-flop 1 1 1 1 1
Edge-triggered D Flip-flop 1 1 1 1 1
Spartan 3 CLB slices
Latches and Flip-Flops SR Latch D Latch Flip-Flops D Flip-Flop JK Flip-Flop T Flip-Flop
J-K Flip-flops J K Qnext 0 0 Q 0 1 0 1 0 1 1 1 Q' Qnext = JQ' + K'Q
J-K Flip-flops J K Qnext 0 0 Q 0 1 0 1 0 1 1 1 Q'
Latches and Flip-Flops SR Latch D Latch Flip-Flops D Flip-Flop JK Flip-Flop T Flip-Flop
T Flip-flops T Qnext 0 Q 1 Q'
T Flip-flops T Qnext 0 Q 1 Q'