EmbDev.net

Forum: FPGA, VHDL & Verilog Please help me solve this (VHDL)


Author: Sean Astviken (strik3r)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Hi!
I'm relatively new at vhdl and need some help.

I'm writing code that is supposed to work with a VGA-display
I need the "program" to write a 4X4 colored pixel in the middle of the 
screen, and then with the help of four buttons, move this pixel up,down 
right and left on the display.

I am using the resolution 640 X 480, so the middle would be 320 and 240, 
but since i need a 4X4 pixel, i know that it need to start at 318-322 
and 238-242, but i have no idea how to write this code.
I earlier written code for the sync signals so thats out of the picture.

I know that i should at least need 3 processes
one for the 4 buttons
one for the updating of the pixel on the screen (X and Y)
and one for the sync signals which iv'e already written


I have attached two pictures, the first (vhdl(1)) shows the entity and a 
working sync process along with counters.

The second picture shows just a thought i had (it's not complete), there 
also seems to be syntax errors in it..

I couldn't think of anything better than to take a printscreen of the 
code,unfortunately its a tall picture..

How can i write code for the pixel and the X/Y?
How can i write code for the buttons?

Can anyone help me with this?? it would be much appriciated!

//Strik3r

Author: lkmiller (Guest)
Posted on:

Rate this post
0 useful
not useful
Pls post your code as *.vhd attachment.

Author: PittyJ (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
I wrote in September something similar.
The size of the 'Pixel' is different, but the rest should be very 
similar.
Take it as example.

Author: tzu (Guest)
Posted on:

Rate this post
0 useful
not useful
usable example but please fix this:

- gated clock with 25 MHz

- gated clock with 5 Hz out of gates clock

- buttons sampled only every 200 ms, so possibly don't detect a short 
press

- incoming button pins directly used on logic

- extremly long logic path for pixel position check:

if(VSyncCounter < 480  ) and ( HSyncCounter < 640) and (VSyncCounter >= 
POSY0) and (VSyncCounter  < POSY1) and (HSyncCounter >= POSX0) and 
(HSyncCounter  < POSX1)

-> 60 Bits compared + Mux afterwards.

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Already said:
  Generate25MHZ: process(CLOCK_50MHZ) is begin
    if rising_edge(CLOCK_50MHZ) then
      if(MHZ_25 = '0' ) then
        MHZ_25 <= '1';
      else
        MHZ_25 <= '0';
      end if;
    end if; -- rising edge
  end process Generate25MHZ;
  
  Generate25HZ: process(MHZ_25) is begin
    if rising_edge(MHZ_25) then
      if(HZ_KeyCounter = 500000) then   -- ******
        HZ_Key <= not(HZ_Key);
      :
This is not the way clocks are generated!

Use clock-enables instead:
  GenerateClockEnables: process(CLOCK_50MHZ) is begin
    if rising_edge(CLOCK_50MHZ) then
      MHZ_25 <= not MHZ_25;
      if(HZ_KeyCounter = 1000000-1) then -- 0...999999 = 1 Mio steps
        HZ_Key <= '1';
        HZ_KeyCounter <= 0;
      else
        HZ_Key <= '0';
        HZ_KeyCounter <= HZ_KeyCounter+1;
      end if;
    end if;

    end if; -- rising edge
  end process;
  
  GenerateSync : process(CLOCK_50MHZ) is begin -- there is only ONE clock in the design!
    if rising_edge(CLOCK_50MHZ) then
      if (MHZ_25='1') then ...

  ButtonCheck : process(CLOCK_50MHZ) is begin -- there is only ONE clock in the design!
    if rising_edge(CLOCK_50MHZ) then
      if (HZ_Key='1') then ...
  


Have a look at this line:
      if (HZ_KeyCounter = 500000) then   
This is fundamentally wrong! An obvious beginners mistake:
A counter counting from 0 to 500000 counts 500001 cycles!
Here the problem is hidden in the big number (you cannot distinguish 
between 500000 and 500001), but you would see the effekt clearly when 
the counter would count from 0 to 4...

Author: Sean Astviken (strik3r)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Thanks for all the replies! =)
I've managed to get a pixel on the screen now and it moves over the 
screen with the help of the buttons, there is just one remaining 
problem. The pixel moves way to fast when i push a button. The 
vga-screen that I'm using works with 25MHZ,so when I press a button, the 
pixel "transforms" into a line.
I need to decrease the moving speed of the pixel, but yet again, I have 
no idea how to do that.

I have posted my code in .vhd


PittyJ
I tested your construction but there was no indication on when the blank 
and v_sync signals should go low, so nothing happend on the screen.
As i said before I'm really new at this so there are a lot of codes that 
i do not understand, but thanks for the example.
I attached a syncsignal picture.
My teacher told me that i needed all the 4 signals for the screen to 
work properly.

Tzu
I'm far to new at this to know how to make those changes, dont even know 
where to start

lkmiller
In which part of my code am I supposed to put in your code?
Also, does this mean?  "if (HZ_KeyCounter = 500000) then" the 500000, 
what does it do?


//Strik3r

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.