实验现象:

核心代码:

  1. module DUAL_PORT_RAM(
  2. input CLK_12M,
  3. inout WR,
  4. input RD,
  5. input CS0,
  6. input [:]A,
  7. inout [:]DB,
  8. output FPGA_LEDR,
  9. output FPGA_LEDG,
  10. output FPGA_LEDB
  11. );
  12. //-------------------------------rst_n---------------------------------//
  13. reg rst_n;
  14. reg [:]cnt_rst;
  15.  
  16. always@(posedge CLK_12M)
  17. begin
  18. if(cnt_rst=='d10)
  19. begin
  20. rst_n <= 'd1;
  21. cnt_rst <= 'd10;
  22. end
  23. else cnt_rst <= cnt_rst + 'd1;
  24. end
  25.  
  26. //---------------------------------PLL--------------------------------//
  27. //实例化PLL
  28. my_pll u1(
  29. .inclk0(CLK_12M),
  30. .c0(PLL_48M)
  31. );
  32.  
  33. //--------------------------------RAM---------------------------------//
  34. //实例化双口ram
  35. wire [:]a_dataout;
  36. wire [:]b_dataout;
  37.  
  38. my_ram u2(
  39. .address_a(a_addr),
  40. .address_b(A),
  41. .data_a(a_datain),
  42. .data_b(DB),
  43. .clock_a(!a_clk),
  44. .clock_b(b_clk),
  45. .wren_a(a_wren),
  46. .wren_b('d0),
  47. .rden_a(a_rden),
  48. .rden_b(!rd),
  49. .q_a(a_dataout),
  50. .q_b(b_dataout)
  51. );
  52.  
  53. //-------------------------------delay-------------------------------//
  54. //对CLK_12M做延时处理
  55. reg clk1,clk2;
  56.  
  57. always@(posedge PLL_48M or negedge rst_n)
  58. begin
  59. if(!rst_n)
  60. begin
  61. clk1 <= 'd0;
  62. clk2 <= 'd0;
  63. end
  64. else
  65. begin
  66. {clk2,clk1} <= {clk1,CLK_12M};
  67. end
  68. end
  69.  
  70. wire a_clk = (CLK_12M & clk2);
  71.  
  72. //---------------------------------ram_cnt----------------------------//
  73. //ram地址数据计数器
  74. reg [:]cnt_addr;
  75.  
  76. always@(posedge CLK_12M or negedge rst_n)
  77. begin
  78. if(!rst_n)
  79. begin
  80. cnt_addr <= 'd0;
  81. end
  82. else if(cnt_addr=='d511)
  83. begin
  84. cnt_addr <= 'd0;
  85. end
  86. else cnt_addr <= cnt_addr + 'd1;
  87. end
  88.  
  89. //------------------------------ram_a wr&rd----------------------------//
  90. reg a_wren,a_rden;
  91. reg [:]a_datain;
  92. reg [:]a_addr;
  93.  
  94. always@(posedge a_clk or negedge rst_n)
  95. begin
  96. if(!rst_n)
  97. begin
  98. a_wren <= 'd0;
  99. a_rden <= 'd0;
  100. a_datain <= 'd0;
  101. a_addr <= 'd0;
  102. end
  103. else if(cnt_addr >= 'd0 && cnt_addr <= 10'd255)
  104. begin
  105. a_wren <= 'd1;
  106. a_datain <= cnt_addr;
  107. a_addr <= cnt_addr;
  108. a_rden <= 'd0;
  109. end
  110. else if(cnt_addr>='d256 && cnt_addr <= 1'd511)
  111. begin
  112. a_rden <= 'd1;
  113. a_addr <= cnt_addr - 'd256;
  114. a_wren <= 'd0;
  115. end
  116. end
  117.  
  118. //------------------------------a_ram_error---------------------------//
  119. //判断读取地址与输出数据是否相等。相等,绿灯亮;不相等,红灯亮。
  120. reg error;
  121. reg [:]led;
  122.  
  123. always@(negedge clk1 or negedge rst_n)
  124. begin
  125. if(!rst_n)
  126. begin
  127. error <= 'd0;
  128. end
  129. else if(a_wren || a_dataout == a_addr)
  130. begin
  131. error <= 'd0;
  132. led <= 'b101;
  133. end
  134. else
  135. begin
  136. error <= 'd1;
  137. led <= 'b011;
  138. end
  139. end
  140.  
  141. assign {FPGA_LEDR,FPGA_LEDG,FPGA_LEDB} = led;
  142.  
  143. //-------------------------------b_ram_rd-----------------------------//
  144. //控制ram_b的读取功能,当读信号来临时,读取数据发送到FSMC总线上
  145. wire wr = (CS0 | WR );
  146. wire rd = (CS0 | RD);
  147. reg wr_clk1,wr_clk2;
  148.  
  149. always@(posedge PLL_48M or negedge rst_n)
  150. begin
  151. if(!rst_n)
  152. begin
  153. wr_clk1 <= 'd1;
  154. wr_clk2 <= 'd1;
  155. end
  156. else
  157. begin
  158. {wr_clk2,wr_clk1} <= {wr_clk1,wr};
  159. end
  160. end
  161. wire b_clk = (!wr_clk2 | !rd);
  162. assign DB = !rd ? b_dataout : 'hzzzz;
  163.  
  164. //------------------------------endmodule-----------------------------//
  165. endmodule

实验方法及指导书:

链接:http://pan.baidu.com/s/1hsEeYxe 密码:004h

【iCore1S 双核心板_FPGA】例程十七:基于双口RAM的ARM+FPGA数据存取实验的更多相关文章

  1. 【iCore1S 双核心板_FPGA】例程十二:基于单口RAM的ARM+FPGA数据存取实验

    实验现象: 核心代码: module single_port_ram( input CLK_12M, input WR, input RD, input CS0, inout [:]DB, input ...

  2. 【iCore4 双核心板_FPGA】例程十五:基于单口RAM的ARM+FPGA数据存取实验

    实验现象: 写RAM命令格式:write:地址(0-255),数据(0-65535)\cr\lf 读RAM命令格式:read:地址(0-255)\cr\lf 核心代码: int main(void) ...

  3. 【iCore3 双核心板_FPGA】实验十八:基于单口RAM的ARM+FPGA数据存取实验

    实验指导书及代码包下载: http://pan.baidu.com/s/1i58Ssvz iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  4. 【iCore4 双核心板_FPGA】例程十六:基于双口RAM的ARM+FPGA数据存取实验

    实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ int i; int address,data; ; ]; ]; char *p; /* US ...

  5. 【iCore3 双核心板_FPGA】实验十九:基于双口RAM的ARM+FPGA数据存取实验

    实验指导书及代码包下载: http://pan.baidu.com/s/1pLReIc7 iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  6. 【iCore4 双核心板_FPGA】例程十七:基于FIFO的ARM+FPGA数据存取实验

    实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ int i; int fsmc_read_data; ; ]; ]; char *p; /* ...

  7. 【iCore3 双核心板】例程十七:USB_MSC实验——读/写U盘(大容量存储器)

    实验指导书及代码包下载: http://pan.baidu.com/s/1qXt1L0o iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  8. 【iCore3 双核心板_FPGA】实验二十:基于FIFO的ARM+FPGA数据存取实验

    实验指导书及代码包下载: http://pan.baidu.com/s/1cmisnO iCore3 购买链接: https://item.taobao.com/item.htm?id=5242294 ...

  9. 【iCore1S 双核心板_FPGA】例程二:GPIO输入实验——识别按键输入

    实验现象: iCore1s 双核心板上与FPGA相连的三色LED(PCB上标示为FPGA·LED),按键按下红灯点亮,松开按键红灯熄灭. 核心源代码: module KEY( input CLK_12 ...

随机推荐

  1. POJ1700----Crossing River

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> us ...

  2. SQL Server中变量的声明和使用方法

    网址:http://blog.sina.com.cn/s/blog_63d0c97a0100qpy7.html 声明局部变量语法: DECLARE @variable_name DataType 其中 ...

  3. Python应用【PDF处理-pypdf2】

    概述 Python处理PDF文件需要安装相应的库:[PyPDF2]库 使用场景 工作中可能会涉及处理pdf文件,PyPDF2就是这样一个库, 使用它可以轻松的处理 pdf 文件,它提供了读.写.分割. ...

  4. JavaScript基础笔记(四) JS式面向对象

    JS式面向对象 一.理解对象 一)属性类型 ECMA-262 第 5 版在定义只有内部才用的特性(attribute)时,描述了属性(property)的各种特征. ECMA-262 定义这些特性是为 ...

  5. bootstrap datepicker显示日历

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...

  6. [Codeforces113C]Double Happiness(数论)

    题意 给定闭区间[l,r] [l,r] [l,r],找出区间内满足t=a2+b2 t=a^{2}+b^{2} t=a2+b2的所有素数t t t的个数( a,b a,b a,b为任意正整数). 思路 ...

  7. mysql时间加减运算

    一.MySQL 获得当前日期时间 函数 1.1 获得当前日期 + 时间(date + time) 函数:now() mysql> select now();+———————+| now() |+ ...

  8. show full processlist

    mysql 显示哪些线程正在运行: show full processlist; 如果mysql 发生了锁表的情况,这个命令很容易知道是哪个表被什么操作锁住了

  9. C#_02.10_基础一_.NET框架

    C#_02.10_基础一_.NET框架 一.概念: .NET框架是一个多语言组件开发和执行环境,它提供了一个跨语言的统一编程环境. 解读: 1..net框架是一个编程环境, 2.可以进行多语言的开发和 ...

  10. JSP(1)—基础知识

    JSP(1)-基本知识 起源 在很多动态网页中绝大多数网页都是固定不变的只有局部内容需要动态产生和改变,如果使用Servlet程序来输出只有局部内容需要动态改变的网页,其中所有的的静态内容,也需要程序 ...