Clock speed

베릴로그 | 2011/05/02 06:31 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
블로그가 말라죽어 가려고 해서 잉공호흡 좀 시킬겸 찌끌여봤다능.
시뮬레이션을 할 때 클럭 스피드를 콘솔에 뿌려주는 구문인데....매우 유용하다.

1
2
3
4
5
6
7
8
9
10
	integer stamp_f;
	integer stamp_s;
	initial begin
		wait(RESETn == 1'b1);
		wait(RESETn == 1'b0);
		@ (posedge CLOCK);
		@ (posedge CLOCK); stamp_f = $time;
		@ (posedge CLOCK); stamp_s = $time;
		@ (negedge CLOCK); $display("CLOCK %d nsec", stamp_s - stamp_f);
	end


active low 리셋을 기둘렸다가 클럭의 rising edge부터 다음 rising edge까지 timescale이 몇번 지났는지 측정해서 보여주는 구문이다. 그러니까 1ns timescale를 사용하면 ns 단위로 클럭 스피드를 재서 보여주게된다. 조타능.

이런식으로 사용하면 된다.

`include "timescale.v"

module tb();
	reg CLOCK;
	reg RESETn;

	initial begin
		CLOCK = 0;
	end

	initial begin
		RESETn = 1;
		#50 RESETn = 0;
		#50 RESETn = 1;
		#200 $finish;
	end

	always begin
		#10		CLOCK = ~CLOCK;			// 20ns(50Mhz) clk at 1ns timescale 
	end

	integer stamp_f;
	integer stamp_s;
	initial begin
		wait(RESETn == 1'b1);
		wait(RESETn == 1'b0);
		@ (posedge CLOCK);
		@ (posedge CLOCK); stamp_f = $time;
		@ (posedge CLOCK); stamp_s = $time;
		@ (negedge CLOCK); $display("CLOCK %d nsec", stamp_s - stamp_f);
	end

	initial begin
		$dumpfile("sim.vcd");
		$dumpvars(0, tb);
	end
endmodule


저작자 표시 비영리 동일 조건 변경 허락

'베릴로그' 카테고리의 다른 글

Wishbone SSRAM controller  (5) 2012/01/04
Clock speed  (0) 2011/05/02
Verilog VPI example  (2) 2011/03/21
Verilog Coding Guidelines  (2) 2010/12/11
베릴로그 스니펫 Resettable D flip-flop  (3) 2010/11/14
베릴로그 스니펫 D flip-flop, Verilog D flip-flop  (0) 2010/11/13
TAG

댓글을 달아 주세요