FPGA之有限状态机
来源:互联网 发布:千牛首页的店铺数据 编辑:程序博客网 时间:2024/06/04 19:31
FPGA之有限状态机 - Assassinn - 博客园
Assassinn
FPGA之有限状态机
独热码编程例:
module fsm(clock,reset,a,f,g);input clock,reset;input a;output f,g;reg f,g;reg [3:0]state;parameter idle=4'b0000, start=4'b0010, stop=4'b0100, clear=4'b1000;always@(posedge clock)if(!reset) begin state=idle; f<=0; g<=0; endelse case(state) idle: begin if(a) begin state<=1; g<=0; end else state<=idle; end start:begin if(!a) state<=stop; else state<=start; end stop: begin if(a) begin state<=clear; f<=1; end else state<=stop; end clear:begin if(!a) begin state<=idle; f<=0; g<=1; end else state<=clear; end default: state<=idle; endcaseendmodule
Other method to write this code:
module fsm(clock,reset,a,f,g);inpout clock,reset,a;output f,g;reg [1:0] state;wire [1:0] nextstate;parameter idle=2'b00, start=2'b01; stop=2'b10,clear=2'b11;always@(posedge clock) if(!reset) begin state<=idle; end else state<=nextstate; assign nextstate= (state==idle) ? (a ? start : idle) : (state==start) ? (!a ? stop : start): (state==stop) ? (a ? clear : stop) : (state==clear) ?(!a ? idle : clear) : idle; assign f=((state==stop)&&a); assign g=((state==clear)&&(!a || !reset))endmodule
combine posedge always module with voltage always module
wire nextstate;always@(posedge clock) if(!reset) begin state<=idle; f<=0; g<=0; end else state<=nextstate;always@(a or state) f=0; g=0; if(state==idle) if(a) nextstate=start; else nextstate=idle; else if(state==start) if(!a) nextstate=stop; else nextstate=start; else if(state==stop) if(a) begin nextstate=clear; f=1; end else nextstate=stop; else if(state==clear) if(a) nextstate=clear; else begin nextstate=idle; f=0; g=1; end else default nextstate=idle;
有限状态机一般步骤:
1.逻辑关系转为状态转换图或者状态转换表;
2.状态编码,Gary码,独热码之类;
3.选定触发器的类型(电平出发还是上升沿或下降沿出触发),并求出状态方程,驱动方程,输出方程;
4.按照方程得出逻辑图;
Carry out a simple processor
module sprocessor(instr, out);// instr 17,16bit choose mode;15-8,data one;7:0;data two;input [17:0]instr;output [8:0]out;reg [8:0]out;reg fun;reg [7:0]opr1;reg [7:0]opr2;function [16:0]mount;input [17:0]instr;reg [1:0]fun_how;reg [7:0]opr1;reg [7:0]opr2;reg ch;beginfun_how=instr[17:16];opr2=instr[7:0];case(fun_how) 2'b00: begin ch=1; opr1=instr[15:8]; end 2'b01: begin ch=0; opr1=instr[15:8]; end 2'b10: begin ch=1; opr1=1; end 2'b11: begin ch=0; opr1=1; endendcasemount={ch,opr1,opr2};endendfunctionalways@(instr)begin{fun,opr1,opr2}=mount(instr);if(fun==1) out=opr1+opr2;else out=opr1-opr2;endendmodule
posted on 2017-10-25 16:06 http://www.cnblogs.com/assassinn/‘>Assassinn 阅读(…) 评论(…) 编辑 收藏
</div><a name="!comments"></a><div id="blog-comments-placeholder"></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
fixPostBody(); setTimeout(function () { incrementViewCount(cb_entryId); }, 50); deliverAdT2(); deliverAdC1(); deliverAdC2(); loadNewsAndKb(); loadBlogSignature(); LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid); GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate); loadOptUnderPost(); GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);
阅读全文
0 0
- FPGA之有限状态机
- 有限状态机的FPGA实现
- FPGA--有限状态机(FSM)的设计
- fpga设计思想(二):有限状态机
- unity AI之有限状态机
- 一种基于FPGA有限状态机思想的RS485 C底层驱动
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 有限状态机
- 聊一聊PCB规划、布局和布线方面的设计技巧
- Android 线程通信(Handler + Message + Looper) 2
- String、StringBuffer、StringBuilder的区别
- Android项目The type R is already defined
- Seafile与花生壳实现网络网盘-yellowcong
- FPGA之有限状态机
- HandlerThread 源码解析
- 高级命令行文本处理cut,sed,awk
- Parted分区
- JS插件(1)--- autocomplete 异步加载下拉数据
- Codeforces Round #442(Div.2) B.Nikita and string(线性DP)
- 深度学习与神经网络-吴恩达(Part2Week3)-超参数调试、Batch正则化和程序框架
- pytorch学习笔记(二) 其他机制
- 欧拉函数 codeforces 776E