Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help with verilog - Better way of implementing this?

Status
Not open for further replies.

vakilp

Newbie level 1
Newbie level 1
Joined
May 18, 2007
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,298
Hello,

I am new to verilog and would like your help on this. I am looking at the code below:


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module beh_fifo (rdata, wfull, rempty, wdata, winc, wclk, wrst_n, rinc, rclk, rrst_n);
 parameter DSIZE = 8;
 parameter ASIZE = 4;
 output [DSIZE-1:0] rdata;
 output wfull;
 output rempty;
 input [DSIZE-1:0] wdata;
 input winc, wclk, wrst_n;
 input rinc, rclk, rrst_n;
 reg [ASIZE:0] wptr, wrptr1, wrptr2, wrptr3;
 reg [ASIZE:0] rptr, rwptr1, rwptr2, rwptr3;
 parameter MEMDEPTH = 1<<ASIZE;
 reg [DSIZE-1:0] ex_mem [0:MEMDEPTH-1];
 
 always @(posedge wclk or negedge wrst_n)
    if (!wrst_n) wptr <= 0;
    else if (winc && !wfull) begin
        ex_mem[wptr[ASIZE-1:0]] <= wdata;
        wptr <= wptr+1;
    end
    
 always @(posedge wclk or negedge wrst_n)
    if (!wrst_n) {wrptr3,wrptr2,wrptr1} <= 0;
    else {wrptr3,wrptr2,wrptr1} <= {wrptr2,wrptr1,rptr};
    
 always @(posedge rclk or negedge rrst_n)
    if (!rrst_n) rptr <= 0;
    else if (rinc && !rempty) rptr <= rptr+1;
 
 always @(posedge rclk or negedge rrst_n)
    if (!rrst_n) {rwptr3,rwptr2,rwptr1} <= 0;
    else {rwptr3,rwptr2,rwptr1} <= {rwptr2,rwptr1,wptr};
 
 assign rdata = ex_mem[rptr[ASIZE-1:0]];
 assign rempty = (rptr == rwptr3);
 assign wfull = ((wptr[ASIZE-1:0] == wrptr3[ASIZE-1:0]) &&
 (wptr[ASIZE] != wrptr3[ASIZE] ));
endmodule
endmodule



My question is, is this code good for synthesis? Or this is merely good for behavioral modeling? Why? Can you please list all the trappings in this code that you would avoid?

Thanks.
 

Looks reasonable & synthesizable to me. Be aware though that those last three assign statements will result in combinational logic. And extra beware because those are also outputs of your module. In general it's a good idea to make the outputs of modules registered. Unless of course there's a good design reason not to do so. :)
 

Last edited:

There's another paper on the same site that is for a FIFO2 design, I would avoid using that design as it's not a robust as the FIFO1 design. According to information I've found that FIFO2 design was sort of an exercise in using different techniques for pointer generation and comparison.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top