verilog经典三段式状态机设计实例(共7页).docx

上传人:飞****2 文档编号:13481655 上传时间:2022-04-29 格式:DOCX 页数:7 大小:124.43KB
返回 下载 相关 举报
verilog经典三段式状态机设计实例(共7页).docx_第1页
第1页 / 共7页
verilog经典三段式状态机设计实例(共7页).docx_第2页
第2页 / 共7页
点击查看更多>>
资源描述

《verilog经典三段式状态机设计实例(共7页).docx》由会员分享,可在线阅读,更多相关《verilog经典三段式状态机设计实例(共7页).docx(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上Moore型verilog源代码:FSM实现10010串的检测Moore状态转移图module moorefsm(clk,rst,a,z); input clk,rst; input a; output z; reg z; reg 3:0 currentstate,nextstate; parameter S0 = 4b0000; parameter S1 = 4b0001; parameter S2 = 4b0010; parameter S3 = 4b0011; parameter S4 = 4b0100; parameter S5 = 4b0101; alway

2、s(posedge clk or negedge rst) begin if(!rst) currentstate = S0; else currentstate = nextstate; endalways(currentstate or a or rst) begin if(!rst) nextstate = S0; else case(currentstate) S0: nextstate = (a=1)?S1:S0; S1: nextstate = (a=0)?S2:S1; S2: nextstate = (a=0)?S3:S1; S3: nextstate = (a=1)?S4:S0

3、; S4: nextstate = (a=0)?S5:S1; S5: nextstate = (a=0)?S3:S1; default: nextstate = S0; endcase endalways(rst or currentstate) begin if(!rst) z = 0; else case(currentstate) S0: z = 0;S1: z = 0;S2: z = 0; S3: z = 0;S4: z = 0;S5: z = 1; default: z = 0; endcase endendmodule moorefsm测试模块testbench module tb

4、_fsm; reg clk,rst; reg a; wire z; moorefsm fsm(.clk(clk),.rst(rst),.a(a),.z(z); initial begin clk = 0; rst = 1; #5 rst = 0; #3 rst = 1; #20 a = 1; #100 a = 1; #100 a = 0; #100 a = 0; #100 a = 1; #100 a = 0; #100 a = 0; #100 a = 1; #100 a = 0; #100 a = 0; #100 a = 0; #100 a = 0; #100 a = 1; #100 a =

5、0; #100 a = 0; #100 a = 1; #100 a = 0; #100 a = 1; #100 a = 0; end always #50 clk = clk;endmodule Mealy型verilog源代码:FSM实现10010串的检测Mealy状态转移图module mealyfsm(clk,rst,a,z); input clk; input rst; input a; output z; reg z; reg 3:0 temp_z; reg 3:0 currentstate,nextstate; parameter S0 = 4b0000; parameter S1

6、 = 4b0001; parameter S2 = 4b0010; parameter S3 = 4b0011; parameter S4 = 4b0100;always(posedge clk or negedge rst) if(!rst) currentstate = S0; else currentstate = nextstate;always(currentstate or a or rst) if(!rst) nextstate = S0; else case(currentstate) S0: nextstate = (a = 1)? S1 : S0; S1: nextstat

7、e = (a = 0)? S2 : S1; S2: nextstate = (a = 0)? S3 : S1; S3: nextstate = (a = 1)? S4 : S0; S4: nextstate = (a = 0)? S2 : S0; default:nextstate = S0; endcase always(rst or currentstate or a) if(!rst) temp_z = 0; else case(currentstate) S0: temp_z = 0; S1: temp_z = 0; S2: temp_z = 0; S3: temp_z = 0; S4

8、: temp_z = (a = 0)? 1 : 0; default:temp_z = 0; endcase always(posedge clk or negedge rst) if(!rst) z = 0; else begin if(temp_z = 1)&(nextstate = S2) z = 1; else z = 0; endendmodule mealyfsm测试模块testbench module tb_fsm; reg clk,rst; reg a; wire z; mealyfsm fsm(.clk(clk),.rst(rst),.a(a),.z(z); initial

9、begin clk = 0; rst = 1; #5 rst = 0; #3 rst = 1; #20 a = 1; #100 a = 1; #100 a = 0; #100 a = 0; #100 a = 1; #100 a = 0; #100 a = 0; #100 a = 1; #100 a = 0; #100 a = 0; #100 a = 0; #100 a = 0; #100 a = 1; #100 a = 0; #100 a = 0; #100 a = 1; #100 a = 0; #100 a = 1; #100 a = 0; end always #50 clk = clk;endmodule 专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁