惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
B
Blog
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Jina AI
Jina AI
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
L
LangChain Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
Y
Y Combinator Blog
F
Fortinet All Blogs
H
Help Net Security
B
Blog RSS Feed
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题

博客园 - yf.x

超声波测距#倒车雷达#DE10-Lite 按键计数器#DE10-Lite 按键消抖#DE10-Lite 流水呼吸灯v2#DE10-Lite 流水呼吸灯-v1#DE10-Lite 呼吸灯-#DE10-Lite 流水灯#DE10-Lite#Verilog 补码FSM-HDLbits 串行数据流输出其中的数据位-HDLbits 串行数据接收判断-HDLbits 输出PS2数据流-HDLbits PS2数据流检测状态机-HDLbits 独热码状态机-HDLbits 旅鼠4-HDLbits 旅鼠游戏3-HDLbits 旅鼠游戏2-HDLbits 旅鼠游戏--HDLbits 水库水位控制问题-HDLbits 康威生命游戏-hdlbits
HDLBits_review 2015fsm
yf.x · 2026-01-28 · via 博客园 - yf.x

题目:

我们将要创建一个计时器:

1. 在检测到特定模式1101时启动;

2. 再移动4位以确定延时时间;

3. 等待计数器计数完成;

4. 通知用户,并等待用户确认定时。

在这个题目里,只实现控制计时器的有限状态机。这里不包括数据路径(计数器和一些比较器)。

串行数据从数据输入引脚获取。当接收到1101时,状态机输出shift_ena4个时钟周期。

之后,状态机开始计数输出,等待计数。等待输入done_counting为1.

此时,状态机断言计数完成。并等待ack为1,然后重置,等待下一个1101。

复位后进入初始状态,用来等待接收1101序列。

下面时预期的输入,输出时序。一旦检测到1101后,状态机不再关注数据输入,直到所有其他操作完成后恢复搜索。

image

 状态转换:

image

 代码:

module top_module (
input clk,
input reset, // Synchronous reset
input data,
output shift_ena,
output counting,
input done_counting,
output done,
input ack );
parameter S=0,S1=1,S11=2,S110=3,B0=4,B1=5,B2=6,B3=7,Count=8,Wait=9;
reg [3:0]state,next_state;

always @(posedge clk)
if(reset)
state<=S;
else
state<=next_state;

always @(*)
case(state)
S:next_state=data?S1:S;
S1:next_state=data?S11:S;
S11:next_state=data?S11:S110;
S110:next_state=data?B0:S;
B0:next_state=B1;
B1:next_state=B2;
B2:next_state=B3;
B3:next_state=Count;
Count:next_state=done_counting?Wait:Count;
Wait:next_state=ack?S:Wait;
default:next_state=S;
endcase

assign shift_ena=(state==B0 || state==B1 || state==B2 || state==B3);
assign counting=(state==Count);
assign done=(state==Wait);
endmodule