huanwuleng 发表于 2007-12-31 17:02:24

用vhdl如何实现按键消抖 和 如何用vhdl写pwm

用vhdl如何实现按键消抖 和 如何用vhdl写pwm?

motion_ctrl 发表于 2008-1-1 12:50:52

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity anti_15ms_glitch is
                port(
                        rst                                                                        : in                std_logic;
                        clk                                                                        : in                std_logic;
                        flag_1ms                                                        : in                std_logic;
                        in_signal                                                        : in                std_logic;
                        out_signal                                                        : out                std_logic
                        );
end anti_15ms_glitch;

architecture behavioral of anti_15ms_glitch is

        type state is (idle,wait_high,signal_out,wait_low);
        signal prt_state                                                         :                         state;
       
        signal counter                                                                :                        std_logic_vector(3 downto 0);
       
begin

        process(rst,clk) -- generate out_signal signal
        begin
                if rst = '0' then
                        out_signal <= '0';
                        counter <= "0000";
                        prt_state <= idle;
                elsif clk'event and clk = '1' then
                        case prt_state is
                                when idle =>
                                        out_signal <= '0';
                                        counter <= "0000";
                                        if in_signal = '1' then
                                                prt_state <= wait_high;
                                        end if;
                                when wait_high =>
                                        if counter = "1111" then --delay 15ms
                                                if in_signal = '1' then
                                                        prt_state <= signal_out;
                                                else
                                                        prt_state <= idle;
                                                end if;
                                        else
                                                if flag_1ms = '1' then
                                                        counter <= counter + 1;
                                                end if;
                                        end if;
                                when signal_out =>
                                        out_signal <= '1';
                                        counter <= "0000";
                                        if in_signal = '0' then
                                                prt_state <= wait_low;
                                        end if;
                                when wait_low =>
                                        if counter = "1111" then --delay 15ms
                                                if in_signal = '1' then
                                                        prt_state <= signal_out;
                                                else
                                                        prt_state <= idle;
                                                end if;
                                        else
                                                if flag_1ms = '1' then
                                                        counter <= counter + 1;
                                                end if;
                                        end if;
                                when others =>
                                        prt_state <= idle;
                        end case;
                end if;
        end process;

end behavioral;

john_wu 发表于 2008-1-4 08:44:20

上面的代码可以玩的转吗?

zxs115523805 发表于 2009-11-15 12:46:42

doubuhui 发表于 2009-11-19 10:44:07

学习下
页: [1]
查看完整版本: 用vhdl如何实现按键消抖 和 如何用vhdl写pwm