FDRS: D flip-flop with synchronous Reset/Set
FDRS is a D-type flip-flop with synchronous active-high reset (R) and set (S) inputs. The R and S inputs are examined in priority order during the low-to-high transition of the clock (C) input. If R is asserted, Q is set to 0. Otherwise, if S is asserted, Q is set to 1. Otherwise, Q is loaded with the data on the D input. |
Verilog
module FDRS( input R, S, D, C, output reg Q); always @(posedge C) if(R) Q <= 0; else if(S) Q <= 1; else Q <= D; endmodule
VHDL
library IEEE; use IEEE.std_logic_1164.all; entity FDRS is port ( R, S, D, C : in std_logic; Q : out std_logic); end entity FDRS; architecture A of FDRS is begin process (C) is begin if rising_edge(C) then if R = '1' then Q <= '0'; elsif S = '1' then Q <= '1'; else Q <= D; end if; end if; end process; end architecture A;
Testbench
DUT { module FDRS(input R, S, D, C, output Q) create_clock C [R, S, D, C] -> [Q] } [1, 0, 1, .C] -> [0] // sync reset [0, 1, 0, .C] -> [1] // sync set [0, 0, 0, .C] -> [0] // 1->0 [0, 0, 1, .C] -> [1] // 0->1 [1, 1, 1, .C] -> [0] // sync reset, overrides S