Page 626 - 3-2
P. 626

always @ (posedge clk,negedge rst)
            begin
                    if(!rst)cnt<=0;
                    else
                    begin
                            if(turn==1) //  반대로 움직이라는 신호가 왔으므로 방향전환을 한다.
                            begin
                                    direct<=!direct;
                                    if(time_count>=speed&&temp>=cnt) // temp   가 cnt 보다 클경우 스텝 모터 회
            전할당량을 채운것이며 타임 카운트가 스피드보다 클때는 회전을 했다는 의미이므로
                                    begin
                                            resolve<=0; //  리솔브를 0   으로 함으로써 모든 동작을 완료했다는 신
            호를 보냄
                                            cnt<=0; //  초기화 해줌
                                    end
                            end


                            if(resolve==0)
                            begin
                                    case (senser)
                                    4'b0001: begin cnt<=100; direct<=1; resolve<=1; end
            // 기계 먼 좌측 소리센서 시계 방향 회전, 90              도 회전
                                    4'b0010: begin cnt<=33; direct<=1; resolve<=1; end
            //  기계 가까운 좌측 소리센서 시계방향 회전 , 30               도 회전
                                    4'b0100: begin cnt<=33; direct<=0; resolve<=1; end
            //  기계 가까운 우측 소리센서 시계방향 회전 , 30               도 회전
                                    4'b1000: begin cnt<=100; direct<=0; resolve<=1; end
            //  기계 먼 우측 소리센서 시계방향 회전 , 90             도 회전


                                    default cnt<=0;
                                    endcase
                            end
                    end
            end
            always @ (posedge clk,negedge rst)
            begin
                    if(!rst)
                    begin
                            time_count<=0;
                            temp<=0;
                            step<=0;
                            stop_flag<=0;
                    end
                            else
                    begin


                                                         - 626 -
   621   622   623   624   625   626   627   628   629   630   631