8b. Stepper motor interface

vtu mp 8b
Q) Drive a Stepper Motor interface to rotate the motor in specified direction (Clockwise or Counter-Clockwise) by N steps (Direction and N are specified by the examiner). Introduce suitable delay between successive steps.

This program will implement a stepper motor driving interface.

Algorithm:
Step 1: Initialize the control word 80H and store it in the control register.
Step 2: Initialize the number of steps (N) the stepper motor has to rotate.
Step 3: Coils are selected by storing 77H in AL register that is current is passed through coil.
Step 4: Send the data through Port C, hence initialize the Port C address.
Step 5: For clockwise rotation rotate the contents of AL register to right by 1 using ROR instruction and decrease the steps. For anticlockwise rotation rotate the contents of AL register to left by 1 using ROL instruction and decrease the steps.
Step 6: Introduce delay counter after each steps.
Step 7: Repeat the steps 5 & 6 until n>0
Step 8: Stop.

CODE:


Explanation:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
    CR EQU 0e803H
    PA EQU 0e800H
    PB EQU 0e801H
    PC EQU 0e802H
DATA ENDS
Programming model selected contains one data segment(DS) and one code segment (CS).
Our data segment contains three memory locations assigned with port addresses of the logical interface. Port A(PA), Port B(PB), Port C(PC) and Control registers(CR) are equated with appropriate port addresses.

CODE SEGMENT
START:   
MOV AX,DATA
MOV DS,AX

Code segment starts with initializing of data segment at the line 3 and 4 in the snippet.

MOV DX,CR
MOV AL,80H   
OUT DX,AL
Initializing stepper motor interface by activating control word.

MOV AL,77H   
MOV CX,8
MOV DX,PA   
OUT DX,AL
Move the number ‘77H’ to AL. This is the bit pattern you got to remember for the stepper motor. Rotating this number (left/right) will give each pattern for rotation(anti-clockwise/clockwise).
CX is loaded with 8. For rotating bits 8 times (one complete rotation).
Content of motor interfacing bit is outputted using OUT command with DX having output port address.

BACK:    
ROR AL,1   
OUT DX,AL
CALL DELAY
DEC CX
JNZ BACK
BACK is the label.
Right rotate the pattern bit by 1 and display the rotation bit using OUT command(for clockwise rotation. For anti clockwise rotation, perform ROL).
Call some delay time.
Decrease the counter value by 1 and CX if not equal to 0, jump to BACK.

After 8 iterations, one complete rotation of motor will be over. You need to stop at this point.

MOV AH,4CH
INT 21H
DELAY PROC NEAR
PUSH CX
PUSH BX
MOV CX,0FFFFH
BAC1:    MOV BX,0FFFFH
BAC:    
        DEC BX
         JNZ BAC
         LOOP BAC1
         POP BX
         POP CX
         RET
DELAY ENDP
CODE ENDS
END START

Now that you have performed one complete rotation, Terminate the program.
Delay procedure remains same.

Output:
Seen in stepper motor interface.

He is a simple passionate tech freak who himself is an engineering student at Canara Engineering college. He likes App Development, Web designing, Blogging, Youtubing, Debugging and also is a CodeGeek!

Sharing is sexy!

Related Articles

Share your views about this article!