0
\$\begingroup\$

Hi for some image processing purposes, I must read 12-bit color data of a pixel from Ram and display it on screen through VGA cable. However, my code does not read from Ram and all I see on the monitor is black square which should have been my picture. I tried reading from Rom and succeeded. I can read and display the picture from Rom but cannot from Ram. I tried everything I can but for 2 days I have not yet determined the problem. Here is the code segment I suspect most. What this code segment does is that it reads and writes data if signal done='1' and resets Ram from Rom if done = '0'. And also I must say that if enable is 1, I make write_enable 1 too. I constructed both Ram and Rom using block_memory_generator in Vivado 2017.2.

Reading_Writing_Resetting_Ram: process(clk,rst) is
begin
if rst = '1' then 

done <= '0';

elsif rising_edge(clk) then

if done = '0' then

if address_rom < 
conv_std_logic_vector((PICTURE_WIDTH_HEIGHT*PICTURE_WIDTH_HEIGHT),16) then

write_enable <= '1';
data_in_ram <= data_rom;
address_ram <= address_rom;
address_rom <= address_rom + 1;

if address_rom = 
conv_std_logic_vector((PICTURE_WIDTH_HEIGHT*PICTURE_WIDTH_HEIGHT),16) then

address_rom <= (others => '0');
write_enable <= '0';
done <= '1';

end if;
end if;

else --if done = '1'

if (pos_x < PICTURE_WIDTH_HEIGHT) and (pos_y <PICTURE_WIDTH_HEIGHT) and 
(pos_x >= 0) and (pos_y >= 0) then -- if within picture

address_ram <=(conv_std_logic_vector((pos_x + 
pos_y*PICTURE_WIDTH_HEIGHT),16));

if ( pos_x > cursor_pos_x - 1) and (pos_x < cursor_pos_x + length) and ( 
pos_y > cursor_pos_y - 1) and (pos_y < cursor_pos_y + length) then --if 
within cursor

data_in_ram <= output_of_operation;

if enable = '1' then

write_enable <= '1';

else

write_enable <= '0';

end if;

end if;

end if;

end if;

end if;

end process;

Additionally

U3: Block_Rom port map(addra => address_rom,
                       clka => clk,
                       douta => data_rom);

U4: Block_Ram port map(addra => address_ram,
                       clka => clk,
                       dina => data_in_ram,
                       douta => data_out_ram,
                       wea => write_enable);

Additionally

    process (clk_in,rst) is
    begin   

    if rst= '1' then --rst

    data_r <= (others => '0');
    data_g <= (others => '0');
    data_b <= (others => '0');

    elsif rising_edge(clk_in) then 

    if (visible = '1') then --visible

    if (pos_x < PICTURE_WIDTH_HEIGHT) and (pos_y <PICTURE_WIDTH_HEIGHT) and 
    (pos_x >= 0) and (pos_y >= 0) then -- if within picture       

    vgaData <= data_out_ram;
    data_r <= vgaData(3*COLOR_BIT-1 downto 2*COLOR_BIT);
    data_g <= vgaData(2*COLOR_BIT-1 downto COLOR_BIT);
    data_b <= vgaData(COLOR_BIT-1 downto 0);      

    if (pos_y = cursor_pos_y and pos_x >= cursor_pos_x and pos_x <= 
    cursor_pos_x + length - 1) then
    vgaData <= "111100000000"; --red
    data_r <= vgaData(3*COLOR_BIT-1 downto 2*COLOR_BIT);
    data_g <= vgaData(2*COLOR_BIT-1 downto COLOR_BIT);
    data_b <= vgaData(COLOR_BIT-1 downto 0);    
    end if;   

    if (pos_y = cursor_pos_y + length -1 and pos_x >= cursor_pos_x and pos_x 
    <= cursor_pos_x + length - 1) then
    vgaData <= "111100000000";
    data_r <= vgaData(3*COLOR_BIT-1 downto 2*COLOR_BIT);
    data_g <= vgaData(2*COLOR_BIT-1 downto COLOR_BIT);
    data_b <= vgaData(COLOR_BIT-1 downto 0);
    end if;

    if (pos_x = cursor_pos_x and pos_y >= cursor_pos_y and pos_y <= 
    cursor_pos_y + length - 1) then
    vgaData <= "111100000000";
    data_r <= vgaData(3*COLOR_BIT-1 downto 2*COLOR_BIT);
    data_g <= vgaData(2*COLOR_BIT-1 downto COLOR_BIT);
    data_b <= vgaData(COLOR_BIT-1 downto 0);
    end if;

    if (pos_x = cursor_pos_x + length - 1 and pos_y >= cursor_pos_y and pos_y 
    <= cursor_pos_y + length - 1) then
    vgaData <= "111100000000";
    data_r <= vgaData(3*COLOR_BIT-1 downto 2*COLOR_BIT);
    data_g <= vgaData(2*COLOR_BIT-1 downto COLOR_BIT);
    data_b <= vgaData(COLOR_BIT-1 downto 0);
    end if;

    else --if out of picture

    vgaData <= "000000001111"; --blue
    data_r <= vgaData(3*COLOR_BIT-1 downto 2*COLOR_BIT);
    data_g <= vgaData(2*COLOR_BIT-1 downto COLOR_BIT);
    data_b <= vgaData(COLOR_BIT-1 downto 0);

    end if; -- if within picture

    else -- if visible = '0'

    vgaData <= "000000000000"; -- black
    data_r <= vgaData(3*COLOR_BIT-1 downto 2*COLOR_BIT);
    data_g <= vgaData(2*COLOR_BIT-1 downto COLOR_BIT);
    data_b <= vgaData(COLOR_BIT-1 downto 0);

    end if;-- visible
    end if; --rst
    end process SHOW;

The code above is used to set RGB values which is used in displaying

How can I solve this problem?

\$\endgroup\$
  • \$\begingroup\$ Did you make a testbench for your design? \$\endgroup\$ – Claudio Avi Chami May 5 '18 at 19:40
  • \$\begingroup\$ I think real problem is in the other question \$\endgroup\$ – runo May 5 '18 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.