This circuit has proven useful when interfacing my computer to home made robotics. It is easy to build and use and it can control two DC motors of any current or voltage rating, depending on the rating of the relays. The circuit also provides two shaft encoders for positional feedback to the computer.
The motor control circuit is connected to an IBM PC parallel port, via U1, a 74LS192 four-bit latch. The first four data lines are used to control the motors, and the strobe signal from the computer stores the data in latch. There are two seperate motor driver circuits and each comprises two transistors and two relays. The relays need to be a SPDT or DPDT type, with a contact rating suited to the motor being controlled. Each motor is controlled by two bits, giving four possible control actions for each motor. The first two data lines control one motor and the next two (D2 and D3) control the other where: 00 = stop, 01 = forward, 10 = reverse, 11 = stop. The feedback part of the circuit uses the status lines of the parallel port. The shaft encoders attached to the motors consist of a metal or plastic disc with holes and a LED/LDR pair either side of the disc. The inverters (U2a and U2b) condition the signal developed across the LDR and provide pulses with sharp rise and fall times to the computer. The 50k variable resistors are adjusted so the inverter just switches on when the LED is shining on the LDR through a hole in the disc. The value should be around 17K, but this will depend on the LDR being used.
The encoder for motor 1 connects to the `out-of-paper' status line, and the encoder for motor 2 connects to the `busy' status line. The computer polls these two lines while the motors are turning.
The software (written in turbo C) has two functions: to control the motors and to read the status of the encoder. More sophisticated software can be built using these two functions.
#include#define TRUE 1 #define FALSE 0 #define ENC1 0x80 #define ENC2 0x20 int status(unsigned char encoder) { if((inportb(0x379) & encoder) > 0 ) return(TRUE); else return(FALSE); } void DCout(unsigned char movement) { outportb(37A,3); /* set load high */ outportb(378,movement); /* output motor command */ outportb(37A,2); /* strobe */ outportb(37A,3); /* strobe */ }
The status function is called with either ENC1 or ENC2 as a parameter which will return the value of the status of either encoder. The function needs to be called in a loop, and a counter included to count the number of holes passing each encoder. The control function DCout is called with a four-bit value (a data byte with the four higher order bits ignored). Each pair of bits represents the direction of each motor.
[Home] | [Publications] | [Past Projects] | [New Projects] |