Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

unipolar stepper motor

Status
Not open for further replies.
can any one help me with the code of how to turn the unipolar stepper motor clockwise and anticlockwise using assembly language and also provide me with reliable link or notes on how to program motors using assembly language
 
can any one help me with the code of how to turn the unipolar stepper motor clockwise and anticlockwise using assembly language

Here's the code, one button turn it clockwise, the other counter clockwise (the schematic attached to the post):
Code:
              LIST    p=16F84 ; PIC16F844 is the target processor

              #include "P16F84.INC" ; Include header file

              CBLOCK 0x10   ; Temporary storage                 
                 pos
                 dc1
                 dc2
              ENDC
              LIST    p=16F84 ; PIC16F844 is the target processor

              #include "P16F84.INC" ; Include header file

              CBLOCK 0x10   ; Temporary storage
              ENDC

              ORG   0
entrypoint    goto  start

              ORG   4
intvector     goto  intvector
        
start         clrw                    ; Zero.

              movwf   PORTB           ; Ensure PORTB is zero before we enable it.
              bsf     STATUS,RP0      ; Select Bank 1
              movlw   0xF0            ; Set port B bits 0-3 as outputs
              movwf   TRISB           ; Set TRISB register.           
                                                               
              bcf     STATUS,RP0      ; Select Bank 0
                 
              movlw   3  	      ; Initialize the motor position 
              movwf   pos                                             
              movwf   PORTB
              call    delay
              clrf    PORTB	      ; Motor drive off	

;Main loop               
loop	      btfss   PORTA,0         ; Test clockwise button
	      call    stepcw
	      btfss   PORTA,1         ; Test anti-clockwise button
	      call    stepccw
	      goto loop
                               
;Rotate one step clockwise                               
stepcw        bcf    STATUS,C	      ; Clear the carry flag
 	      btfsc  pos,3            ; Set carry if this bit set
 	      bsf    STATUS,C
	      rlf    pos,W	      ; Pick up and rotate the motor's current position
              andlw  0x0F             ; Mask to lower nibble
              movwf  pos
              movwf  PORTB	      ; Drive the outputs
              call   delay	      ; Wait
              clrf   PORTB            ; Clear the output
              return

;Rotate one step counter clockwise                                                                             		
stepccw       bcf    STATUS,C	      ; Clear the carry flag
	      btfsc  pos,0
	      bsf    pos,4
	      rrf    pos,W	      ; Pick up and rotate the motor's current position
              andlw  0x0F             ; Mask to lower nibble
              movwf  pos
              movwf  PORTB	      ; Drive the outputs
              call   delay	      ; Wait
              clrf   PORTB            ; Clear the output
              return

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

	      END

and also provide me with reliable link or notes on how to program motors using assembly language

You do not program motors, you program microcontroller. Different motors require different driving. This is unipolar stepper motor example as that's what you asked but this is 4 stage unipolar. There are also 5 stage, 6 stage, even 10 stage unipolar motors so you have to check the motor datasheet before you start making the driver for it, or - you purchase dedicated stepper motor driver and go from there.

The code is pretty simple and clear to understand. If you need help with asm language I strongly suggest you go trough Nigel's tutorials.
 

Attachments

  • unipolar.gif
    unipolar.gif
    4.8 KB · Views: 1,588
Last edited:
please take a look at this link Jones on Stepping Motor Types
it says to rotate the unipolar motor continuously, we just apply power to the two windings in sequence. Assuming positive logic, where a 1 means turning on the current through a motor winding. in the code below i have applied this sequence :Winding 1a 1000100010001000100010001
Winding 1b 0010001000100010001000100
Winding 2a 0100010001000100010001000
Winding 2b 0001000100010001000100010


but the motor does not rotate as animated GIF of figure 1.2 . what is wrong with the code

Code:
;Author : LEBOHANG MAPHOTHOANE
;PROGRAM FUNCTION:turning motor


	list		P=16F877a

    include    "P16F877a.inc"
                __config 0x3D18	
	;errorlevel -302, -207;suppress message 302 from the list
 ;Declarations:

 	CBLOCK 20h   ; Temporary storage                 
                 pos
                 dc1
                 dc2
                 delay
              ENDC



     
      
	org		0x0000
	goto Start	

;Program Start:

Start
    call Init             ;sets the values of ADCON0 and ADCON1 
                                       ;initialize porta

Main           
           
    ;clockwise 
       movlw b'0001'
       movwf PORTB
       call wait
       clrf PORTB

       movlw b'0100'
       movwf PORTB
       call wait
       clrf PORTB

       movlw b'0010'
       movwf PORTB
       call wait
       clrf PORTB
       
       movlw b'1000'
       movwf PORTB
       call wait
       clrf PORTB
       goto Main
       

wait     movlw   4	     ; Outer loop iteration count
	      movwf   dc1		
dl1	      clrf    dc2            ; Initialize inner loop
dl2	      nop
	      nop
	      decfsz  dc2,F         
	      goto    dl2
	      decfsz  dc1,F
	      goto    dl1
	      return







;Subroutines:
            
Init


              clrw                    ; Zero.

              movwf   PORTB           ; Ensure PORTB is zero before we enable it.
              bsf     STATUS,RP0      ; Select Bank 1
              movlw   0xF0            ; Set port B bits 0-3 as outputs
              movwf   TRISB           ; Set TRISB register.           
                                                               
              bcf     STATUS,RP0      ; Select Bank 0
                           
    
    
 
   
    return

    END
 
thanks. now it rotates in the manner i wanted it to. can u give me a link where i can read about USART(Universal Asynchrounous Receive and Transmit) and any tutorial or examples of code of USART written in assembly language, i want to connect a computer to a circuit board where i would have a pic16f877a and a motor connected. so that i can rotate the motor using the input from the computer. the cable i would be using to connect the computer and the pic16f877a is RS232.
 
Hello everybody,
Can anybody help me or suggest me some way of controlling steppers through RF.
Any suggestion for some circuitry, RF chip or anything useful. I can control steppers via matlab and independently but now wants to control them remotely through RF.

Regards.
 
thanks. now it rotates in the manner i wanted it to. can u give me a link where i can read about USART(Universal Asynchrounous Receive and Transmit) and any tutorial or examples of code of USART written in assembly language, i want to connect a computer to a circuit board where i would have a pic16f877a and a motor connected. so that i can rotate the motor using the input from the computer. the cable i would be using to connect the computer and the pic16f877a is RS232.

Check my PIC tutorials, which give both hardware and software examples.
 
I am happy to hear from you Nigel Goodwin, i have been trying to contact you. I used your tutorial 11 analogue inputs to make ADC, i appreciate that, ok im gona go through tutoril 7 and i will inform you if there is something i dont understant.
 
i have gone through the tutorials and mostly tutorial 7. i have a problem. i want to control the motor on a circuit board using computer whereby connection between the circuit board and the computer is made up of rs232 serial cable. The problem is that i do not know how to make computer interface like the one on the diagram, whereby if i click on the box(clockwise), the motor should rotate clockwise and if i click(anticlockwise) it should rotate anticlockwise. i think this two diagrams can explain well what iam trying to say.
 

Attachments

  • cpu.jpg
    cpu.jpg
    13.1 KB · Views: 318
  • CPU1.jpg
    CPU1.jpg
    46.2 KB · Views: 363
For as simple as possible, you just need to send two different data bytes, one for clockwise, one for anti-clockwise. To get slightly more complicated, you could also send the number of steps as well as the direction.
 
yes from the tutorials, i know how to sent data through rs232 and i understant what you mean. i want to make the interface using visual studio. can u help me with any material or tutorials of how to make computer interfaces
 
Yes i know how to send data through rs232. but i do not know how to create computer interface. i want to create the interface as shown on the previous thread using visual studio.im also not sure if the interface would be able to send data to rs232 since i wrote the code for transmission of data through rs232 using assembly language and its like visual studio uses C++ and C only. Can interface created using C++ be able to match with the code of rotating motor written in assembly language.
 
Yes i know how to send data through rs232. but i do not know how to create computer interface. i want to create the interface as shown on the previous thread using visual studio.im also not sure if the interface would be able to send data to rs232 since i wrote the code for transmission of data through rs232 using assembly language and its like visual studio uses C++ and C only. Can interface created using C++ be able to match with the code of rotating motor written in assembly language.

It makes no difference whatsoever what it's written in, the RS232 interface just sends text characters.
 
im not familiar with java language. The software JFrameBuilder(JBF_330) i have installed to create interface only support java. like you gave me the tutorials of how to transmit and receive date through rs232 using assembly language, could you please give me the same tutorilas but written in java language
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top