state_inputs : IN STD_LOGIC_VECTOR (0 TO 1);--外部输入信号 comb_outputs :OUT INTEGER RANGE 0 TO 15 ); --对外输出信号 END s_machine;
ARCHITECTURE behv OF s_machine IS
TYPE FSM_ST IS (s0, s1, s2, s3); --数据类型定义,状态符号化 SIGNAL c_st, next_state: FSM_ST;--将现态和次态定义为新的数据类型 BEGIN
REG: PROCESS (reset,clk) BEGIN
IF reset ='0' THEN c_st <= s0;--检测异步复位信号 ELSIF clk='1' AND clk'EVENT THEN c_st <= next_state; END IF; END PROCESS;
COM1: PROCESS(c_st, state_Inputs)--主控组合进程(现态和外部输入为敏感信号) BEGIN
CASE c_st IS
WHEN s0 => IF state_inputs = \输入为“00”,在s0踏步 ELSE next_state<=s1;END IF;--否则进入s1 WHEN s1 => IF state_inputs = \输入为“00”,在s1踏步 ELSE next_state<=s2;END IF; --否则进入s2 WHEN s2 => IF state_inputs = \输入为“11”,进入s0 ELSE next_state<=s3;END IF; --否则进入s3 WHEN s3 => IF state_inputs = \输入为“11”,在s3踏步 ELSE next_state<=s0;END IF; --否则返回s0 END case; END PROCESS;
COM2: PROCESS(c_st, state_Inputs)--主控组合进程(现态和外部输入为敏感信号) BEGIN
CASE c_st IS
WHEN s0 => comb_outputs<= 5; --现态为s0时,对外输出命令信号5编码 WHEN s1 => comb_outputs<= 8; --现态为s1时,对外输出命令信号8编码 WHEN s2 => comb_outputs<= 12; --现态为s2时,对外输出命令信号12编码 WHEN s3 => comb_outputs<= 14; --现态为s3时,对外输出命令信号14编码 END case; END PROCESS; END behv;
10-3 改写例10-1,用宏定义语句定义状态变量,给出仿真波形(含状态变量),与图10-3作比较。注意设置适当的状态机约束条件。
--10-3 改写例10-1,用宏定义语句定义状态变量,给出仿真波形(含状态变量),与图10-3作比较。注意设置适当的状态机约束条件。 LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL; ENTITY s_machine IS
PORT(clk,reset : IN STD_LOGIC;--主控时序进程时钟驱动和复位信号 state_inputs : IN STD_LOGIC_VECTOR (0 TO 1);--外部输入信号 comb_outputs :OUT INTEGER RANGE 0 TO 15 ); --对外输出信号 END s_machine;
ARCHITECTURE behv OF s_machine IS
-- TYPE FSM_ST IS (s0, s1, s2, s3); --数据类型定义,状态符号化 -- attribute syn_encoding
: string;
-- attribute syn_encoding of FSM_ST : type is \
SIGNAL c_st, next_state: STD_LOGIC_VECTOR(1 DOWNTO 0);--FSM_ST;--将现态和次态定义为新的数据类型
CONSTANT s0: STD_LOGIC_VECTOR(1 DOWNTO 0):=\状态符号编码定义 CONSTANT s1: STD_LOGIC_VECTOR(1 DOWNTO 0):=\ CONSTANT s2: STD_LOGIC_VECTOR(1 DOWNTO 0):=\ CONSTANT s3: STD_LOGIC_VECTOR(1 DOWNTO 0):=\BEGIN
REG: PROCESS (reset,clk) BEGIN
IF reset ='0' THEN c_st <= s0;--检测异步复位信号 ELSIF clk='1' AND clk'EVENT THEN c_st <= next_state; END IF; END PROCESS;
COM:PROCESS(c_st, state_Inputs)--主控组合进程(现态和外部输入为敏感信号) BEGIN
CASE c_st IS
WHEN s0 => comb_outputs<= 5; --现态为s0时,对外输出命令信号5编码 IF state_inputs = \输入为“00”,在s0踏步 ELSE next_state<=s1;END IF; --否则进入s1 WHEN s1 => comb_outputs<= 8; --现态为s1时,对外输出命令信号8编码 IF state_inputs = \输入为“00”,在s1踏步 ELSE next_state<=s2;END IF; --否则进入s2 WHEN s2 => comb_outputs<= 12; --现态为s2时,对外输出命令信号12编码 IF state_inputs = \输入为“11”,进入s0 ELSE next_state<=s3;END IF; --否则进入s3 WHEN s3 => comb_outputs<= 14; --现态为s3时,对外输出命令信号14编码 IF state_inputs = \输入为“11”,在s3踏步 ELSE next_state<=s0;END IF; --否则返回s0 END case; END PROCESS; END behv;
10-4 为例10-2的LOCK信号增加keep属性,再给出此设计的仿真波形(注意删去LOCK_T)。
--10-4 为例10-2(Moore型ADC0809采样)的LOCK信号增加keep属性。