集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1446|回复: 2

状态机—程序下到DE2-70上却始终维持复位状态,求指导!谢谢!

[复制链接]
463764339 发表于 2012-7-9 15:26:40 | 显示全部楼层 |阅读模式
       
module train (reset, clock, sensor1, sensor2, sensor3, sensor4, sensor5, switch1, switch2, switch3, dirA, dirB);
        input reset, clock, sensor1, sensor2, sensor3, sensor4, sensor5;
        output switch1, switch2, switch3;
        output [1:0] dirA, dirB;
        reg switch1, switch2;
        reg [1:0] dirA, dirB;
        reg [2:0] state;
        parameter ABout = 0, Ain = 1, Bin = 2, Astop = 3, Bstop = 4;
        always @(posedge clock or posedge reset)
                begin
                        if (reset)
                                state = ABout;
                        else
                        case (state)
                                ABout:
                                        case (sensor12)
                                                2'b 00: state = ABout;
                                                2'b 01: state = Bin;
                                                2'b 10: state = Ain;
                                                2'b 11: state = Ain;
                                                default: state = ABout;
                                        endcase
                                Ain:
                                        case (sensor24)
                                                2'b 00: state = Ain;
                                                2'b 01: state = ABout;
                                                2'b 10: state = Bstop;
                                                2'b 11: state = ABout;
                                                default: state = ABout;
                                        endcase
                                Bin:
                                        case (sensor13)
                                                2'b 00: state = Bin;
                                                2'b 01: state = ABout;
                                                2'b 10: state = Astop;
                                                2'b 11: state = ABout;
                                                default: state = ABout;
                                        endcase
                                Astop:
                                        if (sensor3)
                                                state = Ain;
                                        else
                                                state = Astop;
                                Bstop:
                                        if (sensor4)
                                                state = Bin;
                                        else
                                                state = Bstop;
                                default: state = ABout;               
                        endcase
                end
        wire [1:0] sensor12 = {sensor1, sensor2};
        wire [1:0] sensor13 = {sensor1, sensor3};
        wire [1:0] sensor24 = {sensor2, sensor4};
        wire switch3 = 0;
        always @(state)
                begin
                        case (state)
                                ABout:
                                        begin
                                                switch1 = 0;
                                                switch2 = 0;
                                                dirA = 2'b 01;
                                                dirB = 2'b 01;
                                        end
                                Ain:
                                        begin
                                                switch1 = 0;
                                                switch2 = 0;
                                                dirA = 2'b 01;
                                                dirB = 2'b 01;
                                        end
                                Bin:
                                        begin
                                                switch1 = 1;
                                                switch2 = 1;
                                                dirA = 2'b 01;
                                                dirB = 2'b 01;
                                        end
                                Astop:
                                        begin
                                                switch1 = 1;
                                                switch2 = 1;
                                                dirA = 2'b 00;
                                                dirB = 2'b 01;
                                        end
                                Bstop:
                                        begin
                                                switch1 = 0;
                                                switch2 = 0;
                                                dirA = 2'b 01;
                                                dirB = 2'b 00;
                                        end
                                default:
                                        begin
                                                switch1 = 0;
                                                switch2 = 0;
                                                dirA = 2'b 00;
                                                dirB = 2'b 00;
                                        end
                        endcase
                end       
endmodule

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?我要注册

x
 楼主| 463764339 发表于 2012-7-10 21:25:55 | 显示全部楼层
复位信号改为下降沿触发,在下面if条件语句中改为复位信号低电平有效。如果不可以需要添加按键防抖模块进行按键防抖
zombes 发表于 2012-7-15 17:11:28 | 显示全部楼层
仿真试下,复位一直是什么信号啊?按键复位?那么复位时低电平有效
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-26 01:49 , Processed in 0.067043 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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