1 回答
TA贡献1868条经验 获得超4个赞
如果要实现你所说的这些功能,完全不必使用到loop 这样复杂的语句。
源代码 alm 给你:
-- Generated by Mentor Graphics' HDL Designer(TM) 2005.3 (Build 75)
--
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY pulse IS
PORT(
clk : IN std_logic;
rst : IN std_logic;
rst_rst : IN std_logic;
output : OUT std_logic
);
-- Declarations
END pulse ;
--
-- VHDL Architecture study7_2_lib.pulse.fsm
--
-- Created:
-- by - PCHYKJUSER.UNKNOWN (TYL)
-- at - 18:24:10 2013-05-20
--
-- Generated by Mentor Graphics' HDL Designer(TM) 2005.3 (Build 75)
--
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ARCHITECTURE fsm OF pulse IS
-- Architecture Declarations
SIGNAL count : integer RANGE 1000 DOWNTO 0;
SIGNAL rsta0 : std_logic;
SIGNAL rsta1 : std_logic;
TYPE STATE_TYPE IS (
hold,
one_pulse
);
-- State vector declaration
ATTRIBUTE state_vector : string;
ATTRIBUTE state_vector OF fsm : ARCHITECTURE IS "current_state";
-- Declare current and next state signals
SIGNAL current_state : STATE_TYPE;
SIGNAL next_state : STATE_TYPE;
-- Declare any pre-registered internal signals
SIGNAL output_cld : std_logic ;
BEGIN
-----------------------------------------------------------------
clocked_proc : PROCESS (
clk,
rst_rst
)
-----------------------------------------------------------------
BEGIN
IF (rst_rst = '0') THEN
current_state <= hold;
ELSIF (clk'EVENT AND clk = '1') THEN
current_state <= next_state;
count<=0;
-- Combined Actions
CASE current_state IS
WHEN hold =>
output_cld<='0';
rsta0<=rst;
rsta1<=rsta0;
WHEN one_pulse =>
output_cld<='1';
count<=count+1;
WHEN OTHERS =>
NULL;
END CASE;
END IF;
END PROCESS clocked_proc;
-----------------------------------------------------------------
nextstate_proc : PROCESS (
count,
current_state,
rsta0,
rsta1
)
-----------------------------------------------------------------
BEGIN
CASE current_state IS
WHEN hold =>
IF (rsta1='1' and rsta0='0') THEN
next_state <= one_pulse;
ELSE
next_state <= hold;
END IF;
WHEN one_pulse =>
IF (count=999) THEN
next_state <= hold;
ELSIF (count<999) THEN
next_state <= one_pulse;
ELSE
next_state <= one_pulse;
END IF;
WHEN OTHERS =>
next_state <= hold;
END CASE;
END PROCESS nextstate_proc;
-- Concurrent Statements
-- Clocked output assignments
output <= output_cld;
END fsm;
可能对于小学生(adulteration)来说 用这种风格编写代码你可能会读不懂。
但是养成良好的编写代码习惯是很重要的,此段代码我已经在 alter 公司的娱乐工具 quartus II 上仿真过了,无错。
注意:输入 rst_rst 是复位信号,这个一定要有!
而 rst 就是你所提到的,所谓的控制信号。
output 就是输出信号无误了,也就是由他输出 脉冲。 频率也是没错的,仿真的时候注意好等复位结束后才输入控制信号,控制信号是高电平有效。
复位是 低电平。
咱用的是这个软件编写的代码 FPGA advantage ,这种程度的代码编写过程不过是10分钟,不过很稀奇国内的 green
hand 都没有学这玩意的倾向。
添加回答
举报