📄 toplevel.vhd
字号:
-------------------------------------------------------------------------------- toplevel - in2305-II DC motor/encoder HW test utility-- -- 20060711 Arjan J.C. van Gemund ---------------------------------------------------------------------------------- -- sensor chain:---- A inp -> dff -> debounce -> -> -- decoder u/d counter -> ssd-- B inp -> dff -> debounce -> -> ---- actuator chain:-- -- button 0 -> dff -> debounce -> autorep -> -- u/d counter -> dpc -> motor-- button 1 -> dff -> debounce -> autorep -> -- ---------------------------------------------------------------------------------- -- button 0: speed inc (autrepeat if pressed long)-- button 1: speed dec (autrepeat if pressed long)-- button 2: NC-- button 3: reset counters-- -- led 0: pwm motor output-- led 1: NC-- led 2: encoder A input-- led 3: encoder B input-- led 4: decoder up signal-- led 5: decoder dn signal-- led 6: NC-- led 7: decoder error event (should only happen during power cycle)------------------------------------------------------------------------------library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity toplevel is port( clk_50Mhz: in std_logic; button: in std_logic_vector(3 downto 0); led: out std_logic_vector(7 downto 0); ssd: out std_logic_vector(11 downto 0); io_b1_05: out std_logic; -- motor io_b1_07: in std_logic; -- encoder A io_b1_09: in std_logic -- encoder B );end toplevel;architecture behavioral of toplevel isattribute LOC : string;attribute LOC of clk_50Mhz : signal is "T9";attribute LOC of button : signal is "L14 L13 M14 M13";attribute LOC of led : signal is "P11 P12 N12 P13 N14 L12 P14 K12";attribute LOC of ssd : signal is "E13 F14 G14 D14 P16 E14 G13 N15 P15 R16 F13 N16";attribute LOC of io_b1_05 : signal is "T3";attribute LOC of io_b1_07 : signal is "N11";attribute LOC of io_b1_09 : signal is "P10";component dff is port( clk: in std_logic; input: in std_logic; output: out std_logic );end component;component debouncer is port( clk: in std_logic; raw: in std_logic; period: in std_logic_vector(31 downto 0); debounced: out std_logic );end component;component autorepeat is port( clk: in std_logic; input: in std_logic; output: out std_logic );end component;component decoder is port( clk: in std_logic; reset: in std_logic; a: in std_logic; b: in std_logic; up: out std_logic; dn: out std_logic; err: out std_logic );end component;component counter is port( clk: in std_logic; reset: in std_logic; edge_up: in std_logic; edge_dn: in std_logic; count: out std_logic_vector(31 downto 0) );end component;component dpc is port ( clk : in std_logic; period : in std_logic_vector(31 downto 0); width : in std_logic_vector(31 downto 0); pulse : out std_logic );end component;component hex2ssd is port( clk: in std_logic; enable: in std_logic; hex: in std_logic_vector(15 downto 0); dot: in std_logic_vector(3 downto 0); ssd: out std_logic_vector(11 downto 0) );end component;----------------------------------------------------------------------------signal reset: std_logic;signal sync_button: std_logic_vector(3 downto 0);signal debounced_button: std_logic_vector(3 downto 0);signal sync_a: std_logic;signal sync_b: std_logic;signal debounced_a: std_logic;signal debounced_b: std_logic;signal decoder_up: std_logic;signal decoder_dn: std_logic;signal decoder_err: std_logic;signal count: std_logic_vector(31 downto 0);signal speed_up: std_logic;signal speed_dn: std_logic;signal speed: std_logic_vector(31 downto 0);signal pwm_speed: std_logic_vector(31 downto 0);signal pwm: std_logic;signal ssd_data: std_logic_vector(15 downto 0);----------------------------------------------------------------------------begin -- button interfaces: dff0: dff port map ( clk => clk_50MHz, input => button(0), output => sync_button(0) ); dff1: dff port map ( clk => clk_50MHz, input => button(1), output => sync_button(1) ); dff2: dff port map ( clk => clk_50MHz, input => button(2), output => sync_button(2) ); dff3: dff port map ( clk => clk_50MHz, input => button(3), output => sync_button(3) ); debouncer0: debouncer port map ( clk => clk_50MHz, raw => sync_button(0), period => x"00100000", -- 20 ms bouncing window debounced => debounced_button(0) ); debouncer1: debouncer port map ( clk => clk_50MHz, raw => sync_button(1), period => x"00100000", debounced => debounced_button(1) ); debouncer2: debouncer port map ( clk => clk_50MHz, raw => sync_button(2), period => x"00100000", debounced => debounced_button(2) ); debouncer3: debouncer port map ( clk => clk_50MHz, raw => sync_button(3), period => x"00100000", debounced => debounced_button(3) ); -- io input interfaces: dff4: dff port map ( clk => clk_50MHz, input => io_b1_07, output => sync_a ); dff5: dff port map ( clk => clk_50MHz, input => io_b1_09, output => sync_b ); debouncer4: debouncer port map ( clk => clk_50MHz, raw => sync_a, period => x"00000100", -- 5 us bouncing window debounced => debounced_a ); debouncer5: debouncer port map ( clk => clk_50MHz, raw => sync_b, period => x"00000100", -- 5 us bouncing window debounced => debounced_b ); -- decoder: decoder0: decoder port map ( clk => clk_50MHz, reset => reset, a => debounced_a, b => debounced_b, up => decoder_up, dn => decoder_dn, err => decoder_err ); -- revolution counter: counter0: counter port map ( clk => clk_50MHz, reset => reset, edge_up => decoder_up, edge_dn => decoder_dn, count => count ); -- button auto-repeaters autorepeat0: autorepeat port map ( clk => clk_50MHz, input => debounced_button(0), output => speed_up ); autorepeat1: autorepeat port map ( clk => clk_50MHz, input => debounced_button(1), output => speed_dn ); -- motor speed up/dn counter: counter1: counter port map ( clk => clk_50MHz, reset => reset, edge_up => speed_up, edge_dn => speed_dn, count => speed ); -- pwm generator: dpc0: dpc port map ( clk => clk_50MHz, period => x"00000400", -- 20 us period width => pwm_speed, pulse => pwm ); -- hex display: hex2ssd0: hex2ssd port map ( clk => clk_50MHz, enable => '1', hex => ssd_data, dot => "1111", -- no dots ssd => ssd ); -- hook it up: led(0) <= pwm; led(1) <= '0'; led(2) <= debounced_a; led(3) <= debounced_b; led(4) <= decoder_up; led(5) <= decoder_dn; led(6) <= '0'; led(7) <= decoder_err; reset <= debounced_button(3); pwm_speed <= x"00000" & "00" & speed(7 downto 0) & "00"; -- 400 = max scale io_b1_05 <= pwm; ssd_data <= count(15 downto 8) & speed(7 downto 0);end behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -