Selasa, 13 Juni 2017

Mengatur Arah Putaran Stepper Motor

Ada beberapa rangkaian yang dapat mengatur arah putaran stepper motor dengan menggunakan mikrokontroller.
Dipasaran juga sudah tersedia modul kit yang dapat digunakan untuk mengatur arah stepper motor.
Dibawah ini adalah rangkaian simple yang dapat digunakan untuk mengatur arah putaran motor.
Tombol push buttom yang ada pada rangkaian adalah untuk arah putaran motor searah jarum jam atau berlawanan arah jarum jam.
IC ULN2002A untuk interface antara output PIC dan stepper motor.

Berikut contoh programnya :

                   
              #include "P16F84.INC" 

              CBLOCK 0x10   
              ENDC

              ORG   0
entrypoint    goto  start

              ORG   4
intvector     goto  intvector
        
start         clrw                    

              movwf   PORTB          
              bsf     STATUS,RP0     
              movlw   0xF0            
              movwf   TRISB                    
                                                               
              bcf     STATUS,RP0      
                 
              movlw   3          
              movwf   pos                                             
              movwf   PORTB
              call    delay
              clrf    PORTB      

;Main loop               
loop      btfss   PORTA,0         
     call    stepcw
     btfss   PORTA,1         
     call    stepccw
     goto loop
                               
;Rotate one step clockwise                               
stepcw        bcf    STATUS,C       
       btfsc  pos,3            
       bsf    STATUS,C
     rlf    pos,W       
              andlw  0x0F             
              movwf  pos
              movwf  PORTB       
              call   delay       
              clrf   PORTB           
              return

;Rotate one step counter clockwise                                                                            
stepccw       bcf    STATUS,C      ; Clear the carry flag
     btfsc  pos,0
     bsf    pos,4
     rrf    pos,W       
              andlw  0x0F             
              movwf  pos
              movwf  PORTB       
              call   delay       
              clrf   PORTB    
              return

; This routine implements the delay between steps,
; and thus controls the motor speed.
delay         movlw   18      
     movwf   dc1
dl1      clrf    dc2            
dl2      nop
     nop
     decfsz  dc2,F         
     goto    dl2
     decfsz  dc1,F
     goto    dl1
     return

     END