Electronic competition summary (2): Common sensor circuit module design

Electronic competition summary (2): Common sensor circuit module design

This chapter mainly records in detail the electronic chip models, design principles and ideas of various commonly used sensors, so that you can review them at any time. This part of the content comes from the book "National College Student Electronic Design Competition Tutorial - Design Method Based on TI Devices" written by Huang Genchun and other scholars. Interested friends can purchase it and read it.

3.1 Sensor

When using a microcontroller as a measurement and control system, the system must always have an input channel for the measured signal. Picking up the state of the object under test is generally inseparable from sensors or sensitive devices. This is because the state parameter of the object under test is often a non-electrical physical quantity, and the microcontroller system is only a system that can identify and process electrical signals. Therefore, Sensors are needed to convert non-electrical physical quantities into electrical signals to achieve the measurement and control function.
Sensors, commonly known as "electrical five senses", are devices or devices that can sense (or respond to) specified measurements and convert them into usable signal output according to certain rules. Their functions are similar to human sensory organs. The sensor is at the input end of the test device and is the "interface" for information exchange between systems. It is usually composed of a sensitive element that directly corresponds to the measured element, a conversion element that generates a usable signal output, and a corresponding electronic circuit.

3.1.1 Sensor classification

There are many types of sensors, and there is currently no unified classification method. The following classification methods are commonly used.
1. Classification by input quantity
: If the input quantity is non-electricity such as temperature, pressure, speed, acceleration, humidity, etc., the corresponding sensor is called a temperature sensor, pressure sensor, speed sensor, acceleration sensor, humidity sensor, etc. This classification method provides readers with convenience and makes it easy to select the required sensor according to the measurement object.
2. Classification by measurement principle
The measurement principle of existing sensors is mainly based on electromagnetic principles and solid state physics theory. For example, according to the principle of variable resistance, there are potentiometer type and strain gauge sensors; according to the principle of variable reluctance, there are inductance type, differential transformer type, and eddy current sensors; according to the theory of semiconductors, there are semiconductor sensors. Force sensitive, thermal sensitive, light sensitive, gas sensitive and other solid state sensors.
3. Classification according to structural type and physical property type
. The so-called structural sensor mainly converts external measured parameters into corresponding changes in physical quantities such as resistance, inductance, and capacitance through changes in the geometric shape or size of the mechanical structure, thereby detecting the measured parameters. To detect signals, this kind of sensor is currently the most commonly used. Physical property sensors utilize changes in the physical properties of certain materials to achieve measurement. They are solid-state devices that use semiconductors, dielectrics, ferroelectrics, etc. as sensitive materials.
In recent years, as semiconductor technology has entered the stage of ultra-large-scale integration, research on various manufacturing processes and material properties has reached a very high level. From the perspective of development prospects, sensors have the following characteristics: solid-state, integrated and multi-functional, image-based, and intelligent.

3.1.2 Hall sensor

Hall sensors use the Hall effect in the magnetoelectric effect of semiconductors to convert the measured physical quantity into Hall potential. The Hall effect means: when a carrier fluid is placed stationary in a magnetic field, if the direction of the current in the carrier fluid is different from the direction of the magnetic field, the carrier fluid will be parallel to the plane composed of the direction of the current and the direction of the magnetic field. An electric potential will be generated, which is called the Hall potential. The Hall potential is where B is the magnetic induction intensity of the external magnetic field, I is the current through the substrate, n is the carrier concentration in the substrate material, e is the electron charge, and d is the thickness of the substrate.
Integrated Hall sensors use silicon integrated circuit technology to integrate Hall elements and measurement circuits. There are linear Hall sensors and switching Hall sensors. The basic application circuit of the integrated Hall sensor is shown in Figure 3-1. The load can be a general resistor, the input resistance of the amplifier or the internal resistance of the indicator, and the resistance value depends on the specific situation.
The application of switching Hall sensors to detect rotational speed is the most commonly used method in measurement control systems. Taking the speed measurement of a car as an example, in order to improve the measurement accuracy, three magnets are evenly installed on the wheel. The circuit is shown in Figure 3-2. Whenever the magnetic piece passes through the Hall piece, the sensor output terminal outputs a pulse, and the number of pulses N is counted by the counter, and the stroke of the car is calculated based on this. Assuming that the wheel circumference is C, the car's stroke is S=NC/3. Combined with the car's travel time T, the average speed of the car can be obtained as v=S/T.
Insert image description here

3.1.3 Temperature sensor

The number of temperature sensors occupies the first place among various sensors. Among them, those that convert temperature into changes in resistance are called thermal resistors and thermistor sensors, and those that convert temperature into changes in electrical potential are called thermocouple sensors.
Thermocouple sensors are based on the thermoelectric effect. The thermoelectric effect means that when two conductors of different materials form a closed loop, if the temperatures of the two nodes are different, a certain current (potential) will be generated. The magnitude of this potential is related to material properties and junction temperature.
Temperature sensors made using the temperature coefficients of thermal resistors and thermistors are called thermal resistance temperature sensors. The resistance of most metal conductors has the characteristic of changing with temperature, and its characteristic equation satisfies:

Insert image description here

In the formula, R₁ and R₀ are the resistance of the thermal resistor at t℃ and 0℃ respectively, and α is the temperature coefficient of the thermal resistor (1/℃). For most metal conductors, the α value is not a constant, but changes with temperature. However, it can be approximately regarded as a constant within a certain temperature range. Different metal conductors have different temperature ranges in which α maintains a constant.
The most commonly used measurement circuit for thermal resistance sensors is a bridge circuit, and automatic bridge circuits are used for high accuracy requirements. In order to eliminate measurement errors caused by changes in the resistance of the connecting wires with the ambient temperature, a three-wire or four-wire connection method is often used. This will not be described in detail.
Commonly used in electronic designs are integrated temperature sensors. This sensor is a solid-state sensor developed using the relationship between the volt-ampere characteristics of the PN junction and temperature. Integrated temperature sensors are divided into analog integrated temperature sensors and digital integrated temperature sensors. Common analog integrated temperature sensors (such as LM35) have high temperature measurement accuracy, good linearity, and fast response speed. At the same time, they can directly output voltage or current values, which facilitates digital processing and are widely used. The digital temperature sensor can directly convert the temperature value into a digital signal with high conversion accuracy and wide measurement range. It can communicate directly with the microcontroller without peripherals and is easy to apply.
LM35 is a voltage output temperature sensor. The output voltage range is ±5V and the sensitivity is 10.0mV/℃. That is, the output voltage is zero when the temperature is 0℃. The output voltage increases (decreases) by 10mV every time the voltage rises (drops) by 1℃. . The temperature measurement accuracy at normal temperature is ±0.5°C, and the impact of self-heating on the measurement accuracy is only within 0.1°C.
When using a single power supply above +4V, the temperature measurement range is 2~150℃; when using dual power supplies, if the chip is packaged in a metal shell, the temperature measurement range is -55~150℃; if the chip is in a TO-92 package, the temperature measurement range The temperature range is -40~110℃. The two package forms and pin diagrams of LM35 are shown in Figure 3-3.
As for digital temperature sensors, the DS18B20 is introduced here. The chip adopts the 1-Wire bus reading method and internal sampling at the same time, converting the temperature into a digital signal, which can be read directly through the control without the need for additional ADC sampling. The temperature measurement range is -55 +125°C, and can be programmed as 9th place12-bit A/D conversion accuracy, temperature measurement resolution up to 0.0625°C, the measured temperature is serially output in a sign-extended 16-bit digital format, and supports multi-channel control and measurement, which facilitates the use of minimal microcontroller resource consumption. (Only one I/O pin on the microcontroller is required) to collect temperature from multiple points. The package pins of DS18B20 are shown in Figure 3-4.
Insert image description here

3.1.4 Photoelectric sensor

Photoelectric sensors can be divided into the following types according to different detection modes.
①Reflective photoelectric sensor, which integrates the light emitter and the photosensitive device. The light emitted by the light emitter is reflected by the detection object to the photosensitive device.
② Transmissive photoelectric sensor, the emitter and photosensitive device are placed in two opposite positions, and the light beam is also between two opposite objects. The object under test passing through the emitter and photosensitive device blocks the light beam and activates the photoreceiver. .
③ Focused photoelectric sensor focuses the light emitter and the photosensitive device at a specific distance. Only when the measured object appears at the focus point, the photosensitive device will receive the light beam emitted by the light emitter.

3.1.5 Infrared sensor

Infrared sensors are divided into reflective and through-beam types. Reflective infrared sensors are usually used to detect black and white objects or determine obstructions, and through-beam infrared sensors are used to detect drip speed. The commonly used infrared sensor with integrated transceiver and receiver is ST188. ST188 is composed of a high-emission power infrared photodiode and a high-sensitivity phototransistor. The detection distance has a large adjustable range, 4~13mm available, and adopts non-contact detection method. The pin diagram of ST188 is shown in Figure 3-5, and its limit parameters are shown in Table 3-1.

Insert image description here

Increase the emission power of the infrared diode. Under the conditions allowed by the extreme parameters, increasing the current flowing through the infrared diode can increase
the emission power of the infrared diode. When the transistor is turned on, there is a certain DC resistance between the collector junction and the emitter junction. In order to make the
output voltage as small as possible when the transistor is turned on, the collector resistance should be selected as large as possible, but the maximum value of the collector resistance is also limited. ,
when it reaches a certain value, ST188 will not be able to output high level when it detects black objects or obstructions.

3.1.6 Ultrasonic sensor

Ultrasonic sensors can be used to measure distances, detect obstacles, and distinguish the size of objects being measured.
The ultrasonic detection device contains a transmitter and a receiver. The transmitter emits a fixed-frequency sound wave signal outwards. When an obstacle is encountered, the sound wave returns and is received by the receiver.

3.1.6.1 Basic principles

Ultrasonic sensors are made using the principle of piezoelectric effect to convert electrical energy and sound energy. Ultrasonic sensors are divided into two types: the transmitter and the receiver are separated, and there are also the transmitter and the receiver in one body. Figure 3-6 shows the internal structure of the UCM-T®40K ultrasonic sensor.
This ultrasonic sensor uses a dual-crystal array to bond bimorphic piezoelectric ceramic sheets together in opposite polarization directions. There is a conical vibrator in the center of the metal plate. When sending ultrasonic waves, the conical vibrator has strong directivity and can efficiently send ultrasonic waves. The ultrasonic probe's chip can be made of many kinds of materials, and this type of chip uses ceramic materials. The main indicators of ultrasonic sensors are:
① Working frequency: The working frequency is the resonance frequency of the piezoelectric chip. When the frequency of the signal applied to both ends of the chip is equal to the resonance frequency of the chip, the output energy is maximum and the sensitivity is also the highest. The operating frequency of this model is (40±1)kHz (UCM-T40K1 for transmitting) and (38±1)kHz (UCM-R40K1 for receiving), so when choosing, try to choose a matching pair.
②Operating temperature: Temperature will have an impact on the operation of the ultrasonic device and the propagation speed of ultrasonic waves.
③ Sensitivity: Sensitivity mainly depends on the chip itself. The larger the electromechanical coupling coefficient, the higher the sensitivity. The device's sensitivity is greater than -70dB/V.

3.1.6.2 Principle of ultrasonic ranging

Ultrasonic ranging is based on the ultrasonic wave encountering the reflection of the object, and then calculating the distance d=vt/2 (rough formula) based on the time t when the echo is received, where v is the speed of sound in the air (340m/s at normal temperature) . In order to further improve the measurement accuracy, the geometric model of the measurement equipment needs to be considered, as shown in Figure 3-7.
The propagation pattern of sound waves should be approximately an isosceles triangle, taking into account the distance h between the transmitter and receiver. but
Insert image description here

where s=vt/2.
Insert image description here

Since the ultrasonic transmitter will have a great impact on the receiver when it is working, the ultrasonic transmitter must work intermittently, that is, after transmitting a series of pulses, it stops sending pulses and waits for the receiver to receive the echo or wait. After timeout, if there is no object and no echo, the next series of pulses will be sent for the next measurement. The waveform schematic diagram is shown in Figure 3-8.
Insert image description here

Figure 3-8 shows that the receiver will receive a series of false echoes, which is the interference generated by the transmitter. There is a delay between this interference and the transmitted wave. This is due to the transmission of signals within the system and the transmitter. caused by factors such as the distance from the receiver. Then the object cannot be measured normally between the time of pulse emission and the receipt of false echo, and the receiver must be turned off during this period. From the above analysis, we can know that the rangefinder will have a blind zone, and the size of the blind zone is a performance indicator of the rangefinder. In order to reduce the blind zone, the following aspects need to be considered: reducing the interference between the transmitter and the receiver; shortening the length of the transmitted pulse without affecting the measurement object; reasonably setting the time to turn on the receiver, etc.

Another performance indicator of the distance meter is the measurement distance, that is, the receiving circuit can identify the received echo signal. The measurement distance depends to a large extent on the comparator comparison threshold of the receiving circuit. Setting the threshold too high will affect the measurement distance, but it cannot be set to 0 because it is necessary to filter out the interference from the post-processing and the pre-stage, as well as the ultrasonic wave in the Due to the influence during the propagation process, there will definitely be noise in the received echo signal; setting the threshold too low will cause misjudgment by the instrument.

3.1.6.3 Error sources and analysis

①According to the principle of ultrasonic ranging, the geometric model of ultrasonic ranging is not necessarily a perfect isosceles triangle, so a certain error will be introduced in the measurement method.
② When ultrasonic waves are reflected by objects, the echo amplitude reflected by objects close to the distance is stronger, and the echo amplitude reflected by objects farther away is weaker. The ultrasonic waves reflected by different objects have different starting pulses that can reach the judgment threshold. Errors will be introduced.
③A factor that has a greater impact on measurement accuracy is temperature.
The speed of sound waves propagating in gas is
Insert image description here

Among them, μ, r, and R are constants, μ is the molar mass of the gas, r is the specific heat of the gas, R is the gas constant, and T is the thermodynamic temperature.
Therefore, the speed of sound is proportional to the square root of temperature, and the higher the temperature, the greater the speed of sound. The speed of sound waves at 0℃ is 331.45m/s, so the corrected speed of sound waves is
(where t is the temperature in degrees Celsius)

Therefore, to improve the measurement accuracy, temperature compensation is needed to calibrate the sound wave speed according to the temperature during measurement.

3.1.6.4 Precautions

After experimental testing, there are some precautions when using ultrasonic sensors.
① The welding time of the two terminal pins should not be too long to prevent the solder joints in the device from melting and desoldering and causing looseness between the base and the terminal pins.
② The ultrasonic sensor should not be in contact with corrosive substances.
③When using ultrasonic sensors, individual differences in devices must be taken into consideration. Although the resonant frequency of commonly used ultrasonic sensors is 40kHz, different sensors are different. Therefore, the operating frequency of the device should be tested before use, and the sensor should be operated at its resonant frequency as much as possible, so that the signal quality of the received echo will be improved. If it is not working at the resonant frequency, the receiving circuit may have to amplify thousands of times to get the required signal, but if it is working at the resonant frequency, it can achieve the same effect, or even better, by just amplifying it dozens of times.

3.1.7 Metal strain gauge sensors

Metal strain gauges can convert strain changes on the specimen into resistance changes. The measuring arm will deform when carrying a load, causing axial strain in the strain gauge wire. There is a proportional relationship between the strain of the strain gauge and the relative change in resistance. The relative change in the output voltage and resistance is linearly related through the full-bridge circuit, and the linear relationship between the load and the output voltage can be achieved.
An equal-arm full-bridge circuit composed of four identical metal strain gauges is used. R₁ and R₃ are attached to the upper surface of the beam arm and are sensitive components for weight measurement; R₂ and R₄ are attached to the side of the beam arm as temperature compensation components. The bridge output voltage is
Insert image description here

The load cell requires an amplifier with a high input impedance. Such an amplifier can be implemented by the circuit shown in Figure 3-9. This circuit uses a differential input method to better suppress common-mode signals. One end of its output is grounded to facilitate interface with subsequent circuits. The calculation formula of magnification factor A is
Insert image description here
Insert image description here

3.1.8 Proximity switch

The proximity switch is an integrated metal detection component for industrial use. The inductive proximity switch shown in Figure 3-10 is a position sensor with switching output. It is composed of an LC high-frequency oscillator and an amplification processing circuit. When a metal object approaches the oscillating sensor head that can generate an electromagnetic field, an eddy current is generated inside the object. This eddy current reacts on the proximity switch, attenuating the oscillation ability of the proximity switch and changing the parameters of the internal circuit, thereby identifying whether a metal object is approaching. , thereby controlling the on or off of the switch. When metal is detected, the output outputs a low level.
There are three colors of blue, black, and brown wires drawn from the outside of the proximity switch. The external circuit is shown in Figure 3-10. When metal is detected, the output terminal outputs a low level, and the metal detection and counting can be realized by continuously querying the status of the output terminal.
Insert image description here

3.1.9 Summary

The performance of the sensor mainly includes sensitivity, accuracy, dynamic characteristics, reliability, temperature indicators, range indicators, etc. There are many technical indicators that determine sensor performance. Requiring a sensor to have comprehensive and good performance indicators not only causes difficulties in design and manufacturing, but is also unnecessary in practice. Therefore, based on actual needs and possibilities, and on the basis of ensuring the realization of primary indicators, the requirements for secondary indicators should be relaxed in order to obtain a high performance-price ratio.
Nonlinearity and errors in sensor conversion are inevitable, and it is often necessary to adopt hardware compensation, or to find out the direction and value of the error, and use correction methods (including correction curves or formulas) to compensate and correct.

3.2 Composition of control system

The control system is composed of many functional modules. This chapter introduces the commonly used functional modules in the control system in detail.

3.2.1 Ultrasonic ranging

3.2.1.1 Launch part

The most commonly used ultrasonic sensor has a resonant frequency of 40kHz. The transmitting circuit of the ultrasonic sensor should include an ultrasonic generator, a 40kHz audio generator, a drive (excitation) circuit, and coding and modulation circuits as needed.
1.40kHz pulse generation scheme
The 40kHz signal generation circuit can be implemented in a variety of ways, and can be selected according to the user's design scheme and device limitations.
①Generated using 555 timer. It is simple and feasible to use the 555 multivibrator to generate a 40kHz square wave, but due to the large errors in the resistor and capacitor values ​​in the circuit, the output frequency error will be large.
②Generated by microcontroller. This solution has a small system size and simple hardware circuit, but requires a large number of timers and generates square signals with large errors.
③Generated using DDS direct digital frequency synthesis technology. The output waveform of this solution is stable and highly accurate, and it can output a waveform with an accurately adjustable frequency according to the frequency selection characteristics of the actual circuit, and has a large measurement range. But the circuit is too complex.
④Generated by CPLD/FPGA. In this solution, CPLD/FPGA is programmed and a frequency divider circuit is constructed to divide the 4MH₂ active crystal oscillator frequency. The output 40kHz square wave waveform is stable and easy to control.
It should be noted here that the generated signal is not necessarily 40kHz. It is best to test the ultrasonic sensor before use. Because there are individual differences between devices, the pulse generation circuit should be designed based on the measured resonant frequency, so that the The ultrasonic sensor has the highest transmission power and efficiency and the best effect.
2. Transmitting part circuit
The driving current required by the ultrasonic sensor is not large, only a dozen milliamps, but the excitation voltage is required to be above 4V, which can increase the transmitting power.
Using piezoelectric ultrasonic transducers whose transmitter and receiver models are UCM-T40K1 and UCM-R40K1 respectively, at the transmitting end, the pulse signal is directly output from the FPGA. The current is very limited, so the power provided cannot satisfy the ultrasonic sensor. Requirements required by the sender. In order to increase the power of ultrasonic transmission, the 40kHz pulse signal output by the FPGA is isolated by the inverter 74LS04 and then passed through the voltage comparator LM311 to increase the transmission voltage and then sent to both ends of the transmitter head. The circuit diagram is shown in Figure 3-11.
Insert image description here

3.2.1.2 Receiving part

1. Measurement plan
① Amplitude detection method. When the transmission power is constant, the amplitude of the echo wave attenuates as the measurement distance increases, and the amplitude of the echo wave will directly affect the accuracy of the measurement. Therefore, this solution is only suitable for rough measurement, and the accuracy does not meet the requirements of the question.
② Degree crossing time detection method. The transit time is the time from when the ultrasonic wave is sent out by the transmitter to when it is received by the receiver. Multiplying the transit time and the propagation speed of the ultrasonic wave in the gas gives the distance of the sound wave propagation. This method does not need to consider the size of the reflected signal, but only detects the presence or absence of the reflected signal. 2. The amplitude of the electrical signal obtained after
receiving the sound wave reflected by part of the circuit and passing through the acoustic-electric converter is in the mV level, and contains noise with similar amplitude.
interference, so it is not suitable to directly compare the voltage. It needs to be amplified and filtered to get the sine wave with a larger amplitude of 40kHz. After voltage comparison, the electrical signal that can trigger the microcontroller interrupt is obtained. The amplification part adopts two levels of reverse amplification connected in series. The first level amplifies

The number is fixed and the second level is adjustable. The filter circuit is a second-order voltage-controlled voltage source band-pass filter with a center frequency of 40kHz and a bandwidth of 10kHz, which can filter out 50Hz power frequency and other additive interference. As shown in Figure 3-12 and Figure 3-13.
Insert image description here

3.2.2 Application of infrared sensors

3.2.2.1 Detecting black lines

The reflective infrared sensor ST188 is used to detect black lines. When the infrared diode detects a black line, the phototransistor is turned off, and the current flowing through the transistor is very small, so the output of the transistor is close to a high level; when the infrared diode detects an obstacle, the phototransistor is turned on, because the collector-emitter gap of the transistor The DC resistance is much smaller than the resistance between the collector and the power supply, and the output voltage is close to 0V. A signal processing circuit must be added after the transistor to improve the stability of the signal and convert the high and low voltages into standard TTL levels so that the controller (microcontroller or FPGA, etc.) can perform corresponding processing. The commonly used comparator is LM311, whose threshold voltage can be continuously adjusted through a potentiometer, which can enhance the adaptability of the system. For a general single-limit comparator, if the input signal has slight interference near the threshold value, the output voltage will produce corresponding jitter. Introducing positive feedback into the circuit can solve this problem. Usually, more than one infrared sensor is used in the control system. When multiple infrared sensors are used, in order to make the hardware circuit simpler, LM339 is often used. This chip integrates four voltage comparators. The infrared detection black line module circuit is shown in Figure 3-14.
The principle of distance measurement using infrared sensors is similar to that of detecting black lines. When the infrared diode does not detect an obstacle, the photosensitive transistor is turned off, the current flowing through the transistor is very small, and the output is high level; when the infrared diode detects an obstacle, the photosensitive transistor is turned off. The transistor is turned on and the output is low level. The downstream stage of the transistor is still connected to a comparator circuit, and the threshold voltage is adjustable. However, this method can only measure distance qualitatively, and it is difficult to achieve quantitative measurement.
.  155    .

3.2.2.2 Detect drip speed

The infrared transmitting and receiving tube is used to detect the dripping speed. The through-beam photoelectric sensor (hereinafter referred to as the sensor) is divided into two parts: the input device and the photoreceiver. The optical axes of the two parts coincide on the same straight line. When working, the emitter emits modulated light, which is received by the photoreceiver and turned into an electrical signal. When the object under test enters the detection area, the light is blocked, the photoreceiver has no light to receive, and the sensor output state changes. However, after the sensor has been working for a period of time, the adjusted optical axis will change. Use black tape to fix the dropper to reduce external interference and minimize errors.
When the droplets drip, due to the scattering effect of water on infrared light, the photoreceptor cannot receive infrared light, the photoreceptor is cut off, and the output is low level; when no droplets are dropped, the photoreceptor is turned on and the output is high level. The output level is amplified, compared with LM311, and shaped by 74HC04 to output a standard rectangular wave signal for FPGA to read. The circuit is shown in Figure 3-15. The positive input terminal of LM311 is connected with a feedback resistor to form a hysteresis comparator to prevent edge jitter.
Insert image description here

3.2.3 Photoresistor detects light source

Photoresistors are often used in smart cars to detect light sources. The resistance of the photoresistor generally varies between 20 and 200kΩ. When there is light, the resistance is low and the output voltage is small. When there is no light, the resistance is high and the output voltage is large. Connect the photoresistor and a resistor with a resistance of 2 to 10kΩ in series to divide the voltage. The divided voltage is input into the comparator. By adjusting the comparison level of the comparator, the intensity of the light can be roughly judged. The circuit diagram is shown in Figure 3-16.
In order to detect the light source more accurately, three photoresistor voltage dividing circuits are installed on the front of the car, and one photoresistor voltage dividing circuit is installed on each side of the car body. The controller uses MSP430F449. The output of the voltage divider circuit is connected to the P6.0~P6.2 port of the microcontroller. It is sampled by the built-in A/D converter, and then the magnitude of each voltage is compared to accurately determine the position of the light source. Compared with the design of ordinary microcontrollers, the internal ADC sampling module of the MSP430 microcontroller simplifies the hardware circuit of the entire system.
It should be noted that the photoresistor should be covered with a black leather cover to prevent light interference and enhance its directionality.
Insert image description here

3.2.4 Application of temperature sensor

The application circuit of the analog integrated temperature sensor LM35 is shown in Figure 3-17. The signal directly coming out of the LM35 is relatively weak and needs to be connected to a level of amplification to adjust the signal to a range suitable for the A/D converter measurement, otherwise it will have a greater impact on the sampling accuracy of the ADC. Considering the amplification accuracy and the need for common-mode interference signal suppression, a precision high-common-mode rejection ratio operational amplifier OPA277 is selected and connected to form a codirectional amplification circuit. The 12-bit high-precision serial port A/D conversion chip ADS7886 can be used here. The serial port ADC can save resources. And due to the slow temperature change rate, you can choose an ADC with a lower sampling rate, and MAX197 is recommended. If you only measure the temperature within a certain positive temperature range, you can choose a 3.3V reference voltage and high-resolution sampling chip, such as LTC1865, etc.
Insert image description here

The application circuit of digital temperature sensor DS18B20 is shown in Figure 3-18.
157

3.2.5 Angle measurement module

3.2.5.1 Angle measurement solution

Option 1: Use the formed inclination sensor UCB-1 (Universal Conditional Broad). It can measure the inclination angle of ±20°, and the measurement accuracy at 25°C is less than 0.126°. However, the cost of this sensor is relatively high, and its temperature characteristics are not ideal.
Option 2: Use the molded angle sensor AME-B002. The measurement range is 0° 360°, the resolution reaches 0.0879°, and the output voltage is 0.5 +4.5V. By fixing a weight on its measuring axis, when the inclined plane tilts, the weight drives the measuring axis to rotate and tilt at an angle value corresponding to the corresponding analog voltage output. Although the weight easily vibrates and swings, causing output voltage fluctuations, accurate angle information can still be obtained by averaging the sampled values.

3.2.5.2 Angle measurement circuit

Choose option 2 for angle measurement, and the circuit is shown in Figure 3-19.
Insert image description here

Angle sensors have practical applications in electric vehicle seesaws. The system model is shown in Figure 3-20.
Insert image description here

Assume that the car has advanced x distance after reaching the theoretical equilibrium point C. Due to the influence of friction, the system is exactly balanced. Take the entire system as the research object for stress analysis, as shown in Figure 3-20. G₁ and G₂ are the gravity on the left and right boards of the seesaw respectively. G₃ is the gravity on the car. L₁, L₂ and L₃ are the moment arms from G₁, G₂ and G₃ to the equilibrium point C respectively. φ is the force of the board when it is balanced. The inclination angle, h is the height difference between the two ends of the board, M is the torque of the kinetic friction of the central axis, the kinetic friction coefficient is μm, the board length is L, and the distance from the contact point of the rotating shaft and the base to the center of mass of the board is R.
The balance equation is: G₁L₁-G₂L₂-G₃L₃+M=0
Insert image description here
With the above equation and the use of the angle sensor, the car can be controlled to reach the equilibrium point of the seesaw. It should be noted that when using the angle sensor, the weight on the angle sensor swings, causing the output voltage waveform to be a damped and attenuated sine wave, as shown in Figure 3-21. Since the voltage attenuation in one cycle is very small, the average value of one cycle is the inclination value in this state. The period measured with an oscilloscope is 372ms, and the maximum error is ±1ms. MAX197 is used to sample the waveform of one cycle. After calculation and actual measurement, 1150 samples can be carried out in one cycle. The average value of the collected data is the inclination value. The single measurement time is about 372ms. Since the car runs slowly during speed regulation at the balance point, the single measurement time can meet the feedback speed requirements.
Insert image description here

3.2.6 Control and drive of DC motor

3.2.6.1 Power supply solution

DC motors have large output power and strong load capacity, and are often used to drive cars in smart car systems. The smart car is different from other systems. It is a moving body and cannot be connected to the power supply by wires like other devices. It must work with its own battery.
Since the instantaneous current of the DC motor is very large when starting, and the PWM drive current fluctuates greatly, it will cause voltage instability, glitches and other interferences. In severe cases, the microcontroller system may be powered off. In addition, considering that the motor consumes relatively large power, dual power supplies are used to supply independent power to the motor drive circuit, the microcontroller and its peripheral circuits. This can eliminate interference caused by the motor drive and improve system stability.

3.2.6.2 Motor drive circuit

There are several methods for motor drive circuits: voltage regulation method, which adjusts the motor's partial voltage through a resistor network or digital potentiometer to achieve speed regulation. However, this method can only achieve limited-level speed regulation, and due to the internal resistance of the motor Generally small, so the efficiency of the motor after voltage division is not high; a relay is used to control the on or off of the motor, and the speed of the car is adjusted by controlling the switching speed of the switch. This solution has a simple circuit, but the mechanical characteristics of the relay are easily damaged, have a short life, and are not highly reliable.

  1. H-type PWM circuit
    A currently widely used method is to use an H-type PWM circuit composed of Darlington tubes, and control the motor by controlling the on and off of the power amplifier tube through a microcontroller. The Darlington tube works alternately in saturation and cut-off modes, so it is very efficient. The H-type PWM circuit can simply control the speed and direction. The electronic switch is very fast and has extremely strong stability.
    The H-type power amplifier circuit is shown in Figure 3-22. It controls the forward and reverse rotation of the motor by controlling the on and off of VT₁ and VT₂. A little explanation here is that considering portability, MSP430F449 is usually used as the controller in smart car systems. The microcontroller outputs a PWM signal with adjustable frequency. When the PWM signal is applied to the "1" terminal and the "reverse" terminal at the same time, VT₃ and VT₂ are turned on, VT₁ and VT₄ are turned off, and B is the positive pole. The motor rotates forward: when the "2" terminal and the " When the PWM signal is applied to the positive terminal at the same time, VT₁ and VT₄ are turned on, VT₁ and VT₂ are turned off, and A represents the positive pole of the motor to reverse. By adjusting the duty cycle of the PWM signal, the motor speed can be accurately controlled.
    Insert image description here
    The main disadvantages of the relay coupling method are high cost and power consumption. In addition, when the relay is closed and turned on, the relay will produce strong electromagnetic radiation, forming a noise source and having a greater impact on small signals. Therefore, the PWM pulse signal and the DC motor are coupled using an optocoupler.
    Optocoupler devices are relatively cheap, and there is no electromagnetic radiation during coupling, and they can well isolate small signal circuit units from motor circuit units. In addition, the optocoupler method saves power (this factor is more important in battery-powered systems). However, when using optocoupler devices, be sure to choose products of the same model and series. Because the linearity of optocoupler devices is poor, you should try to choose devices with the same linearity.
    2. Integrated motor driver chip
    Another way is to use an integrated motor driver chip. The main driver chip used here is the dual-bridge driver chip L298N of SGS-THOMSON Company. Its maximum DC drive current is 4A, and its output is TTL logic level. Its application circuit diagram is shown in Figure 3-23.
    1.298N directly integrates two pairs of motor drive circuits, of which pins 10 and 12 are used as control inputs, and pins 13 and 14 are used as corresponding control outputs to control a DC motor; pins 5 and 7 are used as another pair of control inputs, and pins 2 and 3 are used as control inputs. as its corresponding output to control another DC motor. Here, we take the pair of control inputs 10 and 12 as an example, as shown in Figure 3-23. When pin 10 inputs a positive pulse and pin 12 is connected to a low level, the motor is rotating, and its speed is determined by the duty cycle of the positive pulse. Determine; on the contrary, when pin 10 is connected to low level and pin 12 is connected to positive pulse, the motor will turn left.
    Insert image description here

3.2.7 Stepper motor control and drive

Stepper motors have strong ability to start and stop quickly, and can achieve precise control of displacement by controlling the number of steps they rotate. Stepper motors are used in the suspension pad control system to control the movement of objects and in the drip detection system to adjust the height of the hanging bottle.

3.2.7.1. Stepper motor control principle

The stepper motor is a digitally controlled motor that converts pulse signals into angular displacement. That is, given a pulse signal, the stepper motor rotates by an angle, so it is very suitable for microcontroller control. Stepper motors can be divided into reactive stepper motors (VR for short), permanent magnet stepper motors (PM for short) and hybrid stepper motors (HB for short), among which hybrid stepper motors are the most widely used.
The biggest feature that distinguishes the stepper motor from other control motors is that it is controlled by inputting pulse signals, that is, the total rotation angle of the motor is determined by the number of input pulses, and the speed of the motor is determined by the frequency of the pulse signal.
The drive circuit of the stepper motor works according to the control signal, which is generated by the microcontroller.
1. Control the commutation sequence.
The process of power-on commutation is called pulse distribution. For example, in the six-beat working mode of a three-phase stepper motor, the energization sequence of each phase is →A→AB→B→BC→C→CA. The energization control pulse must strictly follow this sequence to control the A, B, and C phases respectively. On and off.
2. Control the steering of the stepper motor.
If the stepper motor is energized in positive sequence and phase commutation is given in the given working mode, the stepper motor will rotate forward; if the phase commutation is energized in the reverse sequence, the motor will rotate in the reverse direction.
3. Control the speed of the stepper motor.
If you send a control pulse to the stepper motor, it will turn one step, and if you send a control pulse again, it will turn one step again. The shorter the time between the two pulses, the faster the stepper motor will rotate. By adjusting the pulse frequency emitted by the microcontroller, the speed of the stepper motor can be adjusted.
Stepper motors require current pulses to drive, and driving stepper motors requires relatively high current signals. Signals coming directly from microcontrollers, CPLD or EPGA chips cannot drive stepper motors. If the current value does not meet the requirements, the stepper motor will not be able to operate normally or even start normally. Therefore, in order to ensure the accuracy of control, it is necessary to use a high-performance drive circuit as much as possible to ensure good operating performance of the stepper motor.

3.2.7.2 Stepper motor drive circuit

1. Stepper motor drive circuit built with Darlington tube
Figure 3-24 shows a typical drive circuit when the motor adopts four-phase eight-beat working mode. In the drive circuit, TIP41C Darlington transistor is selected, and the power resistor R parameter is 8Ω and 2W. A protection diode (model IN4002) is connected between the collector and the power supply to prevent the power tube VT from changing from the working state to the cut-off state. At this time, due to the continuity of the inductive motor winding current, a strong reverse electromotive force (current) will be generated on the C pole of the triode and damage the triode; the diode (model IN4002) between the E and C poles is added to increase the resistance of the triode. The reverse withstand voltage value plays the role of leakage protection.
Insert image description here

Its working principle is: when a high level is input to the A, B, C, and D level input terminals, the photodiode emits light, so that the optocoupler transistor works. Since the currents of the C and E poles of the transistor are roughly equal, the C pole and the E pole are equivalent to conduction, thus forming a loop from the power supply to the ground, causing the Darlington transistor to be unable to work, thus making the phase of the motor unable to operate. Work. On the contrary, when the A, B, C, D level inputs are low, the optocoupler transistor does not work, but at this time the Darlington transistor works, ultimately driving the stepper motor to rotate.
2. The stepper motor drive circuit composed of L298N
L298N can drive two two-phase motors or one four-phase motor. The output voltage can reach up to 50V. The output voltage can be adjusted directly through the power supply. The drive circuit of the stepper motor is formed through L298N, as shown in Figure 3-25.
Send square wave pulse signals to the IN1~IN4 ports and ENA and ENB ports of L298N through the microcontroller.
3. Integrated drive block
The integrated drive block has strong driving capability and stable operation. An optocoupler isolator is added inside to completely isolate the control circuit from the drive circuit, preventing the motor from affecting the control circuit during starting and braking.
The choice of integrated drive block varies depending on the selected stepper motor. Most commonly used stepper motors are three-phase or four-phase. Here we take a three-phase motor as an example. There are 6 convex teeth on the stator of the three-phase stepper motor, and there is a coil on each tooth. The connection method of the coil winding is that the two coils on the symmetrical teeth are connected in anti-phase, as shown in Figure 3-26. The 6 teeth constitute 3 pairs of magnetic poles (AA, BB, CC). The 45BC340F three-phase stepper motor from Changzhou Micro Motor Factory is used here, and the UP-3BF04 model integrated drive block can be used.
The driver is simple to use and only requires two signal lines to achieve precise control of the three-phase stepper motor. One signal line controls the rotation direction of the motor by outputting a logic level, and the other signal line controls the rotation speed of the motor by outputting a square wave signal with variable frequency, as shown in Figure 3-27. It must be noted that there is a frequency in the stepper motor drive signal that must be avoided - the resonant frequency f₀.
Insert image description here

The characteristics of the UP-3BF04 driver are: ① PWM constant current drive, three-phase six-beat excitation mode, extremely low power loss and extremely high switching efficiency; ② Automatic half-current locking function, the drive current can reach 4A; ③ All control signals and The power drive part is photoelectrically isolated; ④The heat dissipation shell is completely insulated from the inside of the driver. The pin description is as follows:
(1) Motor drive part
A: Motor winding A is connected to the red wire terminal;
B: Motor winding B phase is connected to the green wire terminal;
C: Motor winding C phase is connected to the yellow wire terminal.
(2) Control part
CP: step pulse input terminal, rising edge is valid;
U/D: direction controller, the motor rotates forward when U/D=1, and the motor reverses when U/D=0 or floating; FREE
: off Machine side, high level is active, that is, when FREE=1, the motor is in the release state;
SGND: All control signal ground wires, this terminal must be isolated from the driving power supply ground wire (GND);
VDC: Motor driving power supply, DC 18 40V, No voltage stabilization is required, and it can withstand voltage fluctuations of -20% +15%;
GND: driving power ground wire, this end must be isolated from the signal ground wire (SGND).

3.2.8 Voice module

3.2.8.1 Preamp channel

1. Voice input stage
The microphone uses the relatively popular electret microphone, which has the characteristics of small size, simple structure and high cost performance. Its main internal component is a field effect transistor, which can convert ordinary human voice into a voltage signal of 5~10mV.
The preamp channel is used to amplify the weak voice signal output by the microphone into the input range of the A/D converter and reduce input noise as much as possible. There are two options for voltage amplification:
(1) In-phase amplification
In order to achieve impedance matching between the signal input stage and the amplification stage, a first-level emitter follower is added between the microphone and amplifier to play the role of isolation and buffering. The actual circuit connection is shown in Figure 3-29. Then design several stages of non-inverting amplifiers according to the specific amplification factor. Try to use a potentiometer for the gain resistor to facilitate adjustment. If the gain of the front stage is small, make fine adjustment, and if the gain of the rear stage is large, make coarse adjustment. The non-inverting amplifier has a high input impedance and is simple in form. It adopts a multi-stage cascade method to obtain a very high voltage gain.
Insert image description here

(2) Differential amplification
considers that single-ended microphone input amplification will cause large background noise, so two microphones are used to connect to the positive and negative terminals of the differential amplifier. The differential amplification circuit has a very high common mode rejection ratio, which is good for speech signals. The common mode noise has a high suppression effect. In addition, this circuit can effectively suppress zero point drift and temperature drift.
The differential amplifier circuit is shown in Figure 3-30. The first stage uses dual microphone differential inputs to effectively suppress environmental noise. Its differential mode voltage gain is 82 times. Capacitors C₁, C₂, C₃, and C₄ are DC blocking capacitors to eliminate the impact of DC components on the system.
It is worth mentioning that compared with traditional differential amplifiers, instrumentation amplifiers (such as AD620, INA118, etc.) can further reduce the interference of audio electrical signals from outside the system, so instrumentation amplifiers can be preferred in system design.
2. Filter design
The human voice frequency range is 300~3400Hz. In order to minimize external noise interference, prevent mixing distortion, and improve the signal-to-noise ratio, a band-pass filter must be designed to make the sound stored and then played back by the system as clear and unclear as possible. distortion. Filtering requires flatness in the passband and steep transition bands. In general, the passband of the Butterworth filter is relatively flat, and the use of multi-order filtering can make the transition band steeper. Therefore, 4th-order Butterworth low-pass and 4-order Butterworth high-pass cascades are used here. The cut-off frequency of the low-pass filter is 3.4kHz, which makes it
·  166  ·

It is used to filter out-of-band high-order harmonics to reduce aliasing distortion caused by the 8kHz sampling rate. The cut-off frequency of the high-pass filter is
300Hz, which filters out-of-band low-frequency signals to reduce interference from out-of-band power frequency components and greatly reduce the impact of noise. Because there is
a specially designed amplification circuit in front, the gain of the filter is 1.
The parameters of each component of its normalized filter can be calculated from the poles of the fourth-order Butterworth function . The circuit diagram is shown in Figure 3-31.
Insert image description here
Insert image description here

3.2.8.2 Back Channel

1. Power amplifier
If you want to realize the external amplifier function, the signal is amplified and output by the speaker. The power amplification uses universal audio power

Amplifier LM386 is used to complete the circuit diagram as shown in Figure 3-32. Among them, C₁ and C₂ are used for power supply filtering. Because multiple integrated operational amplifiers of the entire voice module share a DC power supply, coupling through the internal resistance of the power supply sometimes produces low-frequency oscillation. The method of power deregulation can effectively suppress low-frequency oscillation. C₂ forms a low-impedance path for high-frequency signals and plays a high-frequency filtering role; C₁ is used for low-frequency filtering, and its maximum amplification factor is 25.
Insert image description here

However, the Class D audio power amplifier TPA2000d2 (its pin diagram is shown in Figure 3-33) or TPA2000d4 produced by TI is currently very popular and is often used for power amplification in audio. Taking TPA2000d4 as an example, the following briefly introduces the usage of this chip.
Insert image description here

The chip operates on a +5V power supply and is capable of driving speakers with impedances as low as 4Ω. Since the chip uses TI's second-generation modulation technology, its efficiency and signal-to-noise ratio have been significantly improved, which allows the chip to be directly connected to the speaker without the need for an external LC filter at the output of the power amplifier. The gain of the amplifier can be set to 6, 12, 18, and 23.5dB by the GAIN1/GAIN2 pins respectively. The chip also integrates a headphone amplifier, and the MODE pin is used to select the amplifier type. Its typical application circuit diagram is shown in Figure 3-34.
2. Smoothing filtering
To filter out the high-frequency components in the DAC output signal, you can independently design a multi-order low-pass filter, or you can directly use the audio band-pass filter shown in Figure 3-31.
Insert image description here
Since the actual sampling pulse has a certain duration (flat-top sampling), the spectrum of the sampled signal is determined by the ideal sampling signal
Insert image description here
Insert image description here

3.2.9 Wireless transceiver module

For specific applications of wireless transceiver modules, see Chapter 4 of this book. In the control system, considering the scale of the system and the flexibility of control, integrated transceiver modules are generally used. The integrated transceiver module not only has flexible control, but also has a low bit error rate during transmission and strong anti-interference ability, making it suitable for uninterrupted communication between relatively moving objects.

The integrated transceiver module RF24L01 is introduced here. The chip is powered by 3.3V, has low power consumption, has a maximum operating rate of 2Mbps, has a built-in 2.4GHz antenna, and uses efficient GFSK modulation with strong anti-interference ability. This chip is made into a PCB and has a built-in special voltage stabilizing circuit, so that it has good communication effects when powered by various power sources. This module can set the address through software. It will output data only when it receives the local address. It can be directly connected to various microcontrollers for use. Software programming is very convenient. The module schematic diagram is shown in Figure 3-36.
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_47567401/article/details/131347688