• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
156 Part 4
 www.newnespress.comListing 4.7 Outline of Rev Counter Program
MOTREVSSpecify MCU 16F917Include LCD function fileInitialize display digits to zeroSetup LCDSetup timer as external pulse counterMain loopDisplay 3 digits on LCDWait for input switch onReset counter and start motorWait for input switch offStop motorConvert timer count to 3 digit BCD
The timer is set up for external input using
setup_timer_1(T1_EXTERNAL)
, and theresulting count is read using
get_timer1()
. The binary number obtained from the timeris divided by 2 and converted to BCD by a process of successive subtraction, which issimple if not elegant. The calculated digits are then displayed as in previous examples,using the function
lcd_symbol()
to output the display digits and the include fileLCD.INC for the display encoding.
4.4 PICDEM Stepper Motor Control
Stepper motor operation
Stepper motor test program
Speed and direction controlThe main advantage of the stepper motor is that it provides position control without thefeedback required by a DC motor. It has stator windings distributed around a cylindricalrotor, which has permanent or induced magnetic poles. The windings operate in groups tomove the rotor by a fraction of a revolution at a time(Figure 4.8).
 
C Mechatronics Applications
157
 www.newnespress.com
N N NSS
Figure 4.9: Bipolar Permanent Magnet Stepper Motor with Two Winding sets
Construction
The small stepper motor on the mechatronics board is an inexpensive permanent magnet(PM) type, giving 7.5 degrees per step, 48 steps per revolution. It can also be moved inhalf steps by suitable operation of the windings or even smaller steps (microstepping) bysuitable modulation of the winding current. The motor has two bipolar windings, whichmeans the current is reversed to change the polarity of the stator pole. The coils energizetwo rings of poles, creating alternating north and south poles, which interact with thepermanent rotor poles(Figure 4.9).Representative windings are shownFigure 4.10;in the actual motor, coils are distributed around the whole circumference, multiplying the torque produced. Their terminals are
Figure 4.10: Stepper Motor Test System Connections
PIC16F917
SW2RD7 P1RD6 P2CCP1BrownOrangeRedYellowWindingRotorPWM1Direction
Motorcontrollogiclinked forfull bridgedriveoperation
RD5 P3RD4 P4CCP2 PWM3SW3FasterSW3Slower
Drive 1Drive 2Drive 3Drive 4
 
158 Part 4
 www.newnespress.com
connected to the four driver outputs on the board, which are normally connected for full-bridge operation. This allows the current to be reversed in the stator windings, reversingthe polarity of the stator poles. The stator coils are brought out to four color-coded wires,which are connected to the driver terminals.In more expensive motors, a smaller step (typically 1.8º) can be obtained with four sets of windings. These motors usually have six wires, with a common connection for each pairof windings.
Stepper Motor Test 
The stepper motor is connected to the driver outputs, in clockwise order. The six driverinput links must be closed to enable full-bridge operation, since the bipolar motorrequires winding current in both directions. P1, P2, P3, and P4 inputs are connected toRD4, RD5, RD6, and RD7, respectively. When run, the program generates the requiredswitching sequence on the coils to energize them in the right order. SW2/RA1 changesthe direction, and SW3/RA3 and SW4/RA4 allow the step speed to be varied.Source code STEPTEST.C is shown in Listing 4.8.Only the control inputs P1, P2, P3, and P4 need to be connected to outputs RD7–RD4 at this stage. Note that the steppermotor terminal connections are not in numerical color order. As can be seen, no specialprogram setup is needed. The program simply switches on the drivers in the order 1,4,2,3by outputting a suitable hex code to Port D. The delay is set so that the steps can becounted visually. It is helpful to attach an indicator flag to the motor shaft, so that thestepping can be seen more easily. The number of full steps per rev can then beconfirmed (48).Program STEPSPEED,Listings 4.9 and 4.10,is a development of the basic program to test the motor response to a range of step rates. The input tactile switches change thespeed by modifying the delay time parameter, which is set to 16 ms by default. This givesspeed of 16 ms/step
16
48
0.768 sec/rev
0.768
60
46 rpm
Direction Control 
The stepper motor program can now be further developed to include direction control, asshown in STEPDIR.C(Listing 4.11).The program has been restructured to incorporate
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...