Académique Documents
Professionnel Documents
Culture Documents
Home
Kits are available for this project from Talking Electronics for $25.00 plus postage. See more projects using PIC micros: Elektor,EPE,Silicon Chip "Pick-A-PIC."
1 di 27
13/09/2012 8.13
2 di 27
13/09/2012 8.13
3 di 27
13/09/2012 8.13
A STEPPER MOTOR
A stepper motor consists of a number of stationary coils and these are turned on and pull a rotary magnet towards the coil. This action turns a shaft. But you must turn the coils on and off at the right moment to create rotary movement. This requires an external circuit consisting of pulses and these pulses must contain voltage and current to deliver energy to the stepper motor. To understand how a stepper motor works, you just need to know the fact that a coil will attract a magnet when a current flows and it will repel the magnet when the current flows in the opposite direction. In the following animation you can see an armature (rotor) being pulled around by turning on one or more coils.
Note that 8 steps can be created with 4 coils by turning them on individually or in pairs:
Here is another diagram to show how the rotor is moved by half-step intervals:
4 di 27
13/09/2012 8.13
UNIPOLAR ANIMATION
The following animation shows a 6 wire stepper motor. It can be converted to a 5-wire stepper motor by connecting the two centre taps together to the positive supply. The two ends of each winding are alternately grounded to reverse the direction of the field provided by that winding. The cross section shown is a 30 degree per step motor. Motor winding number 1 is distributed between the top and bottom stator pole, while motor winding number 2 is distributed between the left and right motor poles. The rotor is a permanent magnet with 6 poles, 3 south and 3 north, arranged around its circumference. As shown in the figure, the current flowing from the center tap of winding 1 to terminal "a" causes the top stator pole to be a north pole while the bottom stator pole is a south pole. This attracts the rotor into the position shown. If the power to winding 1 is removed and winding 2 is energised, the rotor will turn 30 degrees, or one step. By turning on two windings during part of the cycle, a half-step can be introduced. This is shown in the animation. It takes three complete cycles of the control system to turn this 6-pole rotor one revolution.
5 di 27
13/09/2012 8.13
HALF STEPPING
With half stepping, the drive alternates between two phases ON and a single phase ON. This increases the angular resolution, but the motor also has less torque (approx 70%) at the half step position (where only a single phase is on). This can be increased by increasing the current in the active winding. Half-stepping increases the accuracy of the output. This is what we have done in this project. To keep the theory simple, we are not going into the waveforms needed to produce rotation, however we need to explain how the coils are connected as some motors have 5, 6 or 8 leads (wires). 4-wire stepper motors:
This type of motor has only one winding per stator pole. This is called a Unifilar winding (uni meaning one). As we mentioned above, the winding must see reverse voltage to produce rotation and this type of motor is not covered in this project. 6-wire stepper motors:
6 di 27
13/09/2012 8.13
6-wire stepper motors have two identical sets of windings on each stator pole. This is called bifilar winding and this type of winding configuration simplifies operation in that delivering current from one coil then another, wound in the opposite direction, will reverse the rotation of the motor shaft. Whereas, in a unifilar application, to change direction requires reversing the current in the same winding, as mentioned above. 5-wire stepper motors:
5-wire stepper motors simply have the centre-tap of each winding connected inside the motor or on a terminal-block. 8-wire stepper motors:
7 di 27
13/09/2012 8.13
8-wire stepper motors simply have the wires from the two coils brought out separately. This arrangement offers the flexibility of either a series or parallel connection. But this will bring it to a 4-wire device and require voltage reversal to produce rotation. You can also search the web for details on connecting the windings for high torque but this is beyond the scope of this article. The type of stepper motor we will be covering are 5, 6 or 8-lead Unipolar stepper motors.
8 di 27
13/09/2012 8.13
9 di 27
13/09/2012 8.13
If you do not have a schematic diagram for your stepper motor - for example if it was salvaged from an old printer - it is very easy to work out the wiring. Use a multimeter to measure the resistance of each coil. All four coils will have identical resistance. If they did not, the motor would not function properly. The resistance may be 100 ohms. If a pair of wires measures 200 ohms, you are measuring between two live ends. In other words, you are measuring the resistance of TWO COILS. If you have a 5 wire stepper motor, it will be very easy to find the common wire as every other wires will have a resistance of 100 ohms. For the 6 wire stepper motor, you will have 3 wires with resistance values and another 3 wires with resistance values. The two wires with 200 ohms resistance between them, are "live," so the other wire is "common." Once you have identified the "common" wire(s), you need to find the correct "phases." This is another way of saying the correct way to connect the motor so that it rotates clockwise of anticlockwise. You cannot simply connect the "live" wires to the project in any order. They must be connected so that the pulses will create a rotating magnetic field. There is no way to determine the correct way to connect a stepper motor other than viewing the output on a 4-input CRO. So, we have to do it by trial-and-error. Connect the stepper motor in any arrangement to the project but make sure the common goes to the positive rail, as we have already identified this wire. Turn on the project and see if the stepper motor rotates. If not, do not touch the first wire. Simply swap the last two wires. If this does not work, swap the 2nd and fourth wires. Then the second and third wires. The motor will not be damaged during this process as it does not take any more current when oscillating back and forth or when rotating. keep swapping the last three wires until the motor rotates.
10 di 27
13/09/2012 8.13
PWM
To make a stepper motor rotate at the fastest RPM, we deliver a pulse of very short duration, to each of the poles and the order of delivering these pulses must be correct. If we try to increase the RPM, we need to make the pulse shorter in duration and a point will come when the stepper motor HALTS or STOPS or FREEZES. We now know the maximum RPM. To decrease the RPM, we increase the length of each pulse and this produces less pulses per second. The RPM decreases. In all of this action, the stepper motor is taking almost the same current as the voltage is being supplied almost constantly, the only difference is the pulses are longer or shorter. But suppose you want to supply less current or supply the stepper motor with a higher voltage. This can be done by delivering a short pulse then turning off the supply for a short period of time between pulses. This will not alter the RPM under the following conditions: Suppose the minimum pulse-width is 5mS. Suppose the pulse-width is presently 25mS. If the pulse-width is reduced to 5mS and an off-period of 20mS, the stepper motor will retain the same RPM but consume less current. The torque will also be reduced and this will have be checked - to see if the motor stalls under load. This action is called "reducing-the-pulse-width" and is commonly called PULSE WIDTH MODULATION. This is called "driving the motor with PWM." You can also use PWM to drive a 12v stepper motor from 24v or 36v. By using the example above, the stepper motor is only getting a pulse of energy for 20% of the time, so that delivering a voltage such as 24v or 36v, will result in an average current that is less than driving it without PWM on 12v. These are the main reasons for using PWM. It is not used to control the RPM.
11 di 27
13/09/2012 8.13
used for very short periods of time, they will not get hot or even warm. If you want to use them on a higher voltage, such as 24v or 36v, you will need to drive them with very short pulses and provide an off-period in the waveform so that the overall current is not above about 300mA. This involves a pulse-width technique called PWM, mentioned above. This can be incorporated into the project by modifying the program.
12 di 27
13/09/2012 8.13
compile correctly to produce a .hex file. Use the .hex file above to burn your chip or the .asm file to modify the program. ;******************************* ;Stepper.asm ;drives a Stepper motor forward and reverse ;13-11-2010 ;*******************************
list p=12F629 radix dec include "p12f629.inc" errorlevel -302 ; Don't complain about BANK 1 registers __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc. ;_MCLRE_OFF - master clear must be off for gp3 as input pin
;****************************** ; variables - names and files ;***************************** temp1 temp2 equ 20h ; equ 21h ;
Sw_Flag equ 25h ;switch flag for "inching" loops equ 26h ;loops for full stepping count equ 27h ;loops of discharge time for 100n PotValue equ 28h ;value of pot look equ 29h ;look for pot value every 100 loops
;*************************** ;Equates ;*************************** status equ 0x03 rp1 equ 0x06 rp0 equ 0x05 GPIO equ 0x05
status
equ
03h
13 di 27
13/09/2012 8.13
option_reg
equ 81h
; bits on GPIO pin7 pin6 pin5 pin4 pin3 pin2 equ equ equ equ equ equ 0 1 2 3 4 5 ;GP0 ;GP1 ;GP2 ;GP3 ;GP4 ;GP5 100k speed output1 to output2 to Input from output3 to output4 to pot stepper stepper buttons stepper stepper
;********************** ;Beginning of program ;********************** org 0x00 nop nop nop nop nop SetUp bsf status, rp0 movlw b'11001000' movwf TRISIO bcf status, rp0 movlw 07h movwf CMCON clrf GPIO clrf Sw_Flag incf Sw_Flag,1 goto Main
;bank 0 ;turn off Comparator ports ;must be placed in bank 0 ;Clear GPIO of junk ;put a bit onto Sw_Flag
;**************** ;delays * ;**************** _uS movlw movwf decfsz 08Ch temp1 temp1,f
14 di 27
13/09/2012 8.13
goto retlw
$-1 00
;delay for pulsing servo anticlockwise acw movlw movwf decfsz goto retlw 60h temp1 temp1,f $-1 00
_1mS
nop decfsz goto retlw movlw movwf nop decfsz goto decfsz goto retlw
_5mS
_10mS
movlw movwf nop decfsz goto decfsz goto retlw movlw movwf nop decfsz goto decfsz
0Ah temp2 temp1,f $-2 temp2,f $-4 00 .15 temp2 temp1,f $-2 temp2,f
_15mS
15 di 27
13/09/2012 8.13
goto retlw
$-4 00
_18mS
movlw movwf nop decfsz goto decfsz goto retlw movlw movwf nop decfsz goto decfsz goto retlw
.18 temp2 temp1,f $-2 temp2,f $-4 00 .50 temp2 temp1,f $-2 temp2,f $-4 00
_50mS
_100mS
_200mS
16 di 27
13/09/2012 8.13
;delay to create value for pot for speed PotDel movlw movwf decfsz goto retlw 040h temp1 temp1,f $-1 00 ;40h produces 12 loops
;position of pot creates a value in PotValue Pot bsf bcf bcf bcf call bsf bsf bcf clrf call incf btfss goto retlw status,rp0 trisio,0 ;Make GP0 output status,rp0 gpio,0 ;make GP0 LOW _1mS ;create delay to discharge 100n status,rp0 trisio,0 ;Make GP0 input status,rp0 PotValue PotDel PotValue,f gpio,0 ;is input HIGH? $-3 00 ;returns with a value in PotValue
;****************** ;* Main * ;****************** Main clrf bcf call bsf nop btfss goto gpio gpio,5 _1mS gpio,5 gpio,3 $+2
17 di 27
13/09/2012 8.13
goto clrf bsf btfss goto goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto goto _1HSF_ _2HSF_ _3HSF_ _4HSF_ _5HSF_ _6HSF_ _7HSF_ _8HSF_ movlw goto movlw goto movlw goto movlw goto movlw goto movlw goto movlw goto movlw movwf call clrf call call clrf incf bsf
$+6 gpio
gpio,1 gpio,3 Reverse ;go to half step Reverse _FS ;go to Full Step - for forward or reverse Sw_Flag,0 _1HSF_ Sw_Flag,1 _2HSF_ Sw_Flag,2 _3HSF_ Sw_Flag,3 _4HSF_ Sw_Flag,4 _5HSF_ Sw_Flag,5 _6HSF_ Sw_Flag,6 _7HSF_ _8HSF_ b'00100000' _C b'00110000' _C b'00010000' _C b'00010100' _C b'00000100' _C b'00000110' _C b'00000010' _C b'00100010' gpio _200mS gpio _200mS _200mS Sw_Flag Sw_Flag,1 gpio,5 ;1 ;2 ;3 ;4 ;5 ;6 ;7 ;8
18 di 27
13/09/2012 8.13
_C
movwf call clrf call call bcf rlf bsf nop btfsc goto bcf goto
gpio _200mS gpio _200mS _200mS status,0 Sw_Flag,1 gpio,5 gpio,3 HS_Fwd gpio,5 Main
Reverse clrf bcf call bsf nop btfss goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto gpio gpio,4 _1mS gpio,4 gpio,3 Main Sw_Flag,0 _1HSR_ Sw_Flag,1 _2HSR_ Sw_Flag,2 _3HSR_ Sw_Flag,3 _4HSR_ Sw_Flag,4 _5HSR_ ;gpio,4 high for a short time
19 di 27
13/09/2012 8.13
btfsc goto btfsc goto goto _1HSR_ movlw movwf call clrf call call Movlw movwf bsf nop btfsc goto bcf goto movlw goto movlw goto movlw goto movlw goto movlw goto movlw goto movlw goto
Sw_Flag,5 _6HSR_ Sw_Flag,6 _7HSR_ _8HSR_ b'00100000' gpio _200mS gpio _200mS _200mS 80h Sw_Flag gpio,4 gpio,3 HS_Rev Main b'00110000' _D b'00010000' _D b'00010100' _D b'00000100' _D b'00000110' _D b'00000010' _D b'00100010' _D ;2 ;3 ;4 ;5 ;6 ;7 ;8 ;1
_D
20 di 27
13/09/2012 8.13
HS_Fwd clrf bcf call bsf nop btfss goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto goto _1HSF _2HSF _3HSF _4HSF _5HSF _6HSF movlw goto movlw goto movlw goto movlw goto movlw goto movlw gpio gpio,5 _1mS ;gpio,5 high for a short time gpio,5 gpio,3 Main Sw_Flag,0 _1HSF Sw_Flag,1 _2HSF Sw_Flag,2 _3HSF Sw_Flag,3 _4HSF Sw_Flag,4 _5HSF Sw_Flag,5 _6HSF Sw_Flag,6 _7HSF _8HSF b'00100000' _CC b'00110000' _CC b'00010000' _CC b'00010100' _CC b'00000100' _CC b'00000110' ;1 ;2 ;3 ;4 ;5 ;6
21 di 27
13/09/2012 8.13
_7HSF _8HSF
goto movlw goto movlw movwf call clrf clrf incf goto
_CC b'00000010' _CC b'00100010' gpio _5mS gpio Sw_Flag Sw_Flag,1 HS_Fwd
;7 ;8
_CC
;half step reverse HS_Rev clrf bcf call bsf nop btfss goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto btfsc goto goto gpio gpio,4 _1mS gpio,4 gpio,3 Main Sw_Flag,0 _1HSR Sw_Flag,1 _2HSR Sw_Flag,2 _3HSR Sw_Flag,3 _4HSR Sw_Flag,4 _5HSR Sw_Flag,5 _6HSR Sw_Flag,6 _7HSR _8HSR ;gpio,4 high for a short time
22 di 27
13/09/2012 8.13
_1HSR
movlw movwf call clrf Movlw movwf goto movlw goto movlw goto movlw goto movlw goto movlw goto movlw goto movlw
b'00100000' gpio _10mS gpio 80h Sw_Flag HS_Rev b'00110000' _G b'00010000' _G b'00010100' _G b'00000100' _G b'00000110' _G b'00000010' _G b'00100010' goto _G
;1
;2 ;3 ;4 ;5 ;6 ;7 ;8
_G
_FS
clrf bsf btfss goto goto bsf btfss goto goto clrf
gpio gpio,5 gpio,3 $+2 FS_Fwd gpio,4 gpio,3 $+2 FS_Rev gpio
23 di 27
13/09/2012 8.13
call goto
_1mS $-10
;Full Step Forward FS_Fwd call movlw movwf movlw movwf movf movwf call decfsz goto movlw movwf movf movwf call decfsz goto movlw movwf movf movwf call decfsz goto movlw movwf movf movwf call decfsz goto decfsz goto goto pot ;returns with value in PotValue .50 look ;look at pot every 50 loops b'00000010' ;full step forward gpio PotValue,w loops _1mS loops,1 $-2 b'00000100' gpio PotValue,w loops _1mS loops,1 $-2 b'00010000' gpio PotValue,w loops _1mS loops,1 $-2 b'00100000' gpio PotValue,w loops _1mS loops,1 $-2 look,1 FS_Fwd+3 ;don't look at pot FS_Fwd ;look at pot
;Full Step Reverse FS_Rev call pot ;returns with value in PotValue
24 di 27
13/09/2012 8.13
movlw movwf movlw movwf movf movwf call decfsz goto movlw movwf movf movwf call decfsz goto movlw movwf movf movwf call decfsz goto movlw movwf movf movwf call decfsz goto decfsz goto goto END
.50 look ;look at pot every 50 loops b'00100000' ;full step reverse gpio PotValue,w loops _1mS loops,1 $-2 b'00010000' gpio PotValue,w loops _1mS loops,1 $-2 b'00000100' gpio PotValue,w loops _1mS loops,1 $-2 b'00000010' gpio PotValue,w loops _1mS loops,1 $-2 look,1 FS_Rev+3 ;don't look at pot FS_Rev ;look at pot
GOING FURTHER You can add additional features to this project by writing your own program or modifying the program above.
25 di 27
13/09/2012 8.13
1 4 1 3 1 1
39R SM resistor> 100R SM resistor 220R SM resistor 2k2 SM resistor 47k SM resistor 100k pot
2 - 100n SM capacitors 1 - 100u electrolytic 4 1 4 1 SM yellow LEDs SM diode BD679 transistors 78L05 SM voltage regulator
1 - SPDT mini slide switch 3 - mini tactile buttons 1 - 8 pin IC socket 1 - 5 pin header 40cm fine enamelled wire 20cm fine tinned copper wire
26 di 27
13/09/2012 8.13
20cm - very fine solder 1 - PIC12F629 chip (with Step routine) 1 - 4-cell battery holder 1 - battery snap
1 - Prototype PC board
16/11/2010
27 di 27
13/09/2012 8.13