Forum Discussion

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

pong game

i tried to run pong game in fpga prototyping with vhdl examples book chapter 13 but i couldn't run that can you help me

6 Replies

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

    i used codes in the book i want to write in the vga pau logo but i couldn't that

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

    Please post the code you're trying to get working, and tell us the errors.

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

    these are codes

    library ieee;

    use ieee. std_logic_1164. all ;

    use ieee. numeric_std. all ;

    entity pong_graph_animate is

    port (

    clk, reset : std_logic ;

    btn: std_logic_vector (1 downto 0 ) ;

    video_on: in std_logic;

    pixel_x , pixel_y : in std_logic_vector ( 9 downto 0) ;

    graph_rgb : out std_logic_vector (2 downto 0);

    hit:out std_logic;

    gra_still: in std_logic;

    miss: in std_logic;

    graph_on : in std_logic

    ) ;

    end pong_graph_animate ;

    architecture arch of pong_graph_animate is

    signal refr_tick : std_logic;

    --x , y c o o r d i n a t e s (0,0) to ( 639 , 479 )

    signal pix_x,pix_y : unsigned ( 9 downto 0) ;

    constant MAX_X: integer :=640;

    constant MAX_Y: integer:=480;

    -- w a l l l e f t , r i g h t b o u n d a r y

    constant WALL_X_L : integer :=32 ;

    constant WALL_X_R: integer :=35;

    -- b a r l e f t , r i g h t b o u n d a r y

    constant BAR_X_L: integer :=600;

    constant BAR_X_R: integer :=603;

    --b a r t o p , b o t t o m b o u n d a r y

    signal bar_y_t , bar_y_b : unsigned ( 9 downto 0) ;

    constant BAR_Y_SIZE: integer :=72;

    -- reg t o t r a c k t o p b o u n d a r y ( x p o s i t i o n is f i x e d )

    signal bar_y_reg , bar_y_next : unsigned ( 9 downto 0) ;

    -- b a r moving v e l o c i t y when a b u t t o n i s p r e s s e d

    constant BAR_V: integer:=4;

    -- s q u a r e b a l l

    constant BALL_SIZE: integer:=8; -- 8

    -- b a l l l e f t , r i g h t b o u n d a r y

    signal ball_x_l, ball_x_r : unsigned ( 9 downto 0) ;

    -- b a l l t o p , b o t t o m b o u n d a r y

    signal ball_y_t , ball_y_b : unsigned (9 downto 0) ;

    -- reg t o t r a c k l e f t , t o p b o u n d a r y

    signal ball_x_reg , ball_x_next ,ball_vx_reg : unsigned ( 9 downto 0) ;

    signal ball_y_reg , ball_y_next ,ball_vy_reg : unsigned ( 9 downto 0) ;

    --reg t o t r a c k b a l l s p e e d

    signal x_delta_reg , x_delta_next : unsigned ( 9 downto 0 ) ;

    signal y_delta_reg , y_delta_next : unsigned ( 9 downto 0 ) ;

    -- b a l l v e l o c i t y c a n be p o s o r neg

    constant BALL_V_P : unsigned ( 9 downto 0 )

    := to_unsigned ( 2,10) ;

    constant BALL_V_N: unsigned ( 9 downto 0)

    := unsigned ( to_signed (-2,10));

    -- r o u n d b a l l i m a g e ROM

    type rom_type is array (0 to 7 )

    of std_logic_vector ( 0 to 7 ) ;

    -- ROM d e f i n i t i o n

    constant BALL_ROM: rom_type :=

    (

    "00111100" , -- * * * *

    "01111110", -- * * * * * *

    "11111111", -- * * * * * * * *

    "11111111", -- * * * * * * * *

    "11111111", -- * * * * * * * *

    "11111111", -- * * * * * * * *

    "01111110", -- * * * * * *

    "00111100" --* * * *

    ) ;

    signal rom_addr , rom_col : unsigned ( 2 downto 0 ) ;

    signal rom_data : std_logic_vector ( 7 downto 0) ;

    signal rom_bit : std_logic ;

    -- o b j e c t o u t p u t s i g n a l s

    signal wall_on ,bar_on , sq_ball_on , rd_ball_on : std_logic ;

    signal wall_rgb,bar_rgb , ball_rgb :

    std_logic_vector ( 2 downto 0) ;

    begin

    -- r e g i s t e r s

    process ( clk , reset)

    begin

    if reset = '1' then

    bar_y_reg <= ( others => '0' ) ;

    ball_x_reg <= ( others => '0' ) ;

    ball_y_reg <= ( others => '0' ) ;

    x_delta_reg <= ( "0000000100" ) ;

    y_delta_reg <= ( "0000000100") ;

    elsif( clk'event and clk = '1' ) then

    bar_y_reg <= bar_y_next ;

    ball_x_reg <= ball_x_next ;

    ball_y_reg <= ball_y_next ;

    x_delta_reg <= x_delta_next ;

    y_delta_reg <= y_delta_next ;

    end if ;

    end process;

    pix_x <= unsigned ( pixel_x ) ;

    pix_y <= unsigned ( pixel_y ) ;

    refr_tick <= '1' when ( pix_y = 481 ) and (pix_x=0) else

    '0';

    wall_on <='1' when (WALL_X_L <= pix_x ) and (pix_x<=WALL_X_R) else

    '0';

    wall_rgb <= "001"; -- b l u e

    -- b o u n d a r y

    bar_y_t <= bar_y_reg ;

    bar_y_b <= bar_y_t + BAR_Y_SIZE - 1;

    -- p i x e l w i t h i n b a r

    bar_on <=

    '1' when (BAR_X_L<=pix_x) and (pix_x<=BAR_X_R) and

    (bar_y_t <= pix_y ) and ( pix_y <= bar_y_b ) else

    '0' ;

    -- b a r r g b o u t p u t

    bar_rgb <= "001" ; --green

    -- new b a r y - p o s i t i o n

    process ( bar_y_reg , bar_y_b , bar_y_t , refr_tick , btn)

    begin

    bar_y_next <= bar_y_reg ; -- no move

    if refr_tick = '1' then

    if btn (1) = '1' and bar_y_b<(MAX_Y-1-BAR_V) then

    bar_y_next <= bar_y_reg + BAR_V; -- move down

    elsif btn ( 0 ) = '1'and bar_y_t > BAR_V then

    bar_y_next <= bar_y_reg - BAR_V ; -- move up

    end if;

    end if;

    end process;

    -- s q u a r e b a l l

    -- b o u n d a r y

    ball_x_l <= ball_x_reg ;

    ball_y_t <= ball_y_reg ;

    ball_x_r <= ball_x_l + BALL_SIZE - 1;

    ball_y_b <= ball_y_t + BALL_SIZE - 1;

    -- p i x e l w i t h i n b a l l

    sq_ball_on <=

    '1' when ( ball_x_l <= pix_x ) and ( pix_x <= ball_x_r ) and

    ( ball_y_t <= pix_y ) and ( pix_y <= ball_y_b ) else

    '0' ;

    -- map c u r r e n t p i x e l l o c a t i o n t o ROM a d d r / c o l

    rom_addr <= pix_y(2 downto 0) - ball_y_t(2 downto 0 ) ;

    rom_col <= pix_x(2 downto 0 ) - ball_x_l(2 downto 0 ) ;

    rom_data <= BALL_ROM(to_integer(rom_addr));

    rom_bit <= rom_data(to_integer(rom_col));

    -- p i x e l w i t h i n b a l l

    rd_ball_on<='1'when (sq_ball_on='1') and (rom_bit='1') else

    '0' ;

    ball_rgb <= "100" ; -- red

    ball_x_next <=

    to_unsigned((MAX_X)/2,10) when gra_still='1' else

    ball_x_reg + ball_vx_reg when refr_tick='1' else

    ball_x_reg ;

    ball_y_next <=

    to_unsigned((MAX_Y)/2,10) when gra_still='1' else

    ball_y_reg + ball_vy_reg when refr_tick='1' else

    ball_y_reg ;

    process ( ball_vx_reg , ball_vy_reg , ball_y_t,ball_x_l, ball_x_r ,

    ball_y_t,ball_y_b,bar_y_t,bar_y_b,gra_still,hit,miss)

    begin

    hit <= '0' ;

    miss <= '0' ;

    ball_vx_next <= ball_vx_reg;

    ball_vy_next <= ball_vy_reg;

    if gra_still= '1' then -- i n i t i a 1 v e 1 o c i t y

    ball_vx_next <= BALL_V_N;

    ball_vy_next <= BALL_V_P;

    elsif ball_y_t < 1 then

    ball_vy_next <= BALL_V_P;

    elsif ball_y_b > (MAX_Y-1) then -- r e a c h b o t t o m

    ball_vy_next <= BALL_V_N;

    elsif ball_x_1 <= WALL_X_R then -- r e a c h w a l l

    ball_vx_next <= BALL_V_P; -- b o u n c e b a c k

    elsif (BAR-X-L <=ball-x-r) and (ball-x-r <=BAR-X-R) and

    (bar_y_t<=ball_y_b) and (ball_y_t<=bar_y_b) then

    -- r e a c h x of r i g h t b a r , a h i t

    ball_vx_next <= BALL_V_N; -- b o u n c e b a c k

    hit <= '1';

    elsif (ball_x_r>MAX_X) then --r e a c h r i g h t b o r d e r

    miss <= '1' ; -- a mi s s

    end if ;

    end process ;

    graph_on <= wall_on or bar_on or rd_ball_on;

    process(video_on,wall_on,bar_on,rd_ball_on,

    wall_rgb, bar_rgb, ball_rgb)

    begin

    if video_on='0' then

    graph_rgb <= "000" ; --blank

    else

    if wall_on = '1' then

    graph_rgb <= wall_rgb;

    elsif bar_on = '1' then

    graph_rgb<= bar_rgb ;

    elsif rd_ball_on = '1' then

    graph_rgb <= ball_rgb;

    else

    graph_rgb <= "110"; -- y e l l o w background

    end if ;

    end if ;

    end process ;

    end arch;

    errors

    can't write to interface object ''miss'' of mode IN

    interface object ''hit''of mode out cannot be read.change object mode to buffer

    i added the hit:out std_logic, gra_still: in std_logic, miss: in std_logic, graph_on : in std_logic

    error can be from this
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I think your error is self explanitory.

    You cannot write to an input port. You need to make it an output.

    Also, outputs cannot be read internally. Either make it a buffer (like it suggests) or use an internal signal.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I think your error is self explanitory.

    You cannot write to an input port. You need to make it an output.

    Also, outputs cannot be read internally. Either make it a buffer (like it suggests) or use an internal signal.

    --- Quote End ---

    " I have tried to run the above code but and they are executing successfully , the problem that is not that how do I assign the pins, auto assigning the pin gives a wrong output and when using the DE1 pin assignment how do i change the name as there is discrepancy in naming system "

    https://www.alteraforum.com/forum/attachment.php?attachmentid=6640