Page 627 - 3-2
P. 627

if(turn==1)
                            stop_flag<=0; //  턴 신호가 올경우 모터에 회전 시작 신호를 줌


                            if(senser>=1&&resolve==0) //   센서값이 들어오고 정지상태 일경우 회전 신호를 줌


                            stop_flag<=0;


                            if(time_count>speed)    //speed 가 작아야 step   의 숫자가 빨리 변함->        속도가 빠름
                            begin
                                    time_count<=0;
                                    temp<=temp+1; //temp  의 숫자 증가
                                    step<=step+1;
                                    if(temp>cnt)  // 스텝모터가 cnt   만큼의 회전수를 채우면            정지시킴
                                    begin
                                            temp<=0;
                                            stop_flag<=1;


                                    end
                            end
                            else    time_count<=time_count+1;
                    end
            end
            always @ (posedge clk, negedge rst) // 방향에 따라 모터 회전 정or           역방향
            begin
                    if(!rst)
                    step_phase<=0;
                    else
                    begin
                            if(stop_flag==0)
                            begin
                                    if(direct==1)
                                    begin
                                            case(step)
                                            0: step_phase<=A;
                                            1: step_phase<=B;
                                            2: step_phase<=A_bar;
                                            3: step_phase<=B_bar;
                                            endcase
                                    end
                                    else
                                    begin
                                            case(step)
                                            3: step_phase<=A;
                                            2: step_phase<=B;
                                            1: step_phase<=A_bar;


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