简体   繁体   English

如何使用Verilog将RGB图片最有效地导入FPGA

[英]How to get a rgb picture into FPGA most efficiently, using verilog

I am trying to write a verilog code for FPGA programming where I will implement a VGA application. 我正在尝试编写用于FPGA编程的Verilog代码,我将在其中实现VGA应用程序。 I use Quartus II and Altera DE2. 我使用Quartus II和Altera DE2。

At the moment, my aim is to get a 640x480 rgb image during compilation (method doesn't matter as long as it works and is efficient). 目前,我的目标是在编译过程中获得640x480 rgb图像(方法无关紧要,只要它有效且有效即可)。 The best solution I came up with is to convert the picture into rgb hex files using matlab and to use $readmemh to get them into a register. 我想出的最好的解决方案是使用matlab将图片转换为rgb十六进制文件,并使用$ readmemh将其保存到寄存器中。

But as discussed here: verilog $readmemh takes too much time for 50x50 pixel rgb image 但正如这里讨论的那样: 对于50x50像素的rgb图像,verilog $ readmemh花费了太多时间

it takes too much time and apparently there is no way around it with this method. 它花费了太多时间,显然使用这种方法无法解决。 It would be fine if it was only the time but there is also the size problem, 640x480 pretty much costs most of the free space. 如果只是时间,但是也存在尺寸问题,那将是很好的,640x480几乎会花费大部分可用空间。

What I am hoping is some system function or variable type of verilog that will take and store the picture in a different way so that size won't be a problem anymore. 我希望的是一些系统功能或可变类型的Verilog,它将以不同的方式拍摄和存储图片,因此尺寸不再是问题。 I have checked solutions for verilog and quartus webpage but I believe there should be a faster way to do this general task, rather than writing something from scratch. 我已经检查了verilog和quartus网页的解决方案,但我相信应该有一种更快的方法来执行此常规任务,而不是从头开始编写东西。

compilation report for 200x200 readmemh attempt: 200x200 readmemh尝试的编译报告: 200x200编译报告

Based on your compilation report, I'd recommend you using a block ROM (or RAM) memory, instead of registers to store your image. 根据您的编译报告,建议您使用块ROM(或RAM)存储器,而不是使用寄存器来存储映像。

At this moment you're using distributed RAM, ie the memory that is available inside a each small logic blocks of FPGA. 现在,您正在使用分布式RAM,即FPGA的每个小逻辑块内部可用的存储器。 This makes distributed RAM, ideal for small sized memories. 这使得分布式RAM非常适合小型内存。 But when comes to large memories, this may cause an extra wiring delays and increase synthesis time (the synthesiser need to wire all of this blocks). 但是,对于大容量存储器,这可能会导致额外的布线延迟并增加合成时间(合成器需要对所有这些模块进行布线)。

On the other hand, a block RAM is a dedicated two port memory containing several kilobits (depending on your device and manufacture) of RAM. 另一方面,Block RAM是专用的两端口内存,其中包含几千位的RAM(取决于您的设备和制造商)。 That's why you should use block RAM for large sized memories, while distributed RAM for FIFO's or small sized memories. 这就是为什么您应该将Block RAM用于大型存储器,而将分布式RAM用于FIFO或小型存储器。 Cyclone IV EP4CE115F29 (available in DE2-115) has 432 M9K memory blocks (3981312 memory bits). Cyclone IV EP4CE115F29(在DE2-115中可用)具有432个M9K存储块(3981312个存储位)。

One important thing, the READ operation is asynchronous for distributed RAM (data is read from memory as soon as the address is given, doesn't wait for the clock edge), but synchronous for block RAM. 一件重要的事情,对于分布式RAM来说READ操作是异步的(一旦给定地址,就会从内存中读取数据,而不必等待时钟沿),而对于Block RAM则是同步的。

The example of single port ROM memory (Quartus II Verilog Template): 单端口ROM存储器示例(Quartus II Verilog模板):

module single_port_rom
#(parameter DATA_WIDTH=8, parameter ADDR_WIDTH=8)
(
    input [(ADDR_WIDTH-1):0] addr,
    input clk, 
    output reg [(DATA_WIDTH-1):0] q
);

    // Declare the ROM variable
    reg [DATA_WIDTH-1:0] rom[2**ADDR_WIDTH-1:0];

    initial
    begin
        $readmemh("single_port_rom_init.txt", rom);
    end

    always @ (posedge clk)
    begin
        q <= rom[addr];
    end

endmodule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM