问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

求异步fifo存储器设计的代码

发布网友 发布时间:2022-11-23 14:45

我来回答

1个回答

热心网友 时间:2024-11-04 20:48

下面的网址上就有异步fifo存储器设计的代码
http://www.asic-world.com/examples/verilog/asyn_fifo.html#Asynchronous_FIFO

我把一部分代码贴上来了:
1 //==========================================
2 // Function : Asynchronous FIFO (w/ 2 asynchronous clocks).
3 // Coder : Alex Claros F.
4 // Date : 15/May/2005.
5 // Notes : This implementation is based on the article
6 // 'Asynchronous FIFO in Virtex-II FPGAs'
7 // writen by Peter Alfke. This TechXclusive
8 // article can be downloaded from the
9 // Xilinx website. It has some minor modifications.
10 //=========================================
11
12 `timescale 1ns/1ps
13
14 mole aFifo
15 #(parameter DATA_WIDTH = 8,
16 ADDRESS_WIDTH = 4,
17 FIFO_DEPTH = (1 << ADDRESS_WIDTH))
18 //Reading port
19 (output reg [DATA_WIDTH-1:0] Data_out,
20 output reg Empty_out,
21 input wire ReadEn_in,
22 input wire RClk,
23 //Writing port.
24 input wire [DATA_WIDTH-1:0] Data_in,
25 output reg Full_out,
26 input wire WriteEn_in,
27 input wire WClk,
28
29 input wire Clear_in);
30
31 // 32 reg [DATA_WIDTH-1:0] Mem [FIFO_DEPTH-1:0];
33 wire [ADDRESS_WIDTH-1:0] pNextWordToWrite, pNextWordToRead;
34 wire EqualAddresses;
35 wire NextWriteAddressEn, NextReadAddressEn;
36 wire Set_Status, Rst_Status;
37 reg Status;
38 wire PresetFull, PresetEmpty;
39
40 // 41 //Data ports logic:
42 //(Uses a al-port RAM).
43 //'Data_out' logic:
44 always @ (posedge RClk)
45 if (ReadEn_in & ! Empty_out)
46 Data_out <= Mem[pNextWordToRead];
47
48 //'Data_in' logic:
49 always @ (posedge WClk)
50 if (WriteEn_in & ! Full_out)
51 Mem[pNextWordToWrite] <= Data_in;
52
53 //Fifo addresses support logic:
54 //'Next Addresses' enable logic:
55 assign NextWriteAddressEn = WriteEn_in & ~Full_out;
56 assign NextReadAddressEn = ReadEn_in & ~Empty_out;
57
58 //Addreses (Gray counters) logic:
59 GrayCounter GrayCounter_pWr
60 (.GrayCount_out(pNextWordToWrite),
61
62 .Enable_in(NextWriteAddressEn),
63 .Clear_in(Clear_in),
64
65 .Clk(WClk)
66 );
67
68 GrayCounter GrayCounter_pRd
69 (.GrayCount_out(pNextWordToRead),
70 .Enable_in(NextReadAddressEn),
71 .Clear_in(Clear_in),
72 .Clk(RClk)
73 );
74
75
76 //'EqualAddresses' logic:
77 assign EqualAddresses = (pNextWordToWrite == pNextWordToRead);
78
79 //'Quadrant selectors' logic:
80 assign Set_Status = (pNextWordToWrite[ADDRESS_WIDTH-2] ~^ pNextWordToRead[ADDRESS_WIDTH-1]) & 81 (pNextWordToWrite[ADDRESS_WIDTH-1] ^ pNextWordToRead[ADDRESS_WIDTH-2]);
82
83 assign Rst_Status = (pNextWordToWrite[ADDRESS_WIDTH-2] ^ pNextWordToRead[ADDRESS_WIDTH-1]) & 84 (pNextWordToWrite[ADDRESS_WIDTH-1] ~^ pNextWordToRead[ADDRESS_WIDTH-2]);
85
86 //'Status' latch logic:
87 always @ (Set_Status, Rst_Status, Clear_in) //D Latch w/ Asynchronous Clear & Preset.
88 if (Rst_Status | Clear_in)
89 Status = 0; //Going 'Empty'.
90 else if (Set_Status)
91 Status = 1; //Going 'Full'.
92
93 //'Full_out' logic for the writing port:
94 assign PresetFull = Status & EqualAddresses; //'Full' Fifo.
95
96 always @ (posedge WClk, posedge PresetFull) //D Flip-Flop w/ Asynchronous Preset.
97 if (PresetFull)
98 Full_out <= 1;
99 else
100 Full_out <= 0;
101
102 //'Empty_out' logic for the reading port:
103 assign PresetEmpty = ~Status & EqualAddresses; //'Empty' Fifo.
104
105 always @ (posedge RClk, posedge PresetEmpty) //D Flip-Flop w/ Asynchronous Preset.
106 if (PresetEmpty)
107 Empty_out <= 1;
108 else
109 Empty_out <= 0;
110
111 endmole

You could download file aFifo.v here

1 //==========================================
2 // Function : Code Gray counter.
3 // Coder : Alex Claros F.
4 // Date : 15/May/2005.
5 //=======================================
6
7 `timescale 1ns/1ps
8
9 mole GrayCounter
10 #(parameter COUNTER_WIDTH = 4)
11
12 (output reg [COUNTER_WIDTH-1:0] GrayCount_out, //'Gray' code count output.
13
14 input wire Enable_in, //Count enable.
15 input wire Clear_in, //Count reset.
16
17 input wire Clk);
18
19 // 20 reg [COUNTER_WIDTH-1:0] BinaryCount;
21
22 // 23
24 always @ (posedge Clk)
25 if (Clear_in) begin
26 BinaryCount <= {COUNTER_WIDTH{1'b 0}} + 1; //Gray count begins @ '1' with
27 GrayCount_out <= {COUNTER_WIDTH{1'b 0}}; // first 'Enable_in'.
28 end
29 else if (Enable_in) begin
30 BinaryCount <= BinaryCount + 1;
31 GrayCount_out <= {BinaryCount[COUNTER_WIDTH-1],
32 BinaryCount[COUNTER_WIDTH-2:0] ^ BinaryCount[COUNTER_WIDTH-1:1]};
33 end
34
35 endmole
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
vivox9和x9i有什么区别 ...设置原则跟构造要求。构造柱的设置原则跟构造要求是什么_百度... ...的U型钢筋锚环要几道?在哪里可以找到依据啊 ...月末不含税库存金额1065000元,请计算门店库存天数 公蟹吃什么 公蟹吃什么东西 爬行健身操功能和原理 锻炼爬行的好处有哪些呢 爬行健身法有什么优缺点 檀木如何粘合 成田剑先生还为哪些日本动漫配音,有名一点滴。谢谢了,大神帮忙啊 linux下如何用C解析出发送方的IP地址?例如我接收到UDP包,如果解析出... 茶树祛痘凝胶有用吗 描写美的四字词语 皮肤破皮了怎么办 有什么好药吗 我20岁,鼻子上黑头挺多的,一般一周用卸妆油搓一次,最近感觉黑头没过几... 中科特膳的防伪码在哪里 怎么到电信申请食品防伪认证 求助!关于基于PLC的毕业设计的选择,请前辈指引一下哪个比较简单一些... 菲斯顿壁挂炉怎样设置分时段供暖 新规定:无证驾驶电动汽车将被拘留!聊城人注意啦 浪琴,卡西欧,海鸥,天王,ck这些牌子的手表谁更好 卡西欧的手表和CK的比哪个更好? 卡西欧手表好?还是ck的好? 卡西欧和ck手表哪个牌子大 100克牛肉饼煎熟后多重 拳击速度球训练 住楼房,速度球(梨球)安装问题! 谁知道现在石家庄找中介租房子的话中介费怎么收? 石家庄租房中介费怎么算,是什么样的比例。? 石家庄买房中介费怎么付?租房子中介费怎么付? xilinx fifo支持show head吗 我矫情了是什么意思 验证码看不见 为什么有时候泥鳅都翻了或者是侧躺着睡觉,碰它他还能醒过来? 为什么Excel里一个小方格最多只能输入9个数字。。。 翻肚的泥鳅还能救活吗,怎么救活 泥l鳅被冲进下水道会活吗 泥鳅下半身没了还能活吗 雨过天晴来四九打一动物 问题篇:虚拟机提示“虚拟设备sata0:1在启动时将处于断开连接状态”_百 ... raw格式照片如何从电脑复制到相机上去 RAW格式可以复制一份吗? pascal中string是什么意思,怎么用 阿香米线如果打包的话用什么装? 袁天罡之末日天劫的基本信息 汪国辉的演艺经历 王宝德判刑多少年 之末日天劫拼音是什么 在戒烟过程中,用什么方式能缓解痛苦? b2扣分在交管12123可以处理吗?