Thursday 3 January 2013

Programming Full Step Sequence

►Programming Full step Sequence

►C Programming
I am assuming that stepper motor is connected at Port 1.0 to Port 1.3. Adjusting the delay will increase or decrease the speed of the motor. Here just for demonstration i have taken some delay, you can change it as you want.

[Tip: Do testing.. ]




CODE:
#include <REG2051.H>.
#define stepper P1
void delay();

void main(){
        while(1){
                stepper = 0x0C;
                delay();
                stepper = 0x06;
                delay();
                stepper = 0x03;
                delay();
                stepper = 0x09;
                delay();
        }
}

void delay(){
        unsigned char i,j,k;
        for(i=0;i<6;i++)
        for(j=0;j<255;j++)
       for(k=0;k<255;k++);
}



►Assembly Programming

CODE:
        org 0H

stepper equ P1

main:
        mov stepper, #0CH
        acall delay
        mov stepper, #06H
        acall delay
        mov stepper, #03H
        acall delay
        mov stepper, #09H
        acall delay
        sjmp main

delay:
        mov r7,#4
wait2:
        mov r6,#0FFH
wait1:
        mov r5,#0FFH
wait:
        djnz r5,wait
        djnz r6,wait1
        djnz r7,wait2
        ret
        end


The working of the above code can be seen in the demo animation below.

unipolar stepper motor in full step sequence

No comments:

Post a Comment