FPGA片内ROM读写测试Verilog逻辑源码Quartus工程文件+文档说明,ALTERA 在 Quartus 软件里为我们已经提供了 ROM 的 IP 核, 我们只需通过 IP 核例化一个 ROM, 根据 ROM 的读时序来读取 ROM 中存储的数据。实验中会通过 Quartus 集成的在线逻辑分析仪Signaltap,我们可以观察 ROM 的读时序和从 ROM 中读取的数据,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// module rom_test( input clk, //50MHz时钟 input rst_n //复位信号,低电平有效 ); //----------------------------------------------------------- reg[4:0] rom_addr; //ROM输入地址 wire[7:0] rom_data; //ROM的数据 //产生ROM地址读取数据测试 always @(posedge clk or negedge rst_n) if(rst_n==1'b0) rom_addr <= 10'd0; else rom_addr <= rom_addr+1'b1; //----------------------------------------------------------- //实例化ROM rom_ip rom_ip_inst ( .clock (clk ), // input clock .address (rom_addr ), // input [4 : 0] address .q (rom_data ) // output [7 : 0] q ); endmodule
FPGA片内RAM读写测试Verilog逻辑源码Quartus工程文件+文档说明,使用 FPGA 内部的 RAM 以及程序对该 RAM 的数据读写操作,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// module ram_test( input clk, //50MHz时钟 input rst_n //复位信号,低电平有效 ); //----------------------------------------------------------- reg[8:0] w_addr; //RAM写地址 reg[15:0] w_data; //RAM写数据 reg wea; //RAM PORTA 使能 reg[8:0] r_addr; //RAM读地址 wire[15:0] r_data; //RAM读数据 //产生RAM地址读取数据测试 always @(posedge clk or negedge rst_n) if(rst_n==1'b0) r_addr <= 9'd0; else r_addr <= r_addr+1'b1; ///产生RAM写入的数据 always@(posedge clk or negedge rst_n) begin if(rst_n==1'b0) begin wea <= 1'b0; w_addr <= 9'd0; w_data <= 16'd0; end else begin if(w_addr==511) begin //ram写入完毕 wea <= 1'b0; end else begin wea<=1'b1; //ram写使能 w_addr <= w_addr + 1'b1; w_data <= w_data + 1'b1; end end end //----------------------------------------------------------- //实例化RAM ram_ip ram_ip_inst ( .wrclock (clk ), // input wrclock .wren (wea ), // input [0 : 0] wren .wraddress (w_addr ), // input [8 : 0] wraddress .data (w_data ), // input [15 : 0] data .rdclock (clk ), // input rdclock .rdaddress (r_addr ), // input [8 : 0] rdaddress .q (r_data ) // output [15 : 0] q ); endmodule
FPGA片内FIFO读写测试Verilog逻辑源码Quartus工程文件+文档说明,使用 FPGA 内部的 FIFO 以及程序对该 FIFO 的数据读写操作。FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// module fifo_test( input clk, //50MHz时钟 input rst_n //复位信号,低电平有效 ); //----------------------------------------------------------- localparam W_IDLE = 1; localparam W_FIFO = 2; localparam R_IDLE = 1; localparam R_FIFO = 2; reg[2:0] write_state; reg[2:0] next_write_state; reg[2:0] read_state; reg[2:0] next_read_state; reg[15:0] w_data; //FIFO写数据 wire wr_en; //FIFO写使能 wire rd_en; //FIFO读使能 wire[15:0] r_data; //FIFO读数据 wire full; //FIFO满信号 wire empty; //FIFO空信号 wire[8:0] rd_data_count; wire[8:0] wr_data_count; ///产生FIFO写入的数据 always@(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) write_state <= W_IDLE; else write_state <= next_write_state; end always@(*) begin case(write_state) W_IDLE: if(empty == 1'b1) //FIFO空, 开始写FIFO next_write_state <= W_FIFO; else next_write_state <= W_IDLE; W_FIFO: if(full == 1'b1) //FIFO满 next_write_state <= W_IDLE; else next_write_state <= W_FIFO; default: next_write_state <= W_IDLE; endcase end assign wr_en = (next_write_state == W_FIFO) ? 1'b1 : 1'b0; always@(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) w_data <= 16'd0; else if (wr_en == 1'b1) w_data <= w_data + 1'b1; else w_data <= 16'd0; end ///产生FIFO读的数据 always@(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) read_state <= R_IDLE; else read_state <= next_read_state; end always@(*) begin case(read_state) R_IDLE: if(full == 1'b1) //FIFO满, 开始读FIFO next_read_state <= R_FIFO; else next_read_state <=
d卡实验Verilog逻辑源码Quartus工程文件+文档说明,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 module sd_card_test( input clk, input rst_n, input key1, output SD_nCS, output SD_DCLK, output SD_MOSI, input SD_MISO, output [5:0] seg_sel, output [7:0] seg_data ); parameter S_IDLE = 0; parameter S_READ = 1; parameter S_WRITE = 2; parameter S_END = 3; reg[3:0] state; wire sd_init_done; reg sd_sec_read; wire[31:0] sd_sec_read_addr; wire[7:0] sd_sec_read_data; wire sd_sec_read_data_valid; wire sd_sec_read_end; reg sd_sec_write; wire[31:0] sd_sec_write_addr; reg [7:0] sd_sec_write_data; wire sd_sec_write_data_req; wire sd_sec_write_end; reg[9:0] wr_cnt; reg[9:0] rd_cnt; wire button_negedge; reg[7:0] read_data; ax_debounce ax_debounce_m0 ( .clk (clk), .rst (~rst_n), .button_in (key1), .button_posedge (), .button_negedge (button_negedge), .button_out () ); wire[6:0] seg_data_0; seg_decoder seg_decoder_m0( .bin_data (read_data[3:0]), .seg_data (seg_data_0) ); wire[6:0] seg_data_1; seg_decoder seg_decoder_m1( .bin_data (read_data[7:4]), .seg_data (seg_data_1) ); seg_scan seg_scan_m0( .clk (clk), .rst_n (rst_n), .seg_sel (seg_sel), .seg_data (seg_data), .seg_data_0 ({1'b1,7'b1111_111}), .seg_data_1 ({1'b1,7'b1111_111}), .seg_data_2 ({1'b1,7'b1111_111}), .seg_data_3 ({1'b1,7'b1111_111}), .seg_data_4 ({1'b1,seg_data_1}), .seg_data_5 ({sd_init_done,seg_data_0}) ); always@(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) wr_cnt <= 10'd0; else if(state == S_WRITE) begin if(sd_sec_write_data_req == 1'b1) wr_cnt <= wr_cnt + 10'
基于FPGA设计的vga显示测试实验Verilog逻辑源码Quartus工程文件+文档说明,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 module top( input clk, input rst_n, //vga output output vga_out_hs, //vga horizontal synchronization output vga_out_vs, //vga vertical synchronization output[4:0] vga_out_r, //vga red output[5:0] vga_out_g, //vga green output[4:0] vga_out_b //vga blue ); wire video_clk; wire video_hs; wire video_vs; wire video_de; wire[7:0] video_r; wire[7:0] video_g; wire[7:0] video_b; assign vga_out_hs = video_hs; assign vga_out_vs = video_vs; assign vga_out_r = video_r[7:3]; //discard low bit data assign vga_out_g = video_g[7:2]; //discard low bit data assign vga_out_b = video_b[7:3]; //discard low bit data //generate video pixel clock video_pll video_pll_m0( .inclk0(clk), .c0(video_clk)); color_bar color_bar_m0( .clk(video_clk), .rst(~rst_n), .hs(video_hs), .vs(video_vs), .de(video_de), .rgb_r(video_r), .rgb_g(video_g), .rgb_b(video_b) ); endmodule
基于FPGA设计的sdram读写测试实验Verilog逻辑源码Quartus工程文件+文档说明,DRAM选用海力士公司的 HY57V2562 型号,容量为的 256Mbit,采用了 54 引脚的 TSOP 封装, 数据宽度都为 16 位, 工作电压为 3.3V,并丏采用同步接口方式所有的信号都是时钟信号。FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 timescale 1ps/1ps module top ( input clk, input rst_n, output[1:0] led, output sdram_clk, //sdram clock output sdram_cke, //sdram clock enable output sdram_cs_n, //sdram chip select output sdram_we_n, //sdram write enable output sdram_cas_n, //sdram column address strobe output sdram_ras_n, //sdram row address strobe output[1:0] sdram_dqm, //sdram data enable output[1:0] sdram_ba, //sdram bank address output[12:0] sdram_addr, //sdram address inout[15:0] sdram_dq //sdram data ); parameter MEM_DATA_BITS = 16 ; //external memory user interface data width parameter ADDR_BITS = 24 ; //external memory user interface address width parameter BUSRT_BITS = 10 ; //external memory user interface burst width parameter BURST_SIZE = 128 ; //burst size wire wr_burst_data_req; // from external memory controller,write data request ,before data 1 clock wire wr_burst_finish; // from external memory controller,burst write finish wire rd_burst_finish; // from external memory controller,burst read finish wire rd_burst_req; // to external memory controller,send out a burst read request wire wr_burst_req; // to external memory controller,send out a burst write request wire[BUSRT_BITS - 1:0] rd_burst_len; // to e
基于FGGA设计的音频录音与播放实验例程Verilog逻辑源码Quartus工程文件+文档说明,音频编解码芯片选用WOLFSON 公司的 WM8731 芯,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 `timescale 1ps/1ps module top ( input clk, //clock input input rst_n, //reset input input key, //record play button input wm8731_bclk, //audio bit clock input wm8731_daclrc, //DAC sample rate left right clock output wm8731_dacdat, //DAC audio data output input wm8731_adclrc, //ADC sample rate left right clock input wm8731_adcdat, //ADC audio data input inout wm8731_scl, //I2C clock inout wm8731_sda, //I2C data output sdram_clk, //sdram clock output sdram_cke, //sdram clock enable output sdram_cs_n, //sdram chip select output sdram_we_n, //sdram write enable output sdram_cas_n, //sdram column address strobe output sdram_ras_n, //sdram row address strobe output[1:0] sdram_dqm, //sdram data enable output[1:0] sdram_ba, //sdram bank address output[12:0] sdram_addr, //sdram address inout[15:0] sdram_dq //sdram data ); parameter MEM_DATA_BITS = 16 ; //external memory user interface data width parameter ADDR_BITS = 24 ; //external memory user interface address width parameter BUSRT_BITS = 10 ; //external memory user interface burst width wire wr_burst_data_req; wire
基于FPGA设计的SD卡音乐播放Verilog逻辑源码Quartus工程文件+文档说明,音频编解码芯片选用WOLFSON 公司的 WM8731 芯,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 module top( input clk, input rst_n, input key1, input wm8731_bclk, //audio bit clock input wm8731_daclrc, //DAC sample rate left right clock output wm8731_dacdat, //DAC audio data output input wm8731_adclrc, //ADC sample rate left right clock input wm8731_adcdat, //ADC audio data input inout wm8731_scl, //I2C clock inout wm8731_sda, //I2C data output sd_ncs, //SD card chip select (SPI mode) output sd_dclk, //SD card clock output sd_mosi, //SD card controller data output input sd_miso, //SD card controller data input output [5:0] seg_sel, output [7:0] seg_data ); wire[9:0] lut_index; wire[31:0] lut_data; wire[3:0] state_code; wire[6:0] seg_data_0; //I2C master controller i2c_config i2c_config_m0( .rst (~rst_n ), .clk (clk ), .clk_div_cnt (16'd99 ), .i2c_addr_2byte (1'b0 ), .lut_index (lut_index ), .lut_dev_addr (lut_data[31:24] ), .lut_reg_addr (lut_data[23:8] ), .lut_reg_data (lut_data[7:0] ), .error ( ), .done ( ), .i2c_scl
基于FPGA设计的字符VGA LCD显示实验Verilog逻辑源码Quartus工程文件+文档说明,通过字符转换工具将字符转换为 8 进制 mif 文件存放到单端口的 ROM IP 核中,再从 ROM 中把转换后的数据读取出来显示到 VGA 上,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 module top( input clk, input rst_n, //vga output output vga_out_hs, //vga horizontal synchronization output vga_out_vs, //vga vertical synchronization output[4:0] vga_out_r, //vga red output[5:0] vga_out_g, //vga green output[4:0] vga_out_b //vga blue ); wire video_clk; wire video_hs; wire video_vs; wire video_de; wire[7:0] video_r; wire[7:0] video_g; wire[7:0] video_b; wire osd_hs; wire osd_vs; wire osd_de; wire[7:0] osd_r; wire[7:0] osd_g; wire[7:0] osd_b; assign vga_out_hs = osd_hs; assign vga_out_vs = osd_vs; assign vga_out_r = osd_r[7:3]; //discard low bit data assign vga_out_g = osd_g[7:2]; //discard low bit data assign vga_out_b = osd_b[7:3]; //discard low bit data //generate video pixel clock video_pll video_pll_m0( .inclk0 (clk ), .c0 (video_clk ) ); color_bar color_bar_m0( .clk (video_clk ), .rst (~rst_n ), .hs (video_hs ), .vs (video_vs ), .de (video_de ), .rgb_r (video_r ), .rgb_g (video_g ), .rgb_b
读取SD卡中的BMP图片并通过VGA LCD屏显示的Verilog逻辑源码Quartus工程文件+文档说明,实验将SD卡里的BMP图片读出,写入到外部存储器,再通过 VGA、LCD 等显示,FPGA型号Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。 module top( input clk, input rst_n, input key1, output [5:0] seg_sel, output [7:0] seg_data, output vga_out_hs, //vga horizontal synchronization output vga_out_vs, //vga vertical synchronization output[4:0] vga_out_r, //vga red output[5:0] vga_out_g, //vga green output[4:0] vga_out_b, //vga blue output sd_ncs, //SD card chip select (SPI mode) output sd_dclk, //SD card clock output sd_mosi, //SD card controller data output input sd_miso, //SD card controller data input output sdram_clk, //sdram clock output sdram_cke, //sdram clock enable output sdram_cs_n, //sdram chip select output sdram_we_n, //sdram write enable output sdram_cas_n, //sdram column address strobe output sdram_ras_n, //sdram row address strobe output[1:0] sdram_dqm, //sdram data enable output[1:0] sdram_ba, //sdram bank address output[12:0] sdram_addr, //sdram address inout[15:0] sdram_dq //sdram data ); parameter MEM_DATA_BITS = 16 ; //external memory user interface data width parameter ADDR_BITS = 24 ; //external memory user interface address width parameter BUSRT_BITS = 10 ; //external memory user interface burst width wire