I'd like to add that the principle of photoelectric coupler is similar to that of photoelectric pair tube, except that light emitting tube and photosensitive tube are embedded in it, and it is worth noting that the specifications of photoelectric coupler only have how much voltage, but I haven't heard how much current. It is more direct to use photoelectric coupler than triode. In fact, it is not recommended to use optocouplers as drivers. My circuit drives 12v motor with l298n.
By the way, there is a motor followed by a capacitor in the circuit diagram, mainly for motor speed regulation, but my motor has poor sensitivity, and adding a capacitor plays a buffering role, which is not available in the typical circuit mode of l298 chip.
I recently made the following report on the conclusion of following the car. . .
In fact, whether to use photoelectric isolation depends on the current of the motor you drive. If the current is less than 1 A, photoelectric coupling is not needed. . . The optocoupler drive seems to be ineffective and unstable.
It's best to make the code wheel of speed measurement as dense as possible, otherwise there will be shaking in actual operation and many other reasons will make the result error very large, because the general photoelectric switch will have a condenser, even a small shaking can be felt.
Tracking trolley
Producer: Li Jing
By building a car, you can deepen your proficiency in single chip microcomputer control and learn the process of project development.
The car walks along a given route and has the functions of timing, displaying running time, timing and roughly measuring walking distance.
First,? Design tasks:
1, design requirements
(1) The automatic tracking car starts to be in the setting mode, and the running time is set by pressing the key. After the set time is completed, press the start button to start the car and display the current running time.
(2) When the car travels along the designated route, it automatically distinguishes between the straight track and the detour track, and turns at the designated detour to realize the flexible forward and turning functions.
(3) The car will stop automatically after the preset time, and the digital tube will display the walking time and distance after 3 seconds.
(4) Right-click to stop and end ahead of schedule, showing the walking time and distance.
2. The principle of car tracking
Tracking here refers to the car walking along the black line on the white floor, and the usual method is infrared detection.
Infrared detection method, that is, using the characteristics that infrared rays have different reflective properties on the surfaces of objects with different colors, continuously emits infrared rays to the ground during the driving process of the automobile, and diffuse reflection occurs when the infrared rays meet the white floor, and the reflected light is received by the receiving tube installed on the automobile; If you encounter a black line, the infrared light will be absorbed, and the receiving tube on the car will not receive the infrared light. The single chip microcomputer determines the position of the black line and the running route of the car according to whether it receives the reflected infrared light or not. The detection distance of infrared detector is limited, generally the maximum should not exceed 3cm.
Second,? Scheme demonstration:
According to the design requirements, the system is mainly composed of controller module, power module, tracking sensor module, DC motor and its driving module, voltage comparison module and so on.
In order to better realize the functions of each module, we designed several schemes and demonstrated them respectively.
3. 1 body design
Scheme 1: Buy a toy electric car. The purchased toy electric vehicle has fully assembled frame wheels, motors and their driving circuits. Generally speaking, however, toy electric vehicles have the following disadvantages: firstly, due to its compact assembly, the installation of various required sensors is very inconvenient. Secondly, this kind of electric car is usually driven by the front wheel steering and the rear wheel, which can't adapt to the grid map of this topic and can't keep the coordinates rotating 90 degrees or even 180 degrees conveniently and quickly. Thirdly, the motors of toy electric vehicles are mostly toy DC motors, with small torque, fast no-load speed, poor load performance and difficult speed regulation. And this kind of electric car is generally more expensive. So we gave up the plan.
Option 2: Make your own electric car. After repeated consideration and demonstration, we have worked out a scheme that the left and right wheels are driven separately and the front universal wheel turns. That is, the left and right wheels are driven by two DC motors with basically the same speed and torque, and a universal wheel is installed at the head of the car body. Therefore, it can easily achieve a 90-degree turn with the same coordinates as the car.
During installation, we ensure that the two driving motors are coaxial. When the car moves forward, the left and right driving wheels and the front universal wheel form a three-point structure. This structure makes the car run smoothly, and can avoid the situation that the driving force of the left and right driving wheels is not enough because the rear wheel is too low. In order to prevent the center of gravity of the car from shifting, the front universal wheel plays a supporting role.
For the choice of frame material, we choose aluminum alloy by comparison. The frame made of aluminum alloy is stronger than the plastic frame, lighter and more beautiful than the iron car.
3.2 Controller module
Scheme 1: stc 89c52 single chip microcomputer of STC Hongjing Company is used as the main controller. Stc89c5 is an 8-bit microcontroller with low power consumption, high reliability, ultra-low price and high performance. The chip contains 32k space and can be erased 100000 times repeatedly. With 32 IO ports, stc series single chip microcomputer can be programmed and debugged online, which is convenient for downloading programs and debugging the whole machine.
From the point of view of convenience, we chose this scheme.
3.3 Power supply module
Scheme 1: 12V battery supplies power to DC motor, and 12V voltage is reduced and stabilized to supply power to single chip microcomputer system and other chips. The battery has strong current driving ability and stable voltage output performance. Although the size of the battery is too large, it is very inconvenient to use in small electric vehicles, but because our body design leaves enough space, and the price of the battery is relatively low. So we chose this plan.
To sum up, we chose this scheme.
3.4 voltage stabilizing module
Scheme 1: decompress directly with 7805 and use large radiator. Although the structure and principle are simple, the current is too large, which leads to the instability of the circuit and easy to burn out the voltage stabilizing block. We abandoned the plan.
Scheme 2: Use two 7805s to directly stabilize the voltage to 5V. Theoretically, because the pressure drop is too large, it is easy to burn out the voltage stabilizing block, so two 7805s are used in parallel. However, there is a gift problem in two voltage stabilizing blocks, and then the problem is solved by modifying the circuit. Finally, we chose this scheme.
3.5 Tracking sensor module
Scheme 1: The photosensitive detector consists of a photosensitive resistor. The resistance of photoresistor will change with the change of ambient light. When the light shines on the white line, it shines strongly, and when the light shines on the black line, it shines weakly. So when the photosensitive resistance is above the white line and the black line, the resistance will change obviously. By comparing the change values of resistance, high and low levels can be output.
However, this scheme is greatly affected by illumination and cannot work stably. So we consider other more stable schemes.
Option 2: Use RPR220 photocell. RPR220 is an integrated reflective photodetector. Its emitter is gallium arsenide infrared light-emitting diode, and its receiver is high-sensitivity silicon planar phototransistor.
RPR220 is packaged in DIP4 and has the following characteristics:
Plastic lenses can improve sensitivity.
The built-in visible light filter can reduce the influence of scattered light.
Small size and compact structure.
When the light emitted by LED is reflected, it passes through lm339 voltage comparison chip and is compared with mosfet to output high and low levels. The sensitivity of the sensor unit can be adjusted by adjusting the mosfet. The photocell conditioning circuit is simple and its working performance is stable.
So we chose option two.
3.6 Motor module
The system is an intelligent electric vehicle. For electric vehicles, it is very important to choose the driving motor for their driving wheels. Because this experiment is to achieve accurate location and accurate measurement of the path, we consider two schemes comprehensively.
Scheme 1: DC reduction motor is adopted. The DC reduction motor has the advantages of large torque, small volume, light weight, simple assembly and convenient use. Because the original power is provided by the internal high-speed motor, it can drive the speed-changing (deceleration) gear set and generate greater torque.
Because we use software to speed the motor, the actual value is smaller than this.
Note: Theoretical values are used for actual calculation.
Can better meet the requirements of the system, so we chose this scheme.
3.7 Motor drive module
Scheme 1: The motor driving chip adopts special chip L298N. L298N is a full-bridge driver chip with high voltage and current and high corresponding frequency. One L298N can control two DC motors respectively, and it also has a control enable terminal. Using this chip as motor driver has the advantages of convenient operation, good stability and excellent performance.
Scheme 2: For DC motor, the driving circuit consists of discrete components. The motor drive circuit composed of discrete components is simple in structure and low in price, and is widely used in practical applications. But the performance of this circuit is not stable enough.
So we chose the scheme 1.
Third,? Analysis and calculation:
1 Design of sensor module
So we consider the scheme of using comparator.
The adjustable resistor RV 1 in the figure can adjust the mosfet of the comparator, and the voltage drop of the battery supplying the circuit is verified by experiments. Therefore, we choose this circuit as the sensor detection and conditioning circuit.
2. Follow the installation of photocell
Considering the design requirements, this design only needs four pairs of photoelectric sensors to complete the design requirements. These four pairs of photoelectric sensors are arranged in a straight line, and the middle two pairs of sensors are used to correct the tracking route of the car and ensure the straightness of the car. Sensors on both sides are used to detect the car crossing the line, which can realize the car turning.
4. Design of motor drive circuit.
We use the motor driver chip L298N as the motor driver, and the design of the drive circuit is shown in Figure 7:
Pin 5, pin 7, pin 10 and pin 12 of L298N are connected with a single chip microcomputer. By programming the single chip microcomputer, the PWM speed regulation and forward and reverse rotation functions of two DC motors can be realized. The diode here is used to release the self-induced electric energy of the motor coil.
Capacitor c3 plays a buffering role. After the test, when the speed is adjusted, the lower motor receives high pulse current. Because the sensitivity of DC motor is not very good, we also consider using long-period pulses, but because the scanning of the digital tube will be slow, the digital tube will vibrate. Considering comprehensively, we choose the capacitor to play a buffering role.
4, measuring distance design
We use photocell to sense the black and white stripes of the wheel to calculate the rotation angle of the wheel and indirectly measure the walking distance.
In actual operation, there will be wheel slip, the surface of black and white paper tape is not smooth and uneven, the axle is not firm, and it shakes inside and outside. Because rpr220 has a capacitor, even a small change will react. The signal from the actual test sensor is much larger than the theory. When the battery power is too low, this phenomenon will be more inaccurate and irregular (sometimes large, sometimes small). Even in the case of sufficient power, there is a big error. If it exceeds a certain distance, the result is meaningless, so we limit the maximum estimated distance to about 6 meters, so this design is a rough measurement distance.
Fourth,? General circuit diagram and component list
After repeated argumentation, we finally determined the following scheme:
(1) The car body is made of aluminum alloy frame by hand.
(2) stc89c52 single chip microcomputer is used as the main controller.
(3) The 12V battery supplies power to the DC motor, and the voltage of12v is reduced and stabilized by two 7805s (with large heat sinks) in parallel, which supplies power to the single chip microcomputer system and other chips.
(4) Tracking the pipe with RPR220 photoelectric device.
(5) L298N is used as the driving chip of DC motor.
Verb (short for verb)? software implementation
3. 1 main program flow chart
The main program flow chart of the software we designed is as shown in the figure:
Sixth,? Test:
Seven,? innovate
In this work, the method of connecting lm339 voltage comparator to control the resistance of mosfet is improved, and a unified varistor is used instead of connecting four varistors, which facilitates the adjustment of sensitivity. The photoelectric sensor circuit has also changed. The emitter and collector are directly connected to 5V power supply, which can make the current larger. Experiments show that when the triode is turned on, the current is not enough to burn it out.
DC is connected in parallel with the capacitor, and the capacitor c3 plays a buffering role. After the test, when the speed is adjusted, the lower motor receives high pulse current. Because the sensitivity of DC motor is not very good, we also consider using long-period pulse, but because the scanning of digital tube will be slow, the digital tube will vibrate. At the same time, it is considered to refresh the digital tube with clock interrupt scanning, but that will cause frequent interruption (about 50ms) and it will take a long time (about 24ms) to refresh the digital tube. Considering comprehensively, we choose the capacitor to play a buffering role.
Eight,? Feelings and experiences
P0? If you want to use it as an io port, you must add a pull-up resistor, that is, use a pull-up resistor, and the driving ability is not very good. This work uses * * * cathode digital tube, and the design of driving circuit is complicated, and the numbers are not bright enough. It is better to use * * * anode digital tube and triode drive, which may be better.
Because of the high scanning frequency of the single chip microcomputer to the digital tube, it is required that the period of the main program should not be too long when designing the program, which is very harsh for our car to perform functions such as tracking, speed regulation, timing, timing, ranging and turning. After comprehensive consideration, I decided that the main functions are only the function of refreshing the digital tube and detecting the black line, and the other functions should be handled by interrupts, and the interrupt time needed should not be too long. So far, these have made my program as long as 350 lines.
At first, we designed to measure the distance accurately, but the error was inevitable. Due to the limitation of hardware and respect for facts, we lowered the standard. You can improve and expand here in the future.
In the whole testing stage, we fully consider the continuity and compatibility of program functions. Due to the speed limit of 89c52 single chip microcomputer and the need of real-time refresh frequency of digital tube, we can't design a car with too high speed. After repeated tests and comprehensive consideration, we adopt the current scheme.
Nine,? Concluding remarks
On the premise of meeting the design requirements, our tracking car fully considers the appearance, cost and other issues, and makes a good balance between performance and price. Because the design requirements are not complicated, we have not added redundant functions to the circuit.
Due to the limited level of the author, some viewpoints are wrong. I hope to correct and advise, and thank you here.
Special thanks:
With the guidance of teachers and laboratory teachers, the advice and guidance of predecessors such as Zhang and Huang, and Wu Kuang and the whole team members, without you, we would not be today.
20 10 5? Month?
Gine Lee
Program fragment
/*******************************************
Digital tube refresh function
********************************************/
Invalid? Display (uchar? qw,uchar? bw,uchar? sw,uchar? Gw)// Display function
{
P2 = 0x E0;
p 1 = tabledu[qw];
Delay (6);
P2 = 0xd 0;
p 1 = tabledu[bw];
Delay (6);
P2 = 0xb 0;
p 1 = tabledu[SW];
Delay (6);
P2 = 0x 70;
p 1 = tabledu[GW];
Delay (6);
P2 = 0x0f; //
}
/*******************************************
Task initialization function
********************************************/
Invalid? Init0 () Task 1 initialization function
{
EA = 1;
EX0 = 1;
ex 1 = 1;
it 1 = IT0 = 1;
P0 = 0x00
flag = 1;
Ji Shu = 0; //
}
Invalid? Init()// Task 2 Initialization Function
{
EA = 1;
TH0 =(65536-50000)/256; //Initialize the positive 1 counter.
TL0 =(65536-50000)% 256;
ET0 = 1;
TR0 = 1;
th 1 =(65536-50000)/256; //Initialize the positive 1 counter.
TL 1 =(65536-50000)% 256;
et 1 = 1;
tr 1 = 1;
TMOD = 0x 1 1;
dsh =(qw * 10+bw)* 60; //
Ji Shu =1; //
}
Invalid? Su Jie ()
{
if(flag2==0)
{
flag 1 = 1;
flag 2 = 1;
CNT 1 = 0;
}
ET0 = 0;
P0 = 0;
Display (width, width, width, width);
}