搜索
bottom↓
回复: 2

请大家帮我看下这个状态机

[复制链接]

出0入0汤圆

发表于 2009-12-8 20:49:37 | 显示全部楼层 |阅读模式

(原文件名:1.JPG)

module        s1 (clk,rst_n,light);
        input clk;
        input rst_n;
        output [7:0] light;
       
        parameter s0=4'b0000,
                  s1=4'b0001,
                  s2=4'b0010,
                  s22=4'b0011,
                  s3=4'b0011,
                  s33=4'b0100,
                  s4=4'b0100,
                  s44=4'b0101;
        reg [2:0] cnt;
                  
        reg [7:0] light_temp;
        assign light=light_temp;
        reg [2:0] state,next_state;
       
       
        always @ (posedge clk)
                if(!rst_n)
                        state<=s0;
                else
                        state<=next_state;
                       
        always @ (state)
                        case(state)       
                                s0:begin
                                        light_temp=8'b0000_0001;
                                        end
                                s1:begin
                                        light_temp<={light_temp[6:0],light_temp[7]};
                                        end
                                s2:begin
                                        light_temp<=8'b1000_0000;
                                        end
                                s22:begin
                                        light_temp<={light_temp[0],light_temp[7:1]};
                                        end
                                s3:begin
                                        light_temp<=8'b0001_1000;
                                        end
                                s33:begin
                                        light_temp[7:4]<={light_temp[6:4],light_temp[7]};
                                        light_temp[3:0]<={light_temp[0],light_temp[3:1]};
                                        end
                                s4:begin
                                        light_temp<=8'b1000_0001;
                                        end
                                s44:begin
                                        light_temp[7:4]<={light_temp[4],light_temp[7:5]};
                                        light_temp[3:0]<={light_temp[2:0],light_temp[3]};
                                        end
                                default:light_temp<=light_temp;
                        endcase
                       
        always @ (state or cnt)
                        case(state)
                                        s0:next_state<=s1;
                                        s1:
                                                begin
                                                if(cnt==7)
                                                        begin
                                                        next_state<=s2;
                                                        cnt<=0;
                                                        end
                                                else
                                                        begin
                                                        next_state<=s1;
                                                        cnt<=cnt+1;
                                                        end
                                                end
                                        s2:
                                                begin
                                                next_state<=s22;
                                                end
                                               
                                        s22:begin
                                                if(cnt==7)
                                                        begin
                                                        next_state<=s3;
                                                        cnt<=0;
                                                        end
                                                else
                                                        begin
                                                        next_state<=s22;
                                                        cnt<=cnt+1;
                                                        end
                                                end
                                        s3:begin
                                                next_state<=s33;
                                                end
                                        s33:begin
                                                if(cnt==3)
                                                        begin
                                                        next_state<=s4;
                                                        cnt<=0;
                                                        end
                                                else
                                                        begin
                                                        next_state<=s33;
                                                        cnt<=cnt+1;
                                                        end
                                                end
                                        s4:
                                                begin
                                                next_state<=s44;
                                                end
                                        s44:begin
                                                if(cnt==3)
                                                        begin
                                                        next_state<=s1;
                                                        cnt<=0;
                                                        end
                                                else
                                                        begin
                                                        next_state<=s44;
                                                        cnt<=cnt+1;
                                                        end
                                                 end
                                        default:next_state<=s1;
                                        endcase
       
endmodule

出0入0汤圆

 楼主| 发表于 2009-12-8 20:50:03 | 显示全部楼层
为什么会出现孤立的状态

出0入0汤圆

 楼主| 发表于 2009-12-8 20:56:22 | 显示全部楼层
我知道了。。。。。粗心,前面的状态分配有问题
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-3 16:39

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表