Use the parallel port to control the motor in the notebook drive

Source: Internet
Author: User

For more information about how to use the desktop 3.5-inch stepper motor, I have also done some experiments, mainly using parallel ports to control the stepper motor, the Controller of the soft drive circuit is used. There are also some Portable Soft drives in the hand, which are much lighter than the platform, and the main control circuit board is also very small, the stepper motor is much smaller, because it is used as a notebook, so I guess its power consumption should be much less than that of the platform! In this way, we can not only connect the drive circuit to control, but also use the control circuit of the notebook drive as a motor control module (one spindle motor, one stepper motor, and several photoelectric switches) the structure of the application to the MCU system is basically the same as that of the platform, but the interface is different, the platform is 34pin, And the notebook is 26pin, so as long as you understand the definition of this 26pin, the control method is the same as that of the platform.

The 26pin interface of a certain model is defined as follows:
1-+ 5 V
2-Index
3-+ 5 V
4-ds0 (/ho/OP) multiple options depend on Jumper Block
5-+ 5 V
6-ds1 (/DC/OP)
7-NC
8-DC (/ry/ho/DS2/OP)
9-NC
10-motor on
11-op (/Hi/ho/ry)
12-direction select
13-op (/DC/ry)
14-step
15-0 V (Gnd)
16-write data
17-0 V
18-write Gate
19-0 V
20-track 00
21-0 V
22-write protect
23-0 V
24-read data
25-0 V
26-side one select

After many experiments, we finally got the conditions for motor rotation:
PIN4-DS0 ------------------ Gnd (when it is called pin4 grounding, some models of the soft drive LED light, some light, but does not affect the movement of the stepper motor)
PIN12-DIRECTION select --------------- Gnd (connected to Gnd head forward movement, the initial state is high level, but in the head is located at the bottom, the file in the middle of the photoelectric switch, the initial state is high level, at this time, the step pulse motor will not be moved backward)
PIN14-STEP: Stepping pulse, with a duty cycle of square wave can be
PIN10-MOTOR on: If the foot is connected to Gnd, the Spindle Motor rotation, but note that some models must be next to the spindle motor a touch key press to turn, some models do not have such restrictions.

The above connection methods are applicable to the tests of different types of software drives, including teac, misumi, and Sony.
The following uses parallel port control as an example to describe the specific connection and programming:
Let's take a look at the definition of the Parallel Port Pin:

Here we only use the data port And Gnd of the parallel port. The connection method is very simple, as follows:


Control Program (some changes were made based on the original Towanda Malone program ):
# Include
# Include
# Include

# Define data 0x03bc/* pay attention to the address of your parallel port and modify it according to the actual situation. At the same time, You Need */
/* Set the parallel port to the EPP + ECP mode */

# Define CW 1
# Define CCW 0/* defines the forward direction of the head. 1 indicates the backward direction, and 0 indicates the forward direction */

Int DATA = 0x00;

Void drive_dir (int dir);/* select the forward direction of the head */
Void drive_step (INT time);/* The stepping motor's inching step, which can be adjusted according to time */
/* Cycle (the speed is fast for the stepper motor )*/
Void turn_motor (INT Dir, int time, int duration);/* stepper motor in the given direction, square wave cycle (characterization */
/* Speed), motion under three parameters of the motion time */
Void pause_motor (INT duration);/* Stop the inching interval */
Void main_motor (INT duration);/* rotate the Spindle Motor for a period of time */
Void main (void)/* The main function reads commands from a cmd. dat file, which can be used */
/* Edit the file in a text editor. Select "all files" in "Save type ",*/
/* The file name is cmd. dat. Example of a CMD file :*/
/* T 0 25 5000 forward fast movement 5000 MS */
/* P 5000 pause 5000 MS */
/* T 1 50 5000 backward to slow speed motion 5000 MS */
/* M 5000 spindle motor rotating 5000 MS */
/* Exit Q */
/* Command Format: T motion direction (0 or 1) speed (the smaller the value, the faster the input time */
/* M inching time */
/* P pause time */
/* Q */

{
File * fr;
Int X, Dir, duration, speed, time;
Char line [50], OP;
Fr = fopen ("A:/CMD. dat", "RT ");
While (1)
{
Fgets (line, 50, fr );
Switch (toupper (line [0])
{
Case 'p ':
Sscanf (line, "% C % d", & OP, & duration );
Pause_motor (duration );
Break;

Case 'q ':
Fcloseall ();
Exit (0 );

Case 'T ':
Sscanf (line, "% C % d ",
& OP, & Dir, & speed, & duration );
Turn_motor (Dir, speed, duration );
Break;
Case 'M ':
Sscanf (line, "% C % d", & OP, & duration );
Main_motor (duration );
Break;

Default:
Printf ("Unknown command/N ");
Exit (0 );
}
}
}
Void main_motor (INT duration)
{DATA = Data &(~ 0x04 );
Outport (data, data );
Delay (duration );
Data = data | 0x04;
Outport (data, data );
}
Void turn_motor (INT Dir, int time, int duration)
{
Struct timeb t_curr, t_start;
Int t_diff;

Ftime (& t_start );
Drive_dir (DIR );
Do
{
Drive_step (time );
Ftime (& t_curr );
T_diff = (INT) (1000.0 * (t_curr.time-t_start.time)
+ (T_curr.millitm-t_start.millitm ));
}
While (t_diff }

Void pause_motor (INT duration)
{
Struct timeb t_curr, t_start;
Int t_diff;

Ftime (& t_start );
Outportb (data, 0x04);/* corresponding parallel port data: D0--0, D1--0, D2--1 */
Do
{
Ftime (& t_curr );
T_diff = (INT) (1000.0 * (t_curr.time-t_start.time)
+ (T_curr.millitm-t_start.millitm ));
}
While (t_diff <duration );
}

Void drive_dir (int dir)
{
If (DIR = CW)
{
Data = data | 0x06;
Outportb (data, data );
}
Else
{
Data = (Data &(~ 0x02) | 0x04;
Outportb (data, data );
}
}

Void drive_step (INT time)
{
Data = data | 0x05;
Outportb (data, data );
Delay (Time/2 );
Data = (Data ^ 0x01) | 0x04;/* the function of getting or from 0x04 is to keep D2 as 1 and disable rotation of the spindle motor */
Outportb (data, data );
Delay (Time/2 );
}

The above program can be compiled in the turboc2 environment. The experiment runs well, but sometimes it takes one or more steps, and the time is not very accurate, I think it has something to do with the PC environment, especially the latency. After all, the current PC clock speed is very high. In the past, we encountered a similar problem when using turboc programming, the same latency program is very different on P4 and P2 machines. I think it may be better if we port this experiment to MCU, for example, 51. At the same time, using the controller of the notebook soft drive can save a lot of I/O port resources of 51, compared with the 3.5-inch drive, it has more advantages in volume and power consumption. The old laptop has eliminated many such soft drives and can be bought at around 10 yuan, in the production of some small robots, its advantages in all aspects are no less than the drive chips and motors you have bought. However, there are also some disadvantages, that is, the stepper motors are all with worms, the spindle motor speed is slow (about 360 rpm) and has a large and fixed head. This requires our imagination and creativity. In addition, in terms of power supply, I used the USB port of the PC for power supply during the experiment. The driving capacity is about 200mA, and the power supply requirement of the notebook is 4.5 V ~ 5.5 V.

Some time ago I planned to build a simplest 2-joint mechanical arm. In line with the principle of saving, I wanted to use some motors and controllers on the soft drive to connect them to the computer with a print port, the software uses some motion algorithms and MATLAB for dynamic simulation to obtain the theoretical basis. After all, there is no execution error in the MATLAB simulation environment, but in reality, the execution of programs in the TC environment always has more or less errors, so that the step size of the motor cannot be kept constant. There is also the mechanical part. The uneven resistance distribution also leads to the generation of motion errors, the above are all randomly generated. After some preparation work, I thought carefully and found that there are so many problems that need to be solved. Of course, as long as I am willing to invest, the above problems are not a big problem, but it also loses the significance of DIY. I will write down some of my preparations and hope to share them with you. If you are a diyer who is loyal to exploration, I hope you can discuss them together! Recently I am studying the arm bios. Maybe I will transfer it to the mechanical arm later.

Contact information of the author:
Menger11
Shenyang 2006.06.21
Qq99899095
Mail: menger11@sohu.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.