EmbDev.net

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


von MR M. (Guest)


Attached files:

Rate this post
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

von lkmiller (Guest)


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

von PittyJ (Guest)


Attached files:

Rate this post
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.

von tzu (Guest)


Rate this post
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.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Already said:
1
  Generate25MHZ: process(CLOCK_50MHZ) is begin
2
    if rising_edge(CLOCK_50MHZ) then
3
      if(MHZ_25 = '0' ) then
4
        MHZ_25 <= '1';
5
      else
6
        MHZ_25 <= '0';
7
      end if;
8
    end if; -- rising edge
9
  end process Generate25MHZ;
10
  
11
  Generate25HZ: process(MHZ_25) is begin
12
    if rising_edge(MHZ_25) then
13
      if(HZ_KeyCounter = 500000) then   -- ******
14
        HZ_Key <= not(HZ_Key);
15
      :
This is not the way clocks are generated!

Use clock-enables instead:
1
  GenerateClockEnables: process(CLOCK_50MHZ) is begin
2
    if rising_edge(CLOCK_50MHZ) then
3
      MHZ_25 <= not MHZ_25;
4
      if(HZ_KeyCounter = 1000000-1) then -- 0...999999 = 1 Mio steps
5
        HZ_Key <= '1';
6
        HZ_KeyCounter <= 0;
7
      else
8
        HZ_Key <= '0';
9
        HZ_KeyCounter <= HZ_KeyCounter+1;
10
      end if;
11
    end if;
12
13
    end if; -- rising edge
14
  end process;
15
  
16
  GenerateSync : process(CLOCK_50MHZ) is begin -- there is only ONE clock in the design!
17
    if rising_edge(CLOCK_50MHZ) then
18
      if (MHZ_25='1') then ...
19
20
  ButtonCheck : process(CLOCK_50MHZ) is begin -- there is only ONE clock in the design!
21
    if rising_edge(CLOCK_50MHZ) then
22
      if (HZ_Key='1') then ...


Have a look at this line:
1
      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...

von MR M. (Guest)


Attached files:

Rate this post
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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.