463764339 发表于 2012-7-9 15:26:40

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

       
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 dirA, dirB;
        reg switch1, switch2;
        reg dirA, dirB;
        reg 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 sensor12 = {sensor1, sensor2};
        wire sensor13 = {sensor1, sensor3};
        wire 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

463764339 发表于 2012-7-10 21:25:55

复位信号改为下降沿触发,在下面if条件语句中改为复位信号低电平有效。如果不可以需要添加按键防抖模块进行按键防抖

zombes 发表于 2012-7-15 17:11:28

仿真试下,复位一直是什么信号啊?按键复位?那么复位时低电平有效
页: [1]
查看完整版本: 状态机—程序下到DE2-70上却始终维持复位状态,求指导!谢谢!