p137
library ieee;
use ieee.std_logic_1164.all;
entity shft is
port( clk, load : in std_logic;
qb: out std_logic
din : in std_logic_vetor(7 downto 0);
dout: out std_logic_vector(7 downto 0)
);
end shft;
architecture behav of shft is
signal reg8: std_logic_vector(7 downto 0);
begin
process(clk,load) begin
if clk'event and clk = '1' then
if load = '1' then reg8 <= din; --由(load='1')装载新数据
else reg8(6 downto 0) <= reg8(7 downto 1);
end if;
end if;
end process;
qb <= reg8(0); dout<=reg8;
end behav;
p129
-- 同一进程中同一信号的双边沿操作
process (clk) begin
if rising_edge(clk) then
q1 <= q1 + 1;
elsif falling_egde(clk) then
q1 <= q1 + 1;
end if;
end process
-- 不同进程中同一信号的双边沿操作
process (clk) begin
if rising_edge(clk) then
q1 <= q1 + 1; end if;
end process;
process (clk) begin
if falling_edge(clk) then
q1 <= q1 + 1; end if;
end process;
entity cnt4 is
port(clk,resetb:in std_logic;
dec10:out std_logic_vector(3 downto 0);
dec01:out std_lofic_vector(3 downto 0)
);
end entity cnt4;
architecture bhv of cnt4 is
signal q1:std_logic_vector(3 downto 0);
signal q2:std_logic_vector(3 downto 0);
signal q3:std_logic_vector(3 downto 0);
begin
process(clk,resetb) begin
if resetb='1' then q1<="0000";
elsif clk'event and clk ='1' then
q1<=q1+1; end if;
if resetb='1' then q2<="0000";
elsif clk'event and clk ='0' then
q2<=q2+1; end if;
q<=q2+1; end if;
if q>9 then dec10<="0001"; dec01<=q-10;
else dec10<="0000"; dec01<=q; end if;
end process;
end bhv;
com1: process(cs,EOC) begin
case cs is
when s0=> next_state <= s1;
when s1=> next_state <= s2;
when s2=> if (EOC='1') then next_state <= s3;
else next_state <= s2; end if;
when s3=> next_state <= s4; --开启OE
when s4=> next_state <= s0;
when others => next_state <= s0;
end case;
end process com1;
com2: process(cs) begin
case cs is
when s0=>ALE<='0';START<='0';LOCK<='0';OE<='0';
when s1=>ALE<='1';START<='1';LOCK<='0';OE<='0';
when s2=>ALE<='0';START<='0';LOCK<='0';OE<='0';
when s3=>ALE<='0';START<='0';LOCK<='0';OE<='1';
when s4=>ALE<='0';START<='0';LOCK<='1';OE<='1';
when others => ALE<='0';START<='0';LOCK<='0';
end case;
end process com2;
摩尔型状态机和米利型状态机的区别
摩尔型:下一状态只由当前状态决定,即次态=f(现状,输入),输出=f(现状);
米利型:下一状态不但与当前状态有关,还与当前输入值有关,即次态=f(现状,输入),输出=f(现状,输入);
二者不同点在于摩尔型的输出信号是直接由状态寄存器译码得到,而米利型是以现时的输入信号结合即将变成次态的现态,编码成输出信号
Mooer状态机的输出只与当前的状态有关,也就是数当前的状态决定输出,而与此时的输入无关,输入只决定状态机的状态改变,不影响电路最终的输出(注意:这里所说的输出不是状态机的状态机状态的输出,而是当前状态的所代表的含义,比如:检测110 序列的状态机,当状态机跳转到STA_GOT110时,电路会有一个输出信号,假如说是find,此时find就会为高电平,其他(状态时)时find就会为低电平。find 是我们最后电路的输出,find的值置于我们的转台机当前所处的状态有关,而与输出无关)。用一本书上的话说就是:Moore状态机的每一状态指定它的输出独立于电路的输入 。
Mealy状态机的输出不仅与当前的状态有关,还与当前的输出有关(同样,不要误认为状态机的输出只能是状态机的状态),即当前的输入和当前的状态共同决定当前的输入。
Mooer 状态机和 Mealy 状态机的状态的是相同的,当前的状态和输入共同决定下一个状态是什么。