Documente Academic
Documente Profesional
Documente Cultură
Stepper Motors
Uncovered (2)
Part 2 (final): a universal 4-channel unipolar stepper drive
Design by Timothy G. Constandinou
+5V +5V
100n
2
K1 V+
1 D1 D2 D3 D4 D5
C2 C1+ 16
1 R5
C8 +U B
IC2
1k
6 3
R1 100n C1 R3
2 7 10 100n
R6 R7 R8 R9 R10 IC3
330 T2OUT T2IN 100
220
220
220
220
220
7 14 11 +5V 7805 F1
R2 T1OUT T1IN R4
3 8 9 1 20
330 R2IN R2OUT 100
8 13 12 C6 MCLR/VPP 3A F K2
R1IN R1OUT X1 9 16
C1 OSC1/CLKIN
4 4 RC5/SDO
C3 C2+ 15 C9 C10 C11
9 33p RC4/SDI/SDA
MAX232 100n
15 7
5 5 C7 RA5/AN4/SS
100n C2 10 100n 100n 1000
6 40V
V- OSC2/CLKOUT RA4/T0CKI
20MHz
6 33p IC1
SUB D9 C5 17
RC6/TX/CK
18
RC7/RX/DT
100n
14 24
RC3/SCK/SCL RB3/PGM
13 23
RC2/CCP1 RB2
12 22
RC1/TIOSI/CCP2 RB1
11 21
RC0/T1OSO/T1CKI RB0/INT
2
PIC16F873 28
RA0/AN0 RB7/PGD
3 27
RA1/AN1 RB6/PGC
4 26
RA2/AN2/VREF RB5
5 25
RA3/AN3/VREF+ RB4
+U B +U B +U B +U B
8 19
D6 D10 D18 D14
* * * zie tekst * *
10k
10k
10k
10k
* voir texte
+U B +U B * siehe Text +U B +U B
D7 D11 D19 D15
* see text
*T2 *T6 T14
* *
T10
* * * *
10k
10k
10k
10k
+U B +U B +U B +U B
D8 D12 D20 D16
* * * *
10k
10k
10k
10k
+U B +U B +U B +U B
D9 D13 D21 D17
+U B +U B +U B +U B
R21
R22
R34
R33
R28
R27
* * * *
47
47
47
47
47
47
47
47
10k
10k
10k
10k
K3 K4 K6 K5
020127 - 11
R11
H1
T1
D6
020127-1
R12
T2
D7
K1
R1
R2
C2
C3
R13
T3
D8
R15
R16
IC2
K3
020127-1
1-721020
C4
R14
C5
C1
T4
D9
R4
R3
R17
D10
T5
C7
R18
D11
X1
T6
C8
IC1
C6
D12
R19
T7
R21
R22
K4
D13
R20
T8
R23
D14
T9
D3 D4 D1 D2 D5
R8
R7
R6
R9
R5
R24
T10
D15
R25
T11
D16
R10
R27
R28
K5
R26
T12
D17
C9 C10
IC3
R29
T13
D18
C11
R30
T14
D19
R31
T15
D20
R33
R34
K6
3A/F
F1
R32
T16
D21
K2
H2
H3
-
+
#include <16f873.h>
#include <ports.h>
#include <protocol.h>
#use delay (clock=20000000)
#use rs232(baud=38400, xmit=tx, rcv=rc)
// initialises the ports by defining whether the tri-state buffers should be input or output
void setup_ports(void) { set_tris_a(0x00);set_tris_b(0x00);set_tris_c(0xF0);set_uart_speed(38400); }
// Reads in 2 bytes from the UART and returns a 16-bit integer (range 0-65535)
long readlong(void) { return(256*getc() + getc()); }
// Main Program
void main(void) {
char incomm;
long steps;
setup_ports(); reset_ports();
while(0==0) {
output_low(led_a); output_low(led_b); output_low(led_c); output_low(led_d);
incomm=getc();
output_high(led_a); output_high(led_b); output_high(led_c); output_high(led_d);
switch(incomm) {
case RESET: reset_ports(); break;
case SETUP_ACC: min=readlong(); max=readlong(); break;
case MOVE_A_FW: steps=readlong(); astep=move(0, steps, 1, astep); break;
case MOVE_A_RV: steps=readlong(); astep=move(1, steps, 1, astep); break;
case MOVE_B_FW: steps=readlong(); bstep=move(0, steps, 2, bstep); break;
case MOVE_B_RV: steps=readlong(); bstep=move(1, steps, 2, bstep); break;
case MOVE_C_FW: steps=readlong(); cstep=move(0, steps, 3, cstep); break;
case MOVE_C_RV: steps=readlong(); cstep=move(1, steps, 3, cstep); break;
case MOVE_D_FW: steps=readlong(); dstep=move(0, steps, 4, dstep); break;
case MOVE_D_RV: steps=readlong(); dstep=move(1, steps, 4, dstep); break; } putc(ACKNOWLEDGE); } }
#define tx PIN_C6
#define rc PIN_C7
#define a_1 PIN_C3
#define a_2 PIN_C2
#define a_3 PIN_C1
#define a_4 PIN_C0
#define b_1 PIN_A0
#define b_2 PIN_A1
#define b_3 PIN_A2
#define b_4 PIN_A3
#define c_1 PIN_B3
#define c_2 PIN_B2
#define c_3 PIN_B1
#define c_4 PIN_B0
#define d_1 PIN_B7
#define d_2 PIN_B6
#define d_3 PIN_B5
#define d_4 PIN_B4
#define led_a PIN_A5
#define led_b PIN_A4
#define led_c PIN_C5
#define led_d PIN_C4
#define RESET 1
#define ACKNOWLEDGE 2
#define SETUP_ACC 10
#define MOVE_A_FW 20
#define MOVE_A_RV 21
#define MOVE_B_FW 22
#define MOVE_B_RV 23
#define MOVE_C_FW 24
#define MOVE_C_RV 25
#define MOVE_D_FW 26
#define MOVE_D_RV 27
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, QCCom32, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
QCPort: T_QCCom32;
Commport: TComboBox;
xclgroup: TRadioGroup;
setup_acc, move_a_rv, move_a_fw, move_b_rv, move_b_fw, move_c_rv, move_c_fw, move_d_rv, move_d_fw, reset: TRa-
dioButton;
parameter1, parameter2: TEdit;
commportlabel, parameterlabel: TLabel;
Executebutton: TBitBtn;
autoreset: TCheckBox;
procedure CommportChange(Sender: TObject);
procedure ExecutebuttonClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure setup_accClick(Sender: TObject);
procedure move_a_fwClick(Sender: TObject);
procedure move_a_rvClick(Sender: TObject);
procedure move_b_fwClick(Sender: TObject);
procedure move_b_rvClick(Sender: TObject);
procedure move_c_fwClick(Sender: TObject);
procedure move_c_rvClick(Sender: TObject);
procedure resetClick(Sender: TObject);
procedure move_d_fwClick(Sender: TObject);
procedure move_d_rvClick(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
if (parameter1.enabled) then
begin setlength(command, 2);
command[1] := char(strtoint(parameter1.text) div 256);
command[2] := char(strtoint(parameter1.text) mod 256);
QCPort.Write(command); end;
while(QCPort.Read = ) do;
DIL sockets, ceramic capacitors, etc., ICs may be installed in their DIL The controller software
mainly for convenience. Take special sockets. You can program your own The PIC microcontrollers function is to
care to observe the correct polarity PIC for the project using the source receive commands from the PC via the RS232
of all semiconductors and electrolytic code available under number port and execute them. It is responsible for
capacitors before soldering. Also, the 020127-11 on disk or from the Free generating the stepping sequence which will
ballast resistors should be mounted Downloads section of our website at control the power delivered to the motor. This
slightly off the board surface as they www.elektor-electronics.co.uk. For also produces the acceleration and decelera-
will become hot during operation. It the more ambitious readers wanting tion cycles for optimal stepping response of a
is advisable to use ceramic standoffs to customize the PIC firmware or given motor. By having this low level inter-
to space these resistors above the add functionality, a full overview face the pulse timings can be guaranteed to
board. including some guidelines is pro- be precise.
If all four channels are not vided in the following section. It is So why bother having a microcontroller at
required, you may populate, for advisable to test the project with the all? Why not control the stepper motor drive
example, only two of the four chan- original firmware before attempting directly from the computer? Although such
nels of the stepper motor drivers. to modify it. real-time control was possible in the past
When the soldering is finished, with DOS-based programs, unfortunately this
the PIC microcontroller and MAX232 is no longer the case. This is because of the
joy try reprogramming or replacing again and retest. The motor should
the microcontroller IC. spin smoothly, accelerating and
Once the circuit starts up cor- decelerating when starting and
rectly, use a 1:1 (non-crossed) D-9 stopping. If the motor seems to skip
female to D-9 male cable to connect or the movement is jerky, check that
the controller PCB to the computer the phases are connected in the cor- Useful links
RS232 port. Run the test software on rect order and that the acceleration Microchip PIC 16F87X microcontroller
the PC and select the correct COM rate is not too fast for that stepper datasheet:
port setting. Then try testing any of motor. Remember, lower delay rates www.microchip.com/download/lit/
the commands. On sending a com- mean faster rotation. If you set up pline/picmicro/families/16f87x/
mand, four LEDs should go out and the speed with equal delays, for 30292c.pdf
one LED should light indicating example, 800-800, there will be no Direct download link to the QCCOM32
which channel is in use. Once the acceleration or deceleration. Most VCL for RS232 I/O in Borland Delphi:
command has been executed the stepper motors should work with http://geocities.com/scottpinkham/
four LEDs will light up. If this works 500-1000 step delays. delphi/qccom32.zip
as expected, turn off the controller
PCB and connect a motor to one Once all required channels have Low-cost PIC development tools compatible
with Microchip MPLAB environment:
channel. It is important to ensure the been tested and are found to be
www.taylec.co.uk
phases and common taps are all cor- working, you can customize the
rectly connected. Next, power up command (PC) software or control A PIC C compiler compatible with
(PIC) software to include your own Microchip MPLAB environment:
commands and improvements. One www.ccsinfo.com
powerful variation could be to multi- VCLs for hardware port access and control:
Free Downloads plex the motors, enabling more than www.programmersheaven.com,
one axis to spin at any time. Appli- www.torry.net, www.codeguru.com
PIC and PC software (source code cations of the driver board described
files). File number: 020127-11.zip
here may be found in robotics, for
PCB layout in PDF format. File
number: 020127-1.zip
accurate positioning of mechanical Useful literature
parts in telescopes, robots, cameras,
Serial Port Complete by Jan Axelson, ISBN:
www.elektor-
etc., or for precision movement and
0965081923
electronics.co.uk/dl/dl.htm, select placement as required in CNC PICProg 2003,
month of publication. machine tools. Elektor Electronics September 2003.
(020127-2)