当前位置:网站首页>VHDL finite state machine (FSM) code example
VHDL finite state machine (FSM) code example
2022-04-23 06:46:00 【Round moon】
Example 1 "10" detector
library ieee;
use ieee.std_logic_1164.all;
entity FSM is
port(Din,CLK,Reset:in std_logic;Dout:out std_logic);
end FSM;
architecture behave of FSM is
type state is(S0,S1,S2);
signal currentstate: state:=S0;
signal nextstate:state:=S0;
begin
state_trans:process(Din,currentstate)
begin
case currentstate is
when S0=>if Din='1' then nextstate<=S1;else nextstate<=S0;end if;
when S1=>if Din='0' then nextstate<=S2;else nextstate<=S1;end if;
when S2=>if Din='0' then nextstate<=S0;else nextstate<=S1;end if;
end case;
end process;
state_latch:process(CLK,reset)
begin
if reset='0' then
currentstate<=S0;
else
if CLK'event and CLk='1' then
currentstate<=nextstate;
end if;
end if;
end process;
Dout<='1' when currentstate=S2 else '0';
end behave;
Example 2 Decimal counter
library ieee;
use ieee.std_logic_1164.all;
entity FSM is
port(CLK,Reset,enable:in std_logic;Y:out std_logic_vector(3 downto 0);carry:out std_logic);
end FSM;
architecture behave of FSM is
type state is(S0,S1,S2,S3,S4,S5,S6,S7,S8,S9);
signal currentstate:state:=S0;
signal nextstate:state:=S0;
begin
process(currentstate)
begin
case currentstate is
when S0=>if enable='1' then nextstate<=S1;else nextstate<=S0;end if;
when S1=>if enable='1' then nextstate<=S2;else nextstate<=S1;end if;
when S2=>if enable='1' then nextstate<=S3;else nextstate<=S2;end if;
when S3=>if enable='1' then nextstate<=S4;else nextstate<=S3;end if;
when S4=>if enable='1' then nextstate<=S5;else nextstate<=S4;end if;
when S5=>if enable='1' then nextstate<=S6;else nextstate<=S5;end if;
when S6=>if enable='1' then nextstate<=S7;else nextstate<=S6;end if;
when S7=>if enable='1' then nextstate<=S8;else nextstate<=S7;end if;
when S8=>if enable='1' then nextstate<=S9;else nextstate<=S8;end if;
when S9=>if enable='1' then nextstate<=S0;else nextstate<=S9;end if;
end case;
end process;
process(clk,reset)
begin
if reset='0' then
currentstate<=S0;
elsif CLK'event and CLK='1' then
if enable='1' then
Currentstate<=nextstate;
end if;
end if;
end process;
with currentstate select
Y<="0000" when S0,
"0001" when S1,
"0010" when S2,
"0011" when S3,
"0100" when S4,
"0101" when S5,
"0110" when S6,
"0111" when S7,
"1000" when S8,
"1001" when S9;
carry<='1' when currentstate=S9 else '0';
end behave;
By-Round Moon
版权声明
本文为[Round moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230549498953.html
边栏推荐
- [UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
- cartographer_node 编译没问题,但是运行直接挂掉的bug
- cv_bridge 与opencv 版本不匹配的解决
- POJ-The Unique MST
- FOC 单电阻采样 位置环控制伺服电机
- HDU-Tunnel Warfare
- C语言 #和##的使用
- Camera calibration: key point method vs direct method
- VHDL-任意分频器(50%占空比)
- Declared as a global variable
猜你喜欢
[ThreadX] h743zi + lan8720 + ThreadX + netx duo transplantation
Collection of practical tips for C language (continuously updated)
HDU-Tunnel Warfare
【UDS统一诊断服务】三、应用层协议(2)
[UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)
【UDS统一诊断服务】五、诊断应用示例:Flash Bootloader
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
[UDS unified diagnostic service] III. application layer protocol (1)
三极管原理及特性分析
[UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture
随机推荐
HDU-Memory Control
Eigen 学习总结
C语言代码规范
Shell脚本的通配符和特殊符号
日志写法(带时间)
ES6面试题(参考文档)
C语言进阶要点笔记2
Call procedure of function
Modify registry values
C language advanced notes 3
CUDA project encountered a series of compilation problems after changing the environment (computer)
js获取链接?后边的参数名称或者值,根据url ?后的参数做判断
[UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)
对象的动态建立和释放,赋值和复制
往String原型上封装一个时间戳转日期的方法
TP download folder, compress folder and download
POJ-The Unique MST
C语言进阶要点笔记5
Matlab calibration board corner detection principle
逻辑回归原理及代码实现