-2

For a project i got a screen with a resolution of 1024*600. For the project i need a squarre of 20px *20px with a red color. Im trying to get my verticale pos en horizontale pos out of the hsync en vsync pulse but this doesn't work. Have anyone a solution?

process(int_hsync, int_vsync)
begin
 if Rising_Edge(int_vsync) then
    vsync <= 0;
 elsif Rising_Edge(in_clk) then
    vsync <= vsync+1;
 end if;
 if Rising_Edge(int_hsync) then
    hsync <= 0;
 elsif Rising_Edge(in_clk) then
    hsync <= hsync+1;
 end if;
end process;

process(in_clk)
begin
    if Rising_Edge(in_clk) then
        if hsync < 20 and vsync <20 then
            int_pixel   <= X"0000ff";
        else
            int_pixel   <= X"ff0000";
        end if;
    end if;
end process;
Josh
  • 3,627
  • 26
  • 37
  • Do you have a typo in your code? In the first process you have `vsync` and `hsync` counters, but in the second process you have `hpos` and `vpos`. If you questions is how to get from sync -> pos, the relationship between those two is important. – Josh Mar 16 '16 at 16:24
  • yes the is some typo in the code, in the 2de process pos must be sync. – Alexander De Geeter Mar 16 '16 at 16:34
  • 2
    You're not providing a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) without which an answer involves guess work. Is the clock pixel rate? How many clocks per line? What is the Horizontal Front Porch, width and Back Porch in clocks? Do you have access to horizontal and vertical counters? If so what is the first unblanked pixel's count on the horizontal counter? These can be demonstrated in code. *but this doesn't work* doesn't describe the problem and a solution is not visible from a code snippet. –  Mar 16 '16 at 17:35
  • Please also specify the polarity of the hsync (`int_hsync` ?) and vsync (`int_vsync`) pulse. And should the code be synthesizable with a specific tool? – Martin Zabel Mar 16 '16 at 22:19

1 Answers1

1

Without some additional details it is very difficult to tell what you are trying to do.

However, I did notice that your process is only sensitive to int_hsync and int_vsync, yet you are looking for a rising_edge of in_clk. You should do an edge detect similar to this, instead (assuming that in_clk is much faster than hsync and vsync):

process(in_clk)
begin
  if rising_edge(in_clk) then
     int_vsync_dly <= int_vsync;
     int_hsync_dly <= int_hsync;
     if int_vsync = '1' and int_vsync_dly = '0' then -- rising edge detect
        vsync <= 0;
     else
        vsync <= vsync+1;
     end if;

     if int_hsync = '1' and int_hsync_dly = '0' then -- rising edge detect
        hsync <= 0;
     else
        hsync <= hsync+1;
     end if;
  end if;
end process;

This increments vsync and hsync counters every time a rising edge of the respective trigger signals is observed. Do make sure that the inputs are properly registered before the edge detection to help avoid meta-stable cases.

Josh
  • 3,627
  • 26
  • 37
  • 1
    Thanks for the solution , but this solution doesn't work. I got hundreds of scrolling squares throught the screen. – Alexander De Geeter Mar 16 '16 at 16:35
  • @AlexanderDeGeeter I revised my answer such that everything is clocked by `in_clk`. This is what I meant to answer in the first place. – Josh Mar 16 '16 at 16:54
  • 1
    This presents no offset from your H and V sync edges to position the 20x20 sprite in the visible portion of the screen image nor limit it's size to 20 pixels in either dimension. –  Mar 16 '16 at 17:24