-- 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. spring访问静态资源文件

    用 Spring MVC 开发应用程序,对于初学者有一个很头疼的问题,那就是程序数据都已经查询出来了,但界面样式仍然十分丑陋,加载不了 css,js,图片等资源文件.当你在浏览器上直接输入某个css文 ...

  2. Eclipse+Mingw+Boost 环境搭建

    一.安装CDT插件 Eclipse是用Java的swt开发的,所以需要java虚拟机才能运行,jdk的配置方法网上一大堆,这里就不细说了.安装CDT的方法简单提一下,到Help->Eclipse ...

  3. linux桌面环境gnome,kde,xfce,lxde 使用比较(转)

    Linus Torvalds大神前几日在 Google+上表示,GNOME 3"无可容忍的凌乱",改投Xfce桌面环境.下面就GNOME, KDE, XFCE和 LXDE略作比较. ...

  4. Nodejs Buffer

    javascript中的字符串本身就是以字符来存储,而非字节,下面的例子可以说明: console.log("0123456789".length); console.log(&q ...

  5. Daily Scrum 12.4

    今日完成任务: 对数据库完成了整理,以下是整理的内容: # 表 改动 原因 1 Answer 保留credit列,作为投票数 建议改名为vote,同意?   2 Answer qid.uid设置为外码 ...

  6. Observer设计模式中-委托事件-应用在消息在窗体上显示

    Observer设计模式:监视者模式.在类中的方法中处理的结果或者消息通过事件委托 的方式发送给主窗体. 因为在其它类中直接访问主窗体类,显示内容是不能直接调用控件赋值的,当然也有别的类似查阅控件名, ...

  7. 【转】supervisor安装与配置

    1.安装 宿主机环境:(Centos7) 宿主机环境 #yum install python-setuptools yum install python-setuptools#easy_install ...

  8. 解决Failed to load class "org.slf4j.impl.StaticLoggerBinder"

    Hibernate使用SLF4J API记录日志,所以在Hibernate的lib中,不再提供Log4J的包,而大部分框架依然使用Log4J记录日志,这样导致了兼容性问题. 解决办法,两步: 一.在编 ...

  9. BFS 或 同余模定理(poj 1426)

    题目:Find The Multiple 题意:求给出的数的倍数,该倍数是只由 1与 0构成的10进制数. 思路:nonzero multiple  非零倍数  啊. 英语弱到爆炸,理解不了题意... ...

  10. mysql 全文搜索的FULLTEXT

    FULLTEXT索引 创建FULLTEXT索引语法 创建table的时候创建fullText索引 CREATE TABLE table_name( column1 data_type, column2 ...