# Lab Report for Motor Control

Topics: Binary numeral system, Hexadecimal, Rotation Pages: 7 (1108 words) Published: December 2, 2012
Exericise 1
In function “void Exercise_One()”, the third parameter “0xfe” of “cbDout(BOARD_NUM_0,FIRSTPORTA,0xfe)” is used to controlled “on-and-off” status of each coils; Specifically, the binary value of second digit of the hexadecimal number indicates that status, “1” for “off” while “0” for “on”; For example, “e” in binary is 1110, coil A is turned on (controlling coil A to D from the most right bit to most left). So to turn on coil C only, a binary number 1011 (in hexadecimal “b”) is needed and the code for it is shown as follows: cbDout(BOARD_NUM_0,FIRSTPORTA,0xfb)

Similarly to turn on coil C and D, a binary number 0011(in hexadecimal “3”) is needed and the code for it is shown as follows: cbDout(BOARD_NUM_0,FIRSTPORTA,0xf3)

Exercise 2
A counter-clockwise would be a reversed version of “Full_Step_CW()” as follows: void Full_Step_CCW()
{
unsigned short Step_Code ;
switch ( Step_Number)
{
case 0 : Step_Code = 0x09;
break;
case 1: Step_Code = 0x05;
break;
case 2: Step_Code = 0x06;
break;
case 3: Step_Code = 0x0a;
break;
default: Step_Code = 0x0f;
break;
cbDout(BOARD_NUM_0,FIRSTPORTA, Step_Code);
Step_Number++;
If(Step_Number == 4) Step_Number = 0;
}
}
According to table 1, a Full_Step_CW() , going from ‘a’ , ‘6’, ‘5’ to ‘9’ would rotate clock wise 7.5 degree per step. Then going from ‘9’, ‘5’, ‘6’ to ‘a’ would make it rotate counter clockwise and by calling it each time, the motor would rotate 1 step. To rotate counter-clockwise, in function “void Exercise_Two() “, the following code should be added. This would call the function “Full_Step_CCW()” 12 times. For the cases where the global variable “Step_Code”, it would be reset back to 0;

int a;
for(a=0; a<12; a++)
{
Full_Step_CCW();
Sleep(1000);
}
Exercise 3
By using the results in table 2 and similar principle in Exercise 2, the following two functions are written: void Half_Step_CW()
{
unsigned short Step_Code ;
switch ( Step_Number)
{
case 0 : Step_Code = 0x0e;
break;
case 1: Step_Code = 0x06;
break;
case 2: Step_Code = 0x07;
break;
case 3: Step_Code = 0x05;
break;
case 4 : Step_Code = 0x0d;
break;
case 5: Step_Code = 0x09;
break;
case 6: Step_Code = 0x0b;
break;
case 7: Step_Code = 0x0a;
break;
default: Step_Code = 0x0f;
break;
cbDout(BOARD_NUM_0,FIRSTPORTA, Step_Code);
Step_Number++;
If(Step_Number == 8) Step_Number = 0;
}
}

void Half_Step_CCW()
{
unsigned short Step_Code ;
switch ( Step_Number)
{
case 0 : Step_Code = 0x0a;
break;
case 1: Step_Code = 0x0b;
break;
case 2: Step_Code = 0x09;
break;
case 3: Step_Code = 0x0d;
break;
case 4 : Step_Code = 0x05;
break;
case 5: Step_Code = 0x07;
break;
case 6: Step_Code = 0x06;
break;
case 7: Step_Code = 0x0e;
break;
default: Step_Code = 0x0f;
break;
cbDout(BOARD_NUM_0,FIRSTPORTA, Step_Code);
Step_Number++;
If(Step_Number == 8) Step_Number = 0;
}
}

In “void Exercise_Three(), they should be called as follows: int a;
for(a=0; a<24; a++)
{
Half_Step_CW();
Sleep(1000);
}

int a;
for(a=0; a<24; a++)
{
Half_Step_CCW();
Sleep(1000);
}

Continue

In “Half_Step_CW()”, variable “Step_Number” is incremented by 1 each time and by “switch”, it would assign 8 different hexadecimal values to “Step_Code” and turns on different coils according to table 2. By calling this function each time, the motor would rotate half a step clockwise. Exercise 4

The following function “void Stepper_Control(…)” is written to control the direction, rate and number of steps of the motor by half step mode; void Stepper_Control unsigned short dir, int rate, unsigned int number) If( dir == CCW)

for( i = 0; i < number; i++)
{
current_rate = 500 – i*10;
if( current_rate != rate )
{
Half_Step_CCW();
Sleep( current_rate );
}
else
{
Half_Step_CCW();
Sleep( rate );
}
}
}//End of the Function

{
Int i,...

Please join StudyMode to read the full document