the enable input is high. It has one output Q and two inputs, D and en. Since Q is evaluated in a procedural statement, it must be declared as register type. D-latch responds to input signal levels, so the two inputs are listed without edge qualifiers in the event enable expression following the @ symbol in the always statement. it has only one blocking procedural assignment statement and it also specifies the transfer of D-input to Q-output if logic 1 i.e when enable is true. This statement is executed every time when there is a change in input D if enable is logic1.
module D-latch (Q, 0, en); // en is enable
output Q;
Input D, en;
reg Q;
always @ (en or D)
If (en) Q <= D; //Same as: If (enable == 1)
endmodule
// Alternative syntax
module D-latch (output reg Q, input enable, D);
always @ (enable, D)
If (enable) Q <= D; // No action if enable not asserted
endmodule
Here is an
example of VHDL code for a D-latch:
And here is
an example of Verilog code for a D-latch:
Both codes
define a D-latch module with inputs D and clk, and an output Q. The D-latch is
a level sensitive device and uses the input D as the data input, and the input
clk as the enable input.
In the VHDL code, the process
is sensitive to the clock input and the output Q is assigned the value of the
input D when there is a rising edge on the clock input.
In the Verilog code, the always
block is triggered on the rising edge of the clock input and assigns the value
of the input D to the output Q.
Both codes implements the same
functionality and are equivalent. Please note that this is a basic example and
the actual code may depend on the specific requirements of your design.
No comments:
Post a Comment