Created
November 5, 2014 18:09
-
-
Save fernandoc1/25a24a8950173371344a to your computer and use it in GitHub Desktop.
Register example in Verilog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Register(clock, r_enable, data_in, data_out); | |
input clock; | |
input r_enable; | |
input [15:0] data_in; | |
output reg [15:0] data_out; | |
always @(posedge clock) | |
begin | |
if(r_enable) | |
data_out <= data_in; | |
end | |
endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`include "Register.v" | |
module RegisterTestbench; | |
reg clock = 0; | |
reg enable = 1; | |
reg [15:0] value_in; | |
wire [15:0] value_out; | |
always #1 clock = !clock; | |
initial $dumpfile("registertestbench.vcd"); | |
initial $dumpvars(0, RegisterTestbench); | |
Register r(clock, enable, value_in, value_out); | |
initial begin | |
//These events must be in chronological order. | |
# 5 value_in = 31; | |
# 5 value_in = 127; | |
# 5 enable = 0; | |
# 5 value_in = 1023; | |
# 5 $finish; | |
end | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this, use:
iverilog RegTestbench.v
An to display the result, just use gtkwave:
gtkwave registertestbench.vcd
Output at: http://en.zimagez.com/zimage/screenshot-05-11-2014-1613320.php