![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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
| |
| |
| | #2 | ||
| Quote:
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:
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
__________________ Bits From Bytes - the best RepRap kit out there now featuring RepRap V3 with full electronics redesign based on PIC32MX440F256H (English) MySQL Blog (Serbian) Elco Blog (Serbian) Use forum to ask questions, do not use PP Last edited by arhi; 12th October 2009 at 05:05 AM. Reason: double spacing in code | |||
| |
| | #3 |
|
Look at this link, too: DAK Engineering - U2 Stepper Translator It's a nice project: a 16F84 programmed to drive two indipendent stepper motors. | |
| |
| | #4 |
|
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
| |
| |
| | #5 |
| |
| |
| | #6 |
| |
| |
| | #7 |
|
Remove the "CLRF PORTB" instructions... Code: ;clockwise
movlw b'0001'
movwf PORTB
call wait
(remove --> clrf PORTB)
| |
| |
| | #8 |
![]() 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 | |
| |
| | #9 |
|
Try swapping the stepper motor wires around a bit.
| |
| |
| | #10 |
|
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.
| |
| |
| | #11 |
|
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. | |
| |
| | #12 | |
| Quote:
| ||
| |
| | #13 |
|
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.
| |
| |
| | #14 |
|
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.
| |
| |
| | #15 |
|
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.
| |
| |
|
| 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 |