begin
if(clk'event and clk='1') then current_state<=next_state; end if;
end process reg; catch1:process(clk) begin
if lock='1'and lock'event then regl<=d; end if; end process catch1; end behav; ⑵仿真波形:
图5-4 A-D转换器波形仿真结果
§5.3 比较器
comparator8a[7..0]b[7..0]yinst1 图5-5 8路比较器电路符号
25
⑴程序: library ieee;
use ieee.std_logic_1164.all; entity comparator8 is
port(a,b:in std_logic_vector(7 downto 0); y:out std_logic); end entity;
architecture func of comparator8 is begin
process(a,b) begin
if(a>b) then y<='1'; else y<='0'; end if; end process; end func; ⑵仿真波形:
图5-6 8路比较器波形仿真结果
26
§5.4 选择器
mux2absinst3f 图5-7 选择器电路符号
⑴程序: library ieee;
use ieee.std_logic_1164.all; entity mux2 is port(a,b:in std_logic; s:in std_logic; f:out std_logic); end mux2;
architecture behavior of mux2 is begin
mux2: process(a,b,s) begin
if(s='0') then f<=a; else f<=b; end if;
end process; end behavior; ⑵仿真波形:
27
图5-8 选择器波形仿真结果
§5.5 元件组合完成电机方向转换的仿真
利用计数器和A_D转换器产生的信号在比较器的比较作用下产生输入信号PWM波形,用2个选择器组成Z/F桥选择电路实现对电机旋转方向的控制,当Z_F选择开关输入信号为高电平时,Z桥输出PWM波形信号,当Z_F选择开关输入信号为低电平时,H桥输出PWM波形信号。
元器件组合图:
5-9 元件组合
(1)当Z/F端输入低电平时,F端输出PWM波形,电机正转:
28
5-10输入低电平
5-10输入低电平后的仿真结果
(2)当Z/F输入高电平时,Z端输出PWM波形,电机反转:
29