博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDLBits 系列(34)Serial two's complememter(Mealy and Moore FSM)
阅读量:2027 次
发布时间:2019-04-28

本文共 2641 字,大约阅读时间需要 8 分钟。

目录


Mealy 状态机

原题复现

The following diagram is a Mealy machine implementation of the 2's complementer. Implement using one-hot encoding.

尽管我不太清楚这是个为啥?

但既然状态转移图都给你了,设计一个mealy状态机应该不成问题:

我的设计

module top_module (    input clk,    input areset,    input x,    output z);         localparam A = 2'b01, B = 2'b10;    reg [1:0] state, next_state;    always@(*)begin        case(state)            A: begin                if(x) next_state = B;                 else next_state = A;            end            B: begin                next_state = B;            end            default: begin                next_state = A;            end        endcase    end        always@(posedge clk or posedge areset) begin        if(areset) state <= A;        else state <= next_state;    end        assign z = (state == A)?x:~x;        /*    reg z_mid;    always@(*)begin        case(state)            A: begin                if(x) z_mid = 1;                else z_mid = 0;            end            B: begin                if(x) z_mid = 0;                else z_mid = 1;            end            default: begin                z_mid = 0;            end        endcase    end        assign z = z_mid;    */endmodule

Moore 状态机

姊妹篇,用Moore状态机如何实现?

原题复现

You are to design a one-input one-output serial 2's complementer Moore state machine. The input (x) is a series of bits (one per clock cycle) beginning with the least-significant bit of the number, and the output (Z) is the 2's complement of the input. The machine will accept input numbers of arbitrary length. The circuit requires an asynchronous reset. The conversion begins when Reset is released and stops when Reset is asserted.

状态转移图

我们根据mealy状态机的状态转移图来画Moore状态机的状态转移图,然后完成设计。

我的设计

给出设计:

module top_module (    input clk,    input areset,    input x,    output z);         localparam A = 0, B = 1, C = 2, D = 3;    reg [1:0] state, next_state;    always@(*) begin        case(state)            A: begin                if(x) next_state = B;                else next_state = A;            end            B: begin                if(x) next_state = D;                else next_state = C;            end            C: begin                if(x) next_state = D;                else next_state = C;            end            D: begin                if(x) next_state = D;                else next_state = C;            end            default: begin                next_state = A;            end                    endcase    end    always@(posedge clk or posedge areset) begin        if(areset) state <= A;        else state <= next_state;        end        assign z = (state == B || state == C)? 1 : 0;        endmodule

 

 

转载地址:http://idcaf.baihongyu.com/

你可能感兴趣的文章
AJAX - 跨域
查看>>
T-SQL 运行时生成语句
查看>>
SQL Server 索引 之 书签查找 <第十一篇>
查看>>
T-SQL 变量
查看>>
SQL 操作结果集 -并集、差集、交集、结果集排序
查看>>
T-SQL 公用表表达式(CTE)
查看>>
T-SQL 基于列的逻辑表达式 (CASE)
查看>>
SQL Server 分区表
查看>>
SQL Server 非聚集索引的覆盖,连接,交叉和过滤 <第二篇>
查看>>
SQL Server执行计划的理解
查看>>
T-SQL游标
查看>>
T-SQL 批处理
查看>>
SQL Server 系统视图
查看>>
SQL 语句转换格式函数Cast、Convert
查看>>
SQL Server 存储过程
查看>>
SQL Server UDF用户自定义函数
查看>>
深入.Net字符串类型
查看>>
SQL Server系统存储过程
查看>>
SQL Server 事务语法
查看>>
SQL Server 表变量和临时表的区别
查看>>