Wishbone SSRAM controller

베릴로그 | 2012/01/04 22:49 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
모종의 이유로 16비트 SSRAM 컨트롤러를 만들고 있었는데 이미 매우 잘 만들어 진것이 있어서 만들다 말았다. 그 만들다 만 결과물을 올린다능. 만들다 말아서 시뮬레이션 까지만 검증이 되었다. 블로그가 말라 죽을꺼 같아서 올렸봤다. 스펙은 다음과 같다.

support 32bit Wishbone interface
support only 16bit SSRAM
support single word, half-word, byte access
does not support Wishbone burst operation

아래 코드를 내려받고 sim 디렉토리 아래로 찾아가서 make 하면 돌려볼 수 있다.



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

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

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

댓글을 달아 주세요

  1. prismatic 2012/01/14 03:20  댓글주소  수정/삭제  댓글쓰기

    헐 성님! ㄷㅁㅇ 성님! ㅠㅜ
    공부자료 생겼네 ㅠㅜ

  2. 2012/02/10 14:11  댓글주소  수정/삭제  댓글쓰기

    비밀댓글입니다

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 verilog

댓글을 달아 주세요

Verilog Coding Guidelines

베릴로그 | 2010/12/11 04:52 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License

합성 가능한 코드를 짜기위한 가이드라인이라구 한다능. 나도 어디선거 주워왔는데 쉽게 찾아볼 수 있게 블로그에 백ㅋ업ㅋ

Coding Guidelines
These coding guidelines assume that you are able to write correct synthesizeable code. You can always check the synthesizeablilty of your code by parsing it using the synthesis tool.

1. Use non-blocking assignments (<=) in clocked procedures. Don’t use blocking assignments (=).

1
2
    always @ (posedge clock)
        q <= d;

2 .Use blocking assignments (=) in combinational procedures:
1
2
3
4
5
    always @ (a or b or sl)
        if (sl)
            d = a;
        else
            d = b;

3. Make sure that the event lists are complete
1
2
3
4
5
    always @ (a or b) // this event list is missing signal sl
        if (sl)
            d = a;
        else
            d = b;

4. Take care of indentation. Develop your own identation guidelines and stick to them. Make sure others can read them. It helps readability and debugging greatly if it is done properly.

5. Comment code properly. The theory about good commenting is that you should be able to remove all functional code and the comments remaining should almost document the block you are designing.
1
2
3
4
5
6
7
8
9
10
    // example of bad comments
    // add a and b together
        always @ (a or b)
            c = a + b;

    // Good commenting
    // 8 bit unsigned adder for data signals ‘a’ and ‘b’
    // output is sent to UART2
        always @ (a or b)
            c = a + b;

6. Always completely specify literals.
1
2
3
4
5
    always @ (c)
        if (c == 4’b0101)
            a = 2’bxx;
        else
            a = 2’b10;

7. Use named port mapping when instantiating.
1
2
3
4
5
6
    state_machine u1 (
        .sm_in (in1),
        .sm_clock (clk),
        .reset (reset),
        .sm_out (data_mux)
    );

8. Don’t make the code any more complicated than it needs to be. Your priorities should be correctness, then readability and finally code efficiency.

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

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

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
베릴로그 스니펫 MUX, Verilog Snippet MUX  (3) 2010/05/06

댓글을 달아 주세요

  1. heroant 2011/04/04 17:44  댓글주소  수정/삭제  댓글쓰기

    5번은 좀 쩌네;; 3번이랑 6번은 같은 말 아니냐? 무슨 차이가 있는지 좀 알려줘 ㅠ

    • Favicon of http://www.filepang.co.kr BlogIcon DMW 2011/05/02 06:37  댓글주소  수정/삭제

      내가 알기로는 둘다 의도치 않은 latch가 생기는걸 막으려고 하는걸로 알고 있따능.

베릴로그 스니펫 Resettable D flip-flop

베릴로그 | 2010/11/14 18:50 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
D flip-flop with asynchronous active low reset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// async active low reset d_ff
module d_ff(
      input        wire     clock
    , input        wire     reset
    , input        wire     d
    , output       reg      q
);

    always @(posedge clock or negedge reset) begin
        if(~reset) 
            q <= 1'b0;
        else
            q <= d;
    end
endmodule

D flip-flop with synchronous active low reset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// sync active low reset d_ff
module d_ff(
      input        wire       clock
    , input        wire       reset
    , input        wire       d
    , output       reg        q
);

    always @(posedge clock) begin
        if(~reset) 
            q <= 1'b0;
        else
            q <= d;
    end
endmodule



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

댓글을 달아 주세요

  1. 유노 2010/11/17 17:21  댓글주소  수정/삭제  댓글쓰기

    wire? 시뮬레이터에 표시할 때 쓰는거임?
    허굽허굽~

  2. Favicon of http://montanaviyas.tistory.com BlogIcon 멋진☆윤호™ 2011/03/25 22:08  댓글주소  수정/삭제  댓글쓰기

    물리적인 상태에서 연결하는 선을 표현하는 것이로군.
    거미줄.. ㅋㅋ 이해했음. ㅋ

크리에이티브 커먼즈 라이선스
Creative Commons License
postive edge triggered D flip-flop

1
2
3
4
5
6
7
8
9
module d_ff(
          input     wire    clock
        , input     wire    d
        , output    reg     q
);
    always @(posedge clock)
        q <= d;

endmodule

`include "timescale.v"

module tb();
    reg clock;
    reg d;
    wire q;

    initial begin
    	clock = 0;
    	d = 0;
    end

    always begin
    	#5	clock = ~clock;
    end

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

    	$monitor("TIME=%d clock=%d d=%d q=%d", $time, clock, d, q);

    	#60		d = 1;			
    	#60		d = 0;
    	#60		$finish;
    end

    d_ff Ud_ff(
    	  .clock(clock)
    	, .d(d)
    	, .q(q)
    );

endmodule



negative edge triggered D flip-flop

1
2
3
4
5
6
7
8
9
module d_ff(
    	  input 	wire	clock
    	, input		wire	d
    	, output	reg	q
);
    always @(negedge clock)
    	q <= d;

endmodule



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

댓글을 달아 주세요

크리에이티브 커먼즈 라이선스
Creative Commons License
MUX using procedure
module mux(
	iA,				// input 0
	iB,				// input 1
	iSel,			        // select 1 bit
	oC				// output
);		

/////////////////////// Port declaration///////////////////////
input			iA;
input			iB;
input			iSel;

output			oC;	
////////////////// Port data type declaration ///////////////////
reg			oC;

////////////////// Code Start here!           ///////////////////
always @(iA or iB or iSel) begin
    if(iSel == 1'b1) begin
	oC = iA;
    end else begin
	oC = iB;
    end		
end

endmodule


MUX using case
module mux(
	iA,				// input 0
	iB,				// input 1
	iSel,			        // select 1 bit
	oC				// output
);		

/////////////////////// Port declaration///////////////////////
input			iA;
input			iB;
input			iSel;

output			oC;	
////////////////// Port data type declaration ///////////////////
reg			oC;

////////////////// Code Start here!           ///////////////////
always @(iA or iB or iSel) begin
    case(iSel) 
	1'b1: oC = iA;
	1'b0: oC = iB;	
    endcase	
end

endmodule


Testbench
//`include "mux_using_procedure.v"
`include "mux_using_case.v"

module testbench();
reg		a;				// input 0
reg		b;				// input 1
reg		s;				// input select
wire		c;				// output

initial begin
	$dumpfile("sim.vcd");
	$dumpvars(0, testbench);
	
	$monitor("TIME=%d A=%b B=%b SEL=%b C=%b", $time, a, b, s, c);
	// test scenario
		a <= 1'b0;	b <= 1'b0;	s <= 1'b0;
	#2	a <= 1'b0;	b <= 1'b0;	s <= 1'b1;
	#2	a <= 1'b0;	b <= 1'b1;	s <= 1'b0;
	#2	a <= 1'b0;	b <= 1'b1;	s <= 1'b1;
	#2	a <= 1'b1;	b <= 1'b0;	s <= 1'b0;
	#2	a <= 1'b1;	b <= 1'b0;	s <= 1'b1;
	#2	a <= 1'b1;	b <= 1'b1;	s <= 1'b0;
	#2	a <= 1'b1;	b <= 1'b1;	s <= 1'b1;
	#2	$finish();
end

// connect DUT to testbench
mux dut_mux(
	.iA(a),
	.iB(b),
	.iSel(s),
	.oC(c)
);		

endmodule


Simulation Result

Waveform

할말업ㅂ음
읭여읭여
저작자 표시 비영리 동일 조건 변경 허락
TAG Mux, verilog

댓글을 달아 주세요

  1. ememoho 2010/06/28 21:33  댓글주소  수정/삭제  댓글쓰기

    MUX using case 21번 line
    1'b0: oC = iA; -> 1'b0: oC = iB;
    오타 수정 요망... ^^

  2. 형들아 2010/10/27 21:27  댓글주소  수정/삭제  댓글쓰기

    아 이 코드 생각나네요 ㅋㅋㅋ 예전에 제가 막 징징거리니까
    이게 기본인데... 라고 하셨었는데 이제야 이해가 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
    아 좀 막연히 겁먹지 말고 봤었으면 그때 그렇게 징징거리지도않았을텐데 ㅋㅋㅋㅋㅋㅋㅋ