SAIFIINDUSTRIES's picture
Add Batch 1 with 10 repos
8dc19e4 verified
Raw
History Blame Contribute Delete
1.24 kB
// Dual D flip-flop with set and clear; positive-edge-triggered
// Note: Preset_bar is synchronous, not asynchronous as specified in datasheet for this device,
// in order to meet requirements for FPGA circuit design (see IceChips Technical Notes)
module ttl_7474 #(parameter BLOCKS = 2, DELAY_RISE = 0, DELAY_FALL = 0)
(
input [BLOCKS-1:0] Preset_bar,
input [BLOCKS-1:0] Clear_bar,
input [BLOCKS-1:0] D,
input [BLOCKS-1:0] Clk,
output [BLOCKS-1:0] Q,
output [BLOCKS-1:0] Q_bar
);
//------------------------------------------------//
reg [BLOCKS-1:0] Q_current;
reg [BLOCKS-1:0] Preset_bar_previous;
generate
genvar i;
for (i = 0; i < BLOCKS; i = i + 1)
begin: gen_blocks
always @(posedge Clk[i] or negedge Clear_bar[i])
begin
if (!Clear_bar[i])
Q_current[i] <= 1'b0;
else if (!Preset_bar[i] && Preset_bar_previous[i]) // falling edge has occurred
Q_current[i] <= 1'b1;
else
begin
Q_current[i] <= D[i];
Preset_bar_previous[i] <= Preset_bar[i];
end
end
end
endgenerate
//------------------------------------------------//
assign #(DELAY_RISE, DELAY_FALL) Q = Q_current;
assign #(DELAY_RISE, DELAY_FALL) Q_bar = ~Q_current;
endmodule