Sean Evanuik EE316-Section1 Lab5-4

advertisement
Sean Evanuik
EE316-Section1
Lab5-4-Phase Stepper Motor Controller
3/17/08
Objectives:
1)Understand the basics of a Stepper Motor
2)Learn how to interface a stepper motor with a micro controller
3)Write ccs c-code and picBasic Pro code to control the stepper motor with the micro controller
Equipment:
Experiment board, lab board, the necessary cables and wire to interface the two boards.
Experiment:
The experiment board and lab board were interfaced as follows.
Connect a Wire between Pin-1 (Collector) of J1, of the IR-PT Board, and Pin-1 (FSP) of J8, of
the Experiment Board. The IR-PT Board is mounted on the Lab Board. Also, Connect a Wire between
Pin-2 (Emitter) of J1, of the IR-PT Board, and Pin-2 (GND) of J8, of the Experiment Board.
Connect one end of a BNC to Grabber Lead Cable (Red Lead) to Pin-1 (FSP), of J8, of the
Experiment Board, and the other end to Channel-1 of the Oscilloscope.
Be sure to ground the Black Grabber Lead.
Connect the Stepper Motor of the Lab Board as Follows:
Connect a Wire between Pin-1 (Phase-1) of J5, of the Lab Board, and Pin-2 (P1) of J4, of the
Experiment Board.
Connect a Wire between Pin-2 (Phase-2) of J5, of the Lab Board, and Pin-1 (P2) of J4, of the
Experiment Board.
Connect a Wire between Pin-1 (Phase-3) of J6, of the Lab Board, and Pin-2 (P3) of J3, of the
Experiment Board.
Connect a Wire between Pin-2 (Phase-4) of J6, of the Lab Board, and Pin-1 (P4) of J3, of the
Experiment Board.
Connect a Wire between Pin-2 (GND) of J1, of the Lab Board, and Pin-2 (GND) of J8, of the
Experiment Board.
Using the original code provided two captures were taken for both the basic and c code. These two
captures were the time measurement between two pulses and the width of one pulse at the 50% voltage
point. By looking at the captures it can be seen that there was almost no difference in the time
measurements in the different codes. Please see the plots in the data section.
The next task was to control the stepper motor based on the input from the keypad. When “1” was
pushed the motor found the north position. The A, B, C, and D buttons provided 90 degree rotations in
a specific direction to put the stepper motor at a desired location.
Specifically:
Rotate 90 Degrees from North-to-East and from North-to-West, on Demand, after the Rotor has
been Set in the North Position, thru the use of the Infrared Photo-Transistor Circuit. Use Button “1” of
the Keypad to cause the Rotor to seek and then Stop in the North Position, as a Preset Control, before
moving the Rotor from
North-to-East or from North-to-West.
When the “A” Button is Pressed on the Keypad, the Rotor must rotate North-to-East and then Stop in
the East Position. When the “B” Button is Pressed on the Keypad, the Rotor must rotate East-to-North
and then stop in the North Position, once again.
When the “C” Button is Pressed on the Keypad, the Rotor must rotate North-to-West, and then Stop in
the West Position. When the “D” Button is Pressed on the Keypad, the Rotor must rotate West-toNorth, and then stop in the North Position, once again.
Data:
Basic Plots:
Pulse Width
Width of two Pulses
C Plots:
Pulse Width
Two Pulse Width
Conclusion:
This lab showed how a stepper motor can be controlled with the aid of an infrared photo
transistor circuit. Using the micro controller to find north by stepping a certain amount of degrees
when the infrared circuit was interrupted was also easy to do. This allowed the stepper motor to be
preset to the north direction before executing the other tasks. Overall this lab showed how a stepper
motor works and effectively showed how code can be used to easily rotate to any position desired.
Attached Code:
Basic:
KSCAN:
LCDOUT $FE, 1
'Clear the LCD
LCDOUT $FE, $80
'Set Cursor to Line 1, Position 0
LCDOUT "Scanning"
'Send "Scanning" to the LCD
SERout2 PORTC.6,396,["Scanning",13,10,10]
'Send "Scanning" to the HyperTerminal
'with a Carrage Return & 2 Line Feeds
HIGH PORTD.0
'Make 1st Row High to Scan for the Following:
PAUSE 500
INPUT PORTD.4
IF PORTD.4=1 THEN gosub PSENSE
'Check for Keypad Key "1"
PAUSE 100
LOW PORTD.1
HIGH PORTD.0
PAUSE 500
INPUT PORTD.7
IF PORTD.7=1 THEN gosub loopc
PAUSE 100
LOW PORTD.0
'Make 0th Row High to Scan for the Following:
'Check for Keypad Key "A" , Column-7
HIGH PORTD.1
PAUSE 500
INPUT PORTD.7
IF PORTD.7=1 THEN gosub loopcc
PAUSE 100
LOW PORTD.1
'Make 1st Row High to Scan for the Following:
HIGH PORTD.2
PAUSE 500
INPUT PORTD.7
IF PORTD.7=1 THEN gosub loopcc
PAUSE 100
LOW PORTD.2
'Make 2nd Row High to Scan for the Following:
HIGH PORTD.3
PAUSE 500
INPUT PORTD.7
IF PORTD.7=1 THEN gosub loopc
PAUSE 100
LOW PORTD.3
'Make 3rd Row High to Scan for the Following:
'Check for Keypad Key "B" , Column-7
'Check for Keypad Key "C" , Column-7
'Check for Keypad Key "D" , Column-7
GOTO KSCAN
CLOOP:
LOW PORTE.2
LCDOUT $FE,1
LCDOUT $FE, $80
LCDOUT "Clockwise"
LCDOUT $FE, $C0
LCDOUT "Rotation; Wave"
SEROUT2 PORTC.6,396,["The Motor is Rotating Clockwise; Wave",13,10,10]
loopcc: H=128
revcc:
PORTB=%00011111
PAUSE 5
PORTB=%00101111
PAUSE 5
PORTB=%01001111
PAUSE 5
PORTB=%10001111
PAUSE 5
H=H-1
IF H!=0 THEN revcc
return
loopc: H=128
revC: PORTB=%10001111
PAUSE 5
PORTB=%01001111
PAUSE 5
PORTB=%00101111
PAUSE 5
PORTB=%00011111
PAUSE 5
H=H-1
IF H!=0 THEN revc
return
CCLOOP: LOW PORTE.2
LCDOUT $FE,1
LCDOUT $FE, $80
LCDOUT "Counter"
LCDOUT $FE, $C0
LCDOUT "Rotation; Wave"
SEROUT2 PORTC.6,396,["The Motor is Rotating CounterClockwise; Wave",13,10,10]
CCMLP: PORTB=%00011111
PAUSE 5
PORTB=%00101111
PAUSE 5
PORTB=%01001111
PAUSE 5
PORTB=%10001111
PAUSE 5
GOTO CCMLP
PSENSE: LOW PORTE.2
LCDOUT $FE,1
LCDOUT $FE, $80
'
LCDOUT "North; Wave"
LCDOUT $FE, $C0
'
LCDOUT "Position Search"
SEROUT2 PORTC.6,396,["The Motor is Searching for the North Position; Wave",13,10,10]
'
'
PSLP:
PORTB=%00011111
PAUSE 5
PORTB=%00101111
PAUSE 5
PORTB=%01001111
PAUSE 5
PORTB=%10001111
PAUSE 5
INPUT PORTC.1
IF PORTC.1=0 THEN PNORTH
GOTO PSLP
'Infrared Photo-Transistor Circuit A Low on
'A Low onPortC, Bit-1 will occur when the
'IR-Light-Beam is Broken
PNORTH: H=40
ADVAN: PORTB=%00011111
PAUSE 5
PORTB=%00101111
PAUSE 5
PORTB=%01001111
PAUSE 5
PORTB=%10001111
PAUSE 5
H=H-1
IF H!=0 THEN ADVAN
LED:
HIGH PORTE.2
SEROUT2 PORTC.6,396,["The Motor is at the North Position",13,10,10]
return
end
C Code:
KSCAN:
lcd_putc(0x0c);
lcd_gotoxy(1,1);
printf(lcd_putc,"Scanning");
fprintf(HT, "\n\rScanning\n\r");
output_high(PIN_D0);
delay_ms(500);
D7 = input(PIN_D7);
if (D7) goto ALTR;
delay_ms(100);
output_low(PIN_D0);
output_high(PIN_D1);
delay_ms(500);
D7 = input(PIN_D7);
if (D7) goto PSENSE;
delay_ms(100);
output_low(PIN_D1);
:
output_high(PIN_D2);
delay_ms(500);
D7 = input(PIN_D7);
delay_ms(100);
output_low(PIN_D2);
output_high(PIN_D3);
delay_ms(500);
D7 = input(PIN_D7);
if (D7) goto CCLOOP;
delay_ms(100);
output_low(PIN_D3);
goto KSCAN;
CLOOP:
CMLP:
output_low(PIN_E2);
lcd_putc(0x0c);
lcd_gotoxy(1,1);
printf(lcd_putc,"Clockwise");
lcd_gotoxy(1,2);
printf(lcd_putc,"Rotation; Wave");
fprintf(HT, "\n\rThe Motor is Rotating Clockwise; Wave\n\r");
output_b(0b10001111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b00011111);
delay_ms(5);
goto CMLP;
CCLOOP: output_low(PIN_E2);
lcd_putc(0x0c);
lcd_gotoxy(1,1);
printf(lcd_putc,"Counter");
lcd_gotoxy(1,2);
printf(lcd_putc,"Rotation; Wave");
fprintf(HT, "\n\rThe Motor is Rotating CounterClockwise; Wave\n\r");
CCMLP: output_b(0b00011111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b10001111);
delay_ms(5);
goto CCMLP;
PSENSE: output_low(PIN_E2);
lcd_putc(0x0c);
lcd_gotoxy(1,1);
printf(lcd_putc,"North; Wave");
lcd_gotoxy(1,2);
printf(lcd_putc,"Position Search");
fprintf(HT, "\n\rThe Motor is Searching for the North Position; Wave\n\r");
PSLP:
output_b(0b00011111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b10001111);
delay_ms(5);
C1 = input(PIN_C1);
if (!C1) goto PNORTH;
goto PSLP;
PNORTH: H=40;
ADVAN: output_b(0b00011111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b10001111);
delay_ms(5);
H=H-1;
if (H!=0) goto ADVAN;
LED:
output_high(PIN_E2);
fprintf(HT, "\n\rThe Motor is at the North Position\n\r");
goto LED;
ALTR:
output_low(PIN_E2);
lcd_putc(0x0c);
lcd_gotoxy(1,1);
printf(lcd_putc,"Motor is; Wave");
lcd_gotoxy(1,2);
printf(lcd_putc,"Alternating");
fprintf(HT, "\n\rThe Motor is Alternating; Wave\n\r");
ALPCN: K=12;
ALPAC: output_b(0b10001111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b00011111);
delay_ms(5);
K=K-1;
if (K!=0) goto ALPAC;
ALPC:
output_b(0b10001111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b00011111);
delay_ms(5);
C1 = input(PIN_C1);
if (!C1) goto ALPCCN;
goto ALPC;
ALPCCN: J=12;
ALPACC: output_b(0b00011111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b10001111);
delay_ms(5);
J=J-1;
if (J!=0) goto ALPACC;
ALPCC: output_b(0b00011111);
delay_ms(5);
output_b(0b00101111);
delay_ms(5);
output_b(0b01001111);
delay_ms(5);
output_b(0b10001111);
delay_ms(5);
C1 = input(PIN_C1);
if (!C1) goto ALPCN;
goto ALPCC;
}
Download