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 その182

Posted at

概要 

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

練習問題

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

方針

素子が多いので、dffを変更する。

写真

image.png

サンプルコード


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

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

module test;
	reg i,
		clk;
	output o;
	sr8 u(i, clk, o);
	initial
	begin
		$dumpfile("test.vcd");
		$dumpvars(0, test);
		$display("i clk o");
		$monitor("%b  %b  %b", i, clk, o);
		i = 0;
		clk = 0;
		#10;
			i = 1;
		#4;
			i = 0;
		#20;
			$finish;
	end
	always
	begin
	#2
		clk <= ~clk;
	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
1  1  x
1  0  x
0  1  x
0  0  0
0  1  0
0  0  0
0  1  0
0  0  1
0  1  1
0  0  0
0  1  0
0  0  0
dff6.v:42: $finish called at 34 (1s)
0  1  0

以上

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?