-- https://fpga4u.epfl.ch/wiki/FPGA4U_Description
-- The SDRAM is an ISSI IS42S32800B. With bits data bus, validated by SDRAM_DQM<..> signals,
-- one for each Byte of data bus SDRAM_DQ<..>.
-- This memory is a synchronous SDRAM, validating address and control signals with the rising edge of SDRAM_CLK,
-- while SDRAM_CKE activated (''). The organisation is banks selected by SDRAM_BA<..>.
-- Each bank as ^ Row and ^ Column selected by SDRAM_AD<11.0>, with bits words
-- (SDRAM_DQ<..> (^ * ^ * ^ = * 2M x = 8Mx32 = 32MBytes).
-- In SOPC Builder, with the SDRAM Controller, select:
-- Banks
-- Rows addresses lines
-- Columns addresses lines library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all; entity fpga4u_sdram_controller is
port(
--Avalon slave interface (pipelined, variable latency)
signal clk, reset : in std_logic;
signal as_address : in std_logic_vector( downto );
signal as_read, as_write : in std_logic;
signal as_byteenable : in std_logic_vector( downto );
signal as_readdata : out std_logic_vector( downto );
signal as_writedata : in std_logic_vector( downto );
signal as_waitrequest : out std_logic;
signal as_readdatavalid : out std_logic; --SDRAM interface to FPGA4U SDRAM
signal ram_addr : out std_logic_vector( downto );
signal ram_ba : out std_logic_vector( downto );
signal ram_cas_n : out std_logic;
signal ram_cke : out std_logic;
signal ram_cs_n : out std_logic;
signal ram_dq : inout std_logic_vector( downto );
signal ram_dqm : out std_logic_vector( downto );
signal ram_ras_n : out std_logic;
signal ram_we_n : out std_logic
);
end entity; architecture arch of fpga4u_sdram_controller is
--Initialisation signals
type init_state_t is (init_reset, init_pre, init_wait_pre, init_ref, init_wait_ref, init_mode, init_wait_mode, init_done);
signal init_state : init_state_t := init_reset;
signal init_wait_counter : unsigned( downto );
signal init_ref_counter : unsigned( downto ); --Main state machine
type state_t is (idle, ref, wait_ref, act, wait_act, read, spin_read, write, spin_write, precharge_all, wait_precharge);
signal state : state_t := idle;
signal ref_counter : unsigned( downto );
signal ref_req : std_logic;
signal wait_counter : unsigned( downto ); --Active transaction signals
signal int_address : std_logic_vector( downto );
signal int_readdata : std_logic_vector( downto );
signal int_writedata : std_logic_vector( downto );
signal int_byteenable : std_logic_vector( downto );
signal int_writeop : std_logic; --open bank and row
signal open_bank : std_logic_vector( downto );
signal open_row : std_logic_vector( downto ); --readdata ready pipeline
signal readdata_ready : std_logic_vector( downto ); signal ram_cmd : std_logic_vector( downto );
begin
--State machine to handle SDRAM initialization
INITSTATE : process(clk, reset)
begin
if reset = '' then
init_state <= init_reset;
--power up delay
init_wait_counter <= to_unsigned(,init_wait_counter'length);
--number refresh cycles before mode register write
init_ref_counter <= to_unsigned(,init_ref_counter'length);
elsif rising_edge(clk) then
--count down when not
if init_wait_counter /= then
init_wait_counter <= init_wait_counter - ;
end if;
case init_state is
when init_reset =>
if init_wait_counter = then
init_state <= init_pre;
end if;
--do a precharge
when init_pre =>
init_wait_counter <= to_unsigned(,init_wait_counter'length);
init_state <= init_wait_pre;
when init_wait_pre =>
if init_wait_counter = then
init_state <= init_ref;
end if;
--do a refresh
when init_ref =>
init_wait_counter <= to_unsigned(,init_wait_counter'length);
init_ref_counter <= init_ref_counter - ;
init_state <= init_wait_ref;
when init_wait_ref =>
if init_wait_counter = then
if init_ref_counter = then
init_state <= init_mode;
else
init_state <= init_ref;
end if;
end if;
--set the mode register
when init_mode =>
init_wait_counter <= to_unsigned(,init_wait_counter'length);
init_state <= init_wait_mode;
when init_wait_mode =>
if init_wait_counter = then
init_state <= init_done;
end if;
when others =>
null;
end case;
end if;
end process; --Asynchronous waitrequest to allow one transfer per cycle (critical path)
as_waitrequest <= '' when (state = idle and ref_req = '' and (as_read = '' or as_write = ''))
or ((state = read or state = spin_read) and ref_req = '' and as_read = '' and as_address( downto ) = open_row and as_address( downto ) = open_bank)
or ((state = write or state = spin_write) and ref_req = '' and as_write = '' and as_address( downto ) = open_row and as_address( downto ) = open_bank)
else ''; --Main state machine
make_state : process(clk, reset)
begin
if reset = '' then
state <= idle;
ref_counter <= (others=>'');
ref_req <= ''; --begin with a refresh
wait_counter <= (others=>'');
readdata_ready <= (others=>'');
elsif rising_edge(clk) then
--counters for delays and refresh generation
if wait_counter /= then
wait_counter <= wait_counter - ;
end if;
if ref_counter /= then
ref_counter <= ref_counter - ;
else
ref_req <= '';
ref_counter <= to_unsigned(,ref_counter'length);
end if;
--main state machine runs when the initialization is done
if init_state = init_done then
case state is
when idle =>
if ref_req = '' then --go do a refresh
ref_req <= '';
state <= ref;
elsif as_write = '' or as_read = '' then --accept the request and go to open the row
int_address <= as_address;
int_writedata <= as_writedata;
int_byteenable <= as_byteenable;
int_writeop <= as_write;
state <= act;
end if;
when ref =>
wait_counter <= to_unsigned(,wait_counter'length);
state <= wait_ref;
when wait_ref =>
if wait_counter = then
state <= idle;
end if;
when act => --save the open bank and row
open_bank <= int_address( downto );
open_row <= int_address( downto );
wait_counter <= to_unsigned(,wait_counter'length);
state <= wait_act;
when wait_act =>
if wait_counter = then
if int_writeop = '' then
state <= read;
else
state <= write;
end if;
end if;
when read => --issue a read command, feed a one in the readdata_ready pipeline, when it exits data is ready for the master
as_readdata <= int_readdata;
as_readdatavalid <= readdata_ready();
readdata_ready <= readdata_ready( downto )&'';
if ref_req = '' and as_read = '' and as_address( downto ) = open_row and as_address( downto ) = open_bank then
int_address <= as_address;
state <= read;
else
state <= spin_read;
end if;
when spin_read => --wait for reads to complete and eventually issue more compatible reads
as_readdata <= int_readdata;
as_readdatavalid <= readdata_ready();
readdata_ready <= readdata_ready( downto )&'';
if readdata_ready = "" and (ref_req = '' or as_write = '') then
state <= precharge_all;
elsif ref_req = '' and as_read = '' and as_address( downto ) = open_row and as_address( downto ) = open_bank then
int_address <= as_address;
state <= read;
elsif readdata_ready = "" and as_read = '' then
state <= precharge_all;
end if;
when write => --the same as read, except there is no pipeline as data is presented to the SDRAM on the same cycle as the command
wait_counter <= to_unsigned(,wait_counter'length);
if ref_req = '' and as_write = '' and as_address( downto ) = open_row and as_address( downto ) = open_bank then
int_address <= as_address;
int_writedata <= as_writedata;
int_byteenable <= as_byteenable;
state <= write;
else
state <= spin_write;
end if;
when spin_write => --same as for read
if wait_counter = and (ref_req = '' or as_read = '') then
state <= precharge_all;
elsif ref_req = '' and as_write = '' and as_address( downto ) = open_row and as_address( downto ) = open_bank then
int_address <= as_address;
int_writedata <= as_writedata;
int_byteenable <= as_byteenable;
state <= write;
elsif wait_counter = and as_write = '' then
state <= precharge_all;
end if;
when precharge_all =>
state <= wait_precharge;
when wait_precharge =>
state <= idle;
when others=>
null;
end case;
end if;
end if;
end process; --data from the ram needs to be sampled on the falling edge of the controller clock for proper operation
process(clk)
begin
if falling_edge(clk) then
int_readdata <= ram_dq;
end if;
end process; --process generating the command sequence for the SDRAM
ram_cke <= '';
ram_cs_n <= ram_cmd();
ram_ras_n <= ram_cmd();
ram_cas_n <= ram_cmd();
ram_we_n <= ram_cmd();
OUTPUTS : process(clk, reset)
begin
if reset = '' then
ram_addr <= (others=>'');
ram_cmd <= "";
ram_ba <= (others=>'');
ram_dq <= (others=>'Z');
ram_dqm <= (others=>'');
elsif rising_edge(clk) then
if init_state = init_pre then
ram_cmd <= ""; --precharge
ram_addr <= (=>'', others=>'');
elsif init_state = init_ref then
ram_cmd <= ""; --refresh
elsif init_state = init_mode then
ram_cmd <= ""; --mode set
ram_addr <= ""; --no burst, three cycles latency
elsif init_state = init_done then
if state = ref then
ram_cmd <= ""; --refresh
elsif state = act then
ram_cmd <= ""; --activate
ram_addr <= int_address( downto );
ram_ba <= int_address( downto );
elsif state = read then
ram_cmd <= ""; --read
ram_addr <= ""&int_address( downto );
ram_dqm <= "";
elsif state = write then
ram_cmd <= ""; --write
ram_addr <= ""&int_address( downto );
ram_dq <= int_writedata;
ram_dqm <= not int_byteenable;
elsif state = precharge_all then
ram_cmd <= ""; --precharge
ram_addr <= ""&int_address( downto );
ram_dqm <= "";
else
ram_cmd <= ""; --nop
ram_dq <= (others=>'Z');
end if;
else
ram_cmd <= ""; --nop
end if;
end if;
end process;
end arch;

FPGA4U FPGA SDRAM Controller的更多相关文章

  1. 模拟摄像头解码模块最新测试 TVP5150模块 FPGA+SDRAM+TVP5150+VGA 实现PAL AV输入 VGA视频输出

    模拟摄像头解码模块最新测试  TVP5150模块  FPGA+SDRAM+TVP5150+VGA  实现PAL AV输入 VGA视频输出 测试使用电视机顶盒的AV模拟信号输入,VGA显示器输出测试,效 ...

  2. 基于FPGA摄像头图像采集显示系统

    本系统主要由FPGA主控模块.图像采集模块.图像存储模块以及图像显示模块等模块组成.其中图像采集模块选择OV7670摄像头模块,完成对视频图像的采集和解码功能,并以RGB565标准输出RGB 5:6: ...

  3. SDRAM interface slashes pin count

    Many designs need deep buffering but don't require ultrahigh-memory bandwidth. Examples include imag ...

  4. FPGA在电平接口领域的应用

    电子技术的发展,产生了各种各样的电平接口. TTL电平: TTL电平信号之所以被广泛使用,原因是因为:通常我们采用二进制来表示数据.而且规定,+5V等价于逻辑"1",0V等价于逻辑 ...

  5. FPGA DDR3调试

    FPGA DDR3调试 Spartan6 FPGA芯片中集成了MCB硬核,它可以支持到DDR3.在Xilinx的开发工具Xilinx ISE中提供了MIG IP核,设计者可以用它来直接生成 DDR3 ...

  6. Using the SDRAM on Altera’s DE1-SoC Board with Verilog Designs

    Using the SDRAM on Altera’sDE1-SoC Board with Verilog Designs 1.DE1-SOC Board上SDRAM资源 2.系统架构框图 3.关于S ...

  7. DDR SDRAM芯片DQS的作用以及读写DQS/DQ对齐方式不同的原因

    节选内容转载自https://www.design-reuse.com/articles/13805/the-love-hate-relationship-with-ddr-sdram-control ...

  8. 玩转摄像头之 基于SDRAM缓冲 USB2.0视频采集系统 MT9T001、MT9P031 演示 展示

    玩转摄像头之  基于SDRAM缓冲 USB视频采集系统  MT9T001.MT9P031 最新设计的系统: 核心板(FPGA+SDRAM)+底板(68013+DVP)+sensor 先看图 核心板 正 ...

  9. 从FPGA搞定OV7670 VGA显示 移植到 STM32F10x TFT显示 总结及疑问(高手请进)

    OV7670不愧是最便宜的摄像头了最大显示像素:640*480(在VGA显示器上显示效果还不赖,用usb模块采集显示依然显著) 第一步:VGA显示 视频图像(实时)FPGA+SDRAM+OV7670= ...

随机推荐

  1. AsyncTask源码分析

    在Android中,主线程是UI线程,当需要根据其他数据进行更新UI时,如果获取数据的操作比较耗时的话,会触发ANR,所以我们应该讲耗时的操作进行异步操作,尤其是请求网络数据的操作应该放在后台线程进行 ...

  2. 彻底卸载sublime txt

    最近彻底重装系统之后,安装sublime txt3, 自己设置了一些,总是觉得不是很对劲,想重新安装. 结果每次安装之后,总是有一些配置文件和卸载之前的是一样的,重复几次总是如此,于是网上搜资料,怎么 ...

  3. echo 换行不换行

    echo换行输出需要转义符 -e 看以下例子: echo -e "It is the first line." >> a; echo -e "It is th ...

  4. Web开发中的主要概念

    一.Web开发中的主要概念1.静态资源:一成不变的.html.js.css2.动态资源:JavaWeb.输出或产生静态资源.(用户用浏览器看到的页面永远都是静态资源) 3.JavaEE:十三种技术的集 ...

  5. 一个关于AM335X比较全面的笔记博客

    http://www.eefocus.com/marianna/blog/cate_18142_0.html

  6. Oracle一个中文汉字占用几个字节

    Oracle 一个中文汉字 占用几个字节,要根据Oracle中字符集编码决定   查看oracle server端字符集 select userenv('language') from dual; 如 ...

  7. python语法快速入门(1)

    http://www.runoob.com/python/python-tutorial.html Python 是一种解释型语言: 这意味着开发过程中没有了编译这个环节.类似于PHP和Perl语言 ...

  8. [转] 基于ArcGISServer实现活动地图标注

    ——王嘉彬(Esri中国上海分公司) 1.背景 1.1.主流互联网地图应用的现状 在目前主流的互联网地图应用中,如 Google Map(图 1).搜狗地图(图2),POI 兴趣点的文字标注越来越多的 ...

  9. 解决代码着色组件SyntaxHighlighter行号显示问题

    SyntaxHighlighter是根据代码中的换行符分配行号的.但是,如果一行代码或者注释比较长,在页面显示时需要分成多行显示,这时行号就对不上了.如下图: 通过下面的css强制不换行,可以避开这个 ...

  10. JQuery中动态生成元素的绑定事件(坑死宝宝了)

    今天在做项目的时候,遇到了一个前端的问题,坑了我好长时间没有解决,今天就记录于此,也分享给大家. 问题是这样的,首先看看我的界面,有一个初始印象: 下面是操作列所对应的JS代码: { "da ...