实验:
实验一:
//compare.v
module compare (equal , a , b) ;
input a , b ;
output equal ;
assign equal = (a == b) ? 1 : 0 ;
endmodule
//t.v
`timescale 1 ns/1 ns
`include "./compare.v"
module t ;
reg a , b ;
wire equal ;
initial
begin
a = 0 ;
b = 0 ;
#100 a = 0 ; b = 1 ;
#100 a = 1 ; b = 1 ;
#100 a = 1 ; b = 0 ;
#100 a = 0 ; b = 0 ;
#100 $stop ;
end
compare m(.equal(equal),.a(a),.b(b)) ;
endmodule
实验二:
//half_clk.v
module half_clk (reset , clk_in , clk_out) ;
input clk_in , reset ;
output clk_out ;
reg clk_out ;
always @ (posedge clk_in)
begin
if (! reset)
clk_out = 0 ;
else
clk_out = ~clk_out ;
end
endmodule
//t.v
`timescale 1 ns/100 ps
`define clk_cycle 50
module top ;
reg clk , reset ;
wire clk_out ;
always #`clk_cycle clk = ~clk ;
initial
begin
clk = 0 ;
reset = 1 ;
#10 reset = 0 ;
#110 reset = 1 ;
#100000 $stop ;
end
half_clk m0(.reset(reset),.clk_in(clk),.clk_out(clk_out)) ;
endmodule
实验三:
//fdivision.v
module fdivision (RESET , F10M , F500K) ;
input F10M , RESET ;
output F500K ;
reg F500K ;
reg [7:0] j ;
always @ (posedge F10M)
if (! RESET)
begin
F500K <= 0 ;
j <= 0 ;
end
else
begin
if (j == 19)
begin
j <= 0 ;
F500K <= ~F500K ;
end
else
j <= j + 1 ;
end
endmodule
//t.v
`timescale 1ns/100ps
`define clk_cycle 50
`include "fdivision.v"
module t ;
reg F10M , RESET ;
wire F500K_clk ;
always #`clk_cycle F10M = ~ F10M ;
initial
begin
RESET = 1 ;
F10M = 0 ;
#100 RESET = 0 ;
#100 RESET = 1 ;
#10000 $stop ;
end
fdivision fdivision(.RESET(RESET),.F10M(F10M),.F500K(F500K_clk)) ;
endmodule