当前位置:网站首页>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
边栏推荐
- Generate shortcut
- 汇编 32位无符号加法计算器
- Quaternion multiplication
- [UDS unified diagnosis service] IV. typical diagnosis service (1) - diagnosis and communication management function unit
- Object array and object pointer
- 锚点定位——如何设置锚点居页面顶部距离,锚点定位并距离顶部一定偏移
- SDOI2009-HH的项链
- C language advanced notes 3
- 【UDS统一诊断服务】(补充)五、ECU bootloader开发要点详解 (2)
- cv_bridge 与opencv 版本不匹配的解决
猜你喜欢
信息学一本通-小球
OpenCV使用 GenericIndex 进行 KNN 搜索
[UDS unified diagnosis service] i. diagnosis overview (2) - main diagnosis protocols (K-line and can)
[ThreadX] ThreadX source code reading plan (I)
QT icon application
卷积神经网络实现CIFAR100数据集分类
[UDS unified diagnosis service] i. diagnosis overview (1) - diagnosis overview
【UDS统一诊断服务】五、诊断应用示例:Flash Bootloader
Collection of practical tips for C language (continuously updated)
For() loop parameter call order
随机推荐
提交本地仓库并同步码云仓库
undefined reference to `Nabo::NearestNeighbourSearch
HDU-Memory Control
[stepping on the pit] MELD in win11 wsl2 cannot be used normally. Problem repair
汇编 32位无符号加法计算器
【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能
产生随机数
C语言进阶要点笔记5
赛氪-zeal
ES6
Eigen 学习总结
深蓝学院激光slam 理论与实践 第三章激光雷达去畸变 作业习题
生成快捷方式
WMI技术介绍和应用
[ThreadX] ThreadX source code reading plan (I)
死区时间的分析与设置
C语言实现memcpy、memset、strcpy、strncpy、strcmp、strncmp、strlen
Understanding of SSH public key and private key
【UDS统一诊断服务】(补充)五、ECU bootloader开发要点详解 (2)
Notes on advanced points of C language 5