In previos work, when I encounter the situation counter reach full state (such as counter[3:0] reaches 4'b1111), I used to manually flip counter to zeros on next rsing clock edge . However, I have ignored the fact that counter will automatically overflow on next rising clock edge when it reaches full state.

 Codes below are part of synchronous FIFO design, I will release the rest when I finish testing.

Previous  coding style


 1one tip for HDL codingbegin
 2one tip for HDL codingif(wr_addr != 4'b1111)
 3one tip for HDL coding    begin
 4one tip for HDL coding    if(rd_addr != wr_addr + 4'b0001)
 5one tip for HDL coding        ns = wcntstate;
 6one tip for HDL coding    else
 7one tip for HDL coding        ns = fullstate;
 8one tip for HDL coding    end
 9one tip for HDL codingelse
10one tip for HDL coding        begin
11one tip for HDL coding        if(rd_addr != 4'b0000)
12one tip for HDL coding            ns = wcntstate;
13one tip for HDL coding        else
14one tip for HDL coding            ns = fullstate;
15one tip for HDL coding        end                    
16one tip for HDL codingend


 modified coding style

 

1one tip for HDL codingbegin
2one tip for HDL coding    if(wr_addr != rd_addr + 4'b0001)
3one tip for HDL coding        ns = wcntstate;
4one tip for HDL coding    else
5one tip for HDL coding        ns = emptystate;
6one tip for HDL codingend

 

相关文章: