Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 12th October 2009, 01:01 AM   #1
Default unipolar stepper motor

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
lebohangmaphothoane is offline  
Old 12th October 2009, 05:04 AM   #2
Default

Quote:
Originally Posted by lebohangmaphothoane View Post
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
Quote:
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.
Nigel's PIC Tutorial Page
Attached Thumbnails
unipolar stepper motor-unipolar.gif  

Last edited by arhi; 12th October 2009 at 05:05 AM. Reason: double spacing in code
arhi is offline  
Old 12th October 2009, 02:23 PM   #3
Default

Look at this link, too:

DAK Engineering - U2 Stepper Translator

It's a nice project: a 16F84 programmed to drive two indipendent stepper motors.
Arkham00 is offline  
Old 15th October 2009, 04:32 AM   #4
Default

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
lebohangmaphothoane is offline  
Old 15th October 2009, 04:40 AM   #5
Default

lebohangmaphothoane is offline  
Old 15th October 2009, 04:44 AM   #6
Default

lebohangmaphothoane is offline  
Old 15th October 2009, 11:32 AM   #7
Default

Remove the "CLRF PORTB" instructions...

Code:
    ;clockwise 
       movlw b'0001'
       movwf PORTB
       call wait
        (remove --> clrf PORTB)
and try that.
Mr RB is offline  
Old 16th October 2009, 02:50 AM   #8
Default

unipolar stepper motor-circuit.jpg

Last Loaded TST.zip
the following attachments shows the circuit diagram i constructed and i tested the system using ISIS 7 Professional. still after removing the clearing of port b , the motor does not rotate. the way i want it to rotate. or is the circuit diagram wrong
lebohangmaphothoane is offline  
Old 16th October 2009, 11:54 AM   #9
Default

Try swapping the stepper motor wires around a bit.
Mr RB is offline  
Old 17th October 2009, 03:19 AM   #10
Default

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.
lebohangmaphothoane is offline  
Old 17th October 2009, 08:06 AM   #11
Default

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.
Meesam is offline  
Old 17th October 2009, 09:04 AM   #12
Default

Quote:
Originally Posted by lebohangmaphothoane View Post
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 21st October 2009, 02:51 AM   #13
Smile

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.
lebohangmaphothoane is offline  
Old 5th November 2009, 03:07 AM   #14
Default

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.
Attached Thumbnails
unipolar stepper motor-cpu.jpg   unipolar stepper motor-cpu1.jpg  
lebohangmaphothoane is offline  
Old 5th November 2009, 09:06 AM   #15
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply

Tags
motor, stepper, unipolar

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Unipolar Stepper Motor Driver (need assistance) mrfunkyjay Electronic Projects Design/Ideas/Reviews 7 31st May 2009 10:09 AM
Unipolar stepper with ULN 2003 Ajit Barve Electronic Projects Design/Ideas/Reviews 2 6th April 2008 07:44 PM
Unipolar Stepper Motor Drive Usig Bipolar Driver anjanadev Electronic Projects Design/Ideas/Reviews 2 28th February 2008 05:00 AM
Driving a unipolar stepper motor Wingmax Robotics Chat 0 22nd October 2007 02:01 PM
Unipolar Stepper Motor Controller Wasp Micro Controllers 2 1st November 2005 10:34 AM



All times are GMT. The time now is 02:04 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker