0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windowsでiverilog その183

Posted at

概要 

windowsでiverilogやってみた。
練習問題やってみた。

練習問題

Dフリップフロップで4bitシフトレジスタを書け。

方針

2相差動クロックを採用する。

写真

image.png

サンプルコード


module dff(input D, input clk, input clk2, output reg Q);
	reg r;
	always@(posedge clk)
		r <= D;
	always@(posedge clk2)
		Q = r;
endmodule

module sr8(input _in, input clk, input clk2, output wire _out);
	wire q0,
		q1,
		q2,
		q3;
	assign _out = q3;
	dff u0(.D(_in), .clk(clk), .clk2(clk2), .Q(q0));
	dff u1(.D(q0), .clk(clk), .clk2(clk2), .Q(q1));
	dff u2(.D(q1), .clk(clk), .clk2(clk2), .Q(q2));
	dff u3(.D(q2), .clk(clk), .clk2(clk2), .Q(q3));
endmodule

module test;
	reg i,
		clk,
		clk2;
	output o;
	sr8 u(i, clk, clk2, o);
	initial
	begin
		$dumpfile("test.vcd");
		$dumpvars(0, test);
		$display("i clk o");
		$monitor("%b  %b  %b", i, clk, o);
		i <= 0;
		clk <= 0;
		clk2 <= 0;
		#11;
			i <= 1;
		#3;
			i <= 0;
		#30;
			$finish;
	end
	always
	begin
	#1;
		clk <= 1;
	#1;
		clk2 <= 1;
	#1;
		clk <= 0;
	#1;
		clk2 <= 0;
	end
endmodule








実行結果

>vvp a.out
VCD info: dumpfile test.vcd opened for output.
i clk o
0  0  x
0  1  x
0  0  x
0  1  x
0  0  x
0  1  x
1  0  x
1  1  x
0  1  0
0  0  0
0  1  0
0  0  0
0  1  0
0  0  0
0  1  0
0  1  1
0  0  1
0  1  1
0  1  0
0  0  0
0  1  0
0  0  0
0  1  0
0  0  0
0  1  0
0  0  0
dff7.v:44: $finish called at 44 (1s)

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?