📄 fsm_motion_v01_00_02.vhd
字号:
------------------------------------------------------------------------------------ Company: SANDEEPANI - Bangalore-- Engineer: PRAVEEN FELIX-- -- Create Date: 19:54:26 09/01/2008 -- Design Name: FSM for motion-- Module Name: fsm_motion - Behavioral -- Project Name: Moving Geometric Objects on VGA monitor-- Target Devices: XILINX Spartan 3 Starter Kit xc3s200-4ft256-- Tool versions: XILINX ISE Project Navigator 9.2.04i, MENTOR GRAPHICS ModelSim SE 6.2f-- Description: The module is the FSM for the unit that creates motion for the geometric objects---- Dependencies: ---- Revision: v01_00_02 -- Revision 0.01 - File Created-- Additional Comments: ------------------------------------------------------------------------------------library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;-- including VGA_GEOMETRY_PACKAGEuse WORK.MY_PACK.ALL;---- Uncomment the following library declaration if instantiating---- any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;entity fsm_motion_v01_00_02 is Port ( clk25 : in STD_LOGIC; -- 25MHz Clock input rst : in STD_LOGIC; -- Reset input a_side : in STD_LOGIC_VECTOR (9 downto 0); -- Side a of the frame of geometric object b_side : in STD_LOGIC_VECTOR (9 downto 0); -- Side b of the frame of geometric object c_side : in STD_LOGIC_VECTOR (9 downto 0); -- Side c of the frame of geometric object d_side : in STD_LOGIC_VECTOR (9 downto 0); -- Side d of the frame of geometric object up_updown : out STD_LOGIC; -- Up/Down count for updown counter up_leftright : out STD_LOGIC -- Up/Down count for leftright counter );end fsm_motion_v01_00_02;architecture Behavioral of fsm_motion_v01_00_02 is
-- STATE Description
-- IDLE - No motion state
-- DOWN_RIGHT - State for object movement in Down Right direction -- DOWN_LEFT - State for object movement in Down Left direction -- UP_LEFT - State for object movement in Up Left direction -- UP_RIGHT - State for object movement in Up Right direction type MY_STATE is (IDLE, DOWN_RIGHT, DOWN_LEFT, UP_LEFT, UP_RIGHT); SIGNAL CURRENT_STATE, NEXT_STATE: MY_STATE;begin -- Synchronous process SYNC: process(clk25, rst) begin if rst = '1' then CURRENT_STATE <= IDLE; elsif clk25'event and clk25 = '1' then CURRENT_STATE <= NEXT_STATE; end if; end process SYNC; -- Combinational process COMB: process(CURRENT_STATE, a_side, b_side, c_side, d_side) begin case CURRENT_STATE is
-- STATE: IDLE
-- Algorithm description given below
-- NEXT_STATE = DOWN_RIGHT
when IDLE => NEXT_STATE <= DOWN_RIGHT;
-- STATE: DOWN_RIGHT -- Algorithm description given below:
-- If the object hits the right side of the frame then NEXT_STATE = DOWN_LEFT
-- Else if the object hits the down side of the frame then NEXT_STATE = UP_RIGHT
-- Else NEXT_STATE = DOWN_RIGHT when DOWN_RIGHT => if d_side >= (PIXEL_COLUMN_HIGH - 1) then NEXT_STATE <= DOWN_LEFT; elsif c_side >= (PIXEL_ROW_HIGH - 1) then NEXT_STATE <= UP_RIGHT; else NEXT_STATE <= DOWN_RIGHT; end if;
-- STATE: DOWN_LEFT -- Algorithm description given below: -- If the object hits the left side of the frame then NEXT_STATE = DOWN_RIGHT -- Else if the object hits the down side of the frame then NEXT_STATE = UP_LEFT -- Else NEXT_STATE = DOWN_LEFT when DOWN_LEFT => if b_side <= (PIXEL_COLUMN_LOW - 1) then NEXT_STATE <= DOWN_RIGHT; elsif c_side >= ( PIXEL_ROW_HIGH - 1) then NEXT_STATE <= UP_LEFT; else NEXT_STATE <= DOWN_LEFT; end if;
-- STATE: UP_RIGHT -- Algorithm description given below: -- If the object hits the right side of the frame then NEXT_STATE = UP_LEFT -- Else if the object hits the up side of the frame then NEXT_STATE = DOWN_RIGHT -- Else NEXT_STATE = UP_RIGHT when UP_RIGHT => if d_side >= (PIXEL_COLUMN_HIGH - 1) then NEXT_STATE <= UP_LEFT; elsif a_side <= (PIXEL_ROW_LOW - 1) then NEXT_STATE <= DOWN_RIGHT; else NEXT_STATE <= UP_RIGHT; end if; -- STATE: UP_LEFT -- Algorithm description given below: -- If the object hits the left side of the frame then NEXT_STATE = UP_RIGHT -- Else if the object hits the up side of the frame then NEXT_STATE = DOWN_LEFT -- Else NEXT_STATE = UP_LEFT when UP_LEFT => if b_side <= (PIXEL_COLUMN_LOW - 1) then NEXT_STATE <= UP_RIGHT; elsif a_side <= (PIXEL_ROW_LOW - 1) then NEXT_STATE <= DOWN_LEFT; else NEXT_STATE <= UP_LEFT; end if;
end case; end process COMB; -- Output process OUTPUT: process(CURRENT_STATE) begin case CURRENT_STATE is when IDLE => up_updown <= '0'; up_leftright <= '0'; when DOWN_RIGHT => up_updown <= '1'; up_leftright <= '1'; when DOWN_LEFT => up_updown <= '1'; up_leftright <= '0'; when UP_RIGHT => up_updown <= '0'; up_leftright <= '1'; when UP_LEFT => up_updown <= '0'; up_leftright <= '0'; end case; end process; end Behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -