Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

sram and vga problem ?

Hi,everyone ! I'm trying to show a 1024*768*8 grayscale image on my lcd monitor.I've already written a vga interface, and it works. On my FPGA Bord , i have two 1MB sram. Here is my questions ?

1. How do i store an image into sram?

2.Do i need to write a interface between sram and vga ?

3.Since I just want to show a grayscale image.,but my vga ports have RGB three inputs,each one have 8bits, how do i deal with this?

Thx for your help ?

<p.s> i am using Altera EP2C35F672C8

8 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have done a similar project on DE2, in my project the image is captured by CCD then putted into sram.

    I wrote two individual modules for read and write. One is for save data and one is for read data to the vga.

    By seting the RGB same value makes a gray scale picture.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    maybe you can design a rom and initialize it using a mif file (the image)

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi

    I am trying to display simple bmp file onto a monitor(thru the VGA cable) using a SPARTAN2 board.

    I have written a code for simple animation drawing and it works , but i got a problem regarding image file displays.

    I used a bmp to mif converter to get the associated mif file for my image.

    I am able to understand that it has the rgb vales of each pixel belonging to that image. But also the file contains some integer values like the pixel index and so on. Suppose i am transferring the mif file to a SRAM via RS232 then how do i do it? I am confused bcos of the non-binary stuff in the file....
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,karthikR !

    I don't have any experience of transferring data via RS232. But if you want to show an image onto a monitor, you can simply use the megawizard to generate a rom or ram then store your .mif file in it.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi karthikR,

    I doubt that transferring a MIF file via RS232 is the way to go.

    The structure of a simple BMP file is very straightforward and well-documented, so if I were you I'd consider sending the bitmap file itself down your serial link. Start by opening your bitmap in a text editor with hex mode and look for the various structures starting with BITMAPFILEHEADER. If you're only going to be dealing with bitmaps of a fixed size and colour depth you should soon be able to see how you can cut to the chase and extract just the array of RGB data you need.

    If memory space is an issue, palette based bitmaps are efficient and still pretty simple.

    Cheers

    Sharkybaba
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    regarding my prev post...............

    i thought i'd start reading a .bin file into the BRAM first before trying for the bmp file

    unfortunately the code is not responding:

    entity files is

    PORT(

    clk_in :in std_logic;

    output : out bit_vector(2 DOWNTO 0);

    out1 : out std_logic_vector(6 DOWNTO 0);

    we : in std_logic;

    input : in std_logic_vector(3 DOWNTO 0);

    rst: in std_logic);

    end files;

    architecture Behavioral of files is

    type ramtype is array(0 to 7) of bit_vector(2 downto 0);

    impure function file_io (inFile : in string) return ramtype is

    file Prog: text is in inFile;

    variable L: line;

    variable VALUE : bit_vector(2 DOWNTO 0);

    variable RAM1 :ramtype;

    begin

    for I in ramtype'range loop

    if NOT endfile(Prog) then

    readline (Prog, L);

    read (L, RAM1(I));

    end if;

    end loop;

    return RAM1;

    end function;

    signal in_data : bit_vector(2 DOWNTO 0);

    signal RAM : ramtype := file_io("demo.bin");

    signal address : std_logic_vector(3 DOWNTO 0);

    begin

    process (clk_in) IS

    begin

    if clk_in'EVENT and clk_in ='1' then

    if (we = '0') then

    RAM(conv_integer(input)) <= in_data;

    output <= in_data;

    else

    output<=RAM(conv_integer(input));

    end if;

    end if;

    CASE input IS

    WHEN "0000"=>out1<="1000000";

    WHEN "0001"=>out1<="1111001";

    WHEN "0010"=>out1<="0100100";

    WHEN "0011"=>out1<="0110000";

    WHEN "0100"=>out1<="0011001";

    WHEN "0101"=>out1<="0010010";

    WHEN "0110"=>out1<="0000010";

    WHEN "0111"=>out1<="1111000";

    WHEN "1000"=>out1<="0000000";

    WHEN "1001"=>out1<="0010000";

    WHEN OTHERS=>NULL;

    END CASE;

    end process;

    end Behavioral;

    The in_data seems to be redundant and confusing , but if i dont assign the ram to an unassigned signal ie when we ='0' then the RAM is instantiated as distributed instead of BLOCK

    The bin file is just :

    demo.bin

    000001010011100101110111

    ( 0 to 7 in 3 bit)

    can anyone help me with this file_io problem...

    ?

    or is ther something fundamentally wrong with this approach
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I have made similar desings many times and have 15 years experience with Altera.

    I have always used the megawizzard to create the memory. I would add the splach screen image by means of a mif file.

    Inserting a new image is simple but you will need a statemachine which interprets the complete stream or you will need this intelligence on the transmitter side if you only want to transmit the raw data extracted from the bmp. With the latter you only need an x and y counter for writing the image to the memory.

    As an experienced Altera user I would suggest you to simulate this with Modelsim or use Signaltap for verification.

    Dreeke
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,everyone ! I'm trying to show a 1024*768*8 grayscale image on my lcd monitor.I've already written a vga interface, and it works. On my FPGA Bord , i have two 1MB sram. Here is my questions ?

    1. How do i store an image into sram?

    2.Do i need to write a interface between sram and vga ?

    3.Since I just want to show a grayscale image.,but my vga ports have RGB three inputs,each one have 8bits, how do i deal with this?

    Thx for your help ?

    <p.s> i am using Altera EP2C35F672C8

    --- Quote End ---

    Hi Bro.

    I am working on project that is little bit similar to yours but I have a problem on VGA intrfacing becouse I am beginner on using veirolog. :(

    Could you please give me your code to try if you don't mind ???