对于状态机的总结以及Gray码基本概念

一、状态机总结

状态机分为两种

一种称为Mealy状态机,它的时序逻辑输出不但取决于状态还取决于输入;

另外一种称为Moore状态机,它的输出只取决于当前的状态。实际的设计工作中大部分都是Mealy状态机。

有限状态机设计一般步骤:1、逻辑抽象,得出状态转换图;2、状态化简;3、状态分配;4、选定触发器的类型并求出状态方程、驱动方程和输出方程;5、按照方程得出逻辑图。

1、“111”序列检测器(米里型)

module fsm111 ( clk,rst,x,z)  ;
input  clk,rst,x;  output  reg z ;
reg[1:0]  state;
parameter  s0=2’b00,s1=2’b01,s2=2’b11;//状态转换图在心中,哈哈

always@(posedge clk or negedge rst)
  begin  if(!rst)  state<=s0;
         else  case(state)
         s0:begin  if(x)  state<=s1 ; 
                  else  state<=s0 ; end
         s1:begin  if(x)  state<=s2; 
                  else  state<=s0 ; end
s2:begin  if(x)  state<=s2 ; 
                  else  state<=s0 ; end
        defualt : state<=s0;
        
always @(state)
begin  case(state)
        s2: begin  if(x)  z=1’b1;
                  else  z=1’b0; 
defualt : z=1’b0;
 end
endmodule

2、“101”序列检测器(摩尔型)

module fsm101 ( clk,rst,x,z)  ;
input  clk,rst,x;  output  reg z ;
reg[1:0]  state,next_state;
parameter  s0=2’b00,s1=2’b01,s2=2’b11,s3=2’b10;//状态编码,采用格雷码

always@(posedge clk or negedge rst)
       begin   if(!rst)   state<=s0;
             else      state<=next_state;
       end
       
always(state or x)
begin
case(state)
         s0:begin  if(x)  next_state<=s1 ; 
                  else  next_state<=s0 ; end
         s1:begin  if(x)  next_state<=s1; 
                  else  next_state<=s2 ; end
s2:begin  if(x)  next_state<=s3 ; 
                  else  next_state<=s0 ; end
s3:begin  if(x)  next_state<=s1 ; 
                  else  next_state<=s2 ; end
        default :   state<=s0;
endcase
end

always @(state)
begin  case(state)
        s3:      z=1’b1;
        default:  z=1’b0; 
endcase
end
endmodule

3、“1001”序列检测器

module fsm1001 ( clk,clr,x,z)  ;
input  clk,clr,x;  output  reg z ;
reg[1:0]  state;
parameter  s0=2’b00,s1=2’b01;
parameter s2=2’b11,s3=2’b10;

always @(posedge clk or posedge clr)
begin  if(clr)  state<=s0;
else  case(state)
s0:begin  if(x) state<=s1 ; 
else  state<=s0 ; end
s1:begin  if(x) state<=s1; 
else  state<=s2 ; end
s2:begin  if(x) state<=s1 ; 
else  state<=s3 ; end
 s3:begin  if(x) state<=s1; 
else  state<=s0 ; end
defualt : state<=s0;

always  @(state)
begin  case(state)
s3: begin  if(x)  z=1’b1;
else  z=1’b0; 
defualt : z=1’b0;
 end
endmodule

二、Gray码基本概念

1、格雷码概念
在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同,则称这种编码为格雷码;另外由于最大数与最小数之间也仅一位数不同,即“首尾相连”,因此又称循环码或反射码;

2、优点:
若采用8421码,则数0111变到1000时四位均要变化,而在实际电路中,4位的变化不可能绝对同时发生,则计数中可能出现短暂的其它代码(1100、1111等)。在特定情况下可能导致电路状态错误或输入错误,使用格雷码可以避免这种错误。

3.Gray码的编码形式(我们讨论四位Gray码,二位三位方法相同)

十进制数4位二进制码四位典型Gray码
000000000
100010001
200100011
300110010
401000110
501010111
601100101
701110100
810001100
910011101
1010101111
1110111110
1211001010
1311011011
1411101001
1511111000
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值