0Introduction
In modern industrial measurement systems, the measurement of displacement and rotation speed is a key link. Although the early measurement systems were relatively mature in technology, they were generally composed of discrete components, resulting in low measurement accuracy, poor stability, high cost, and poor anti-interference ability. With the development of electronic technology and computer technology, the measurement system has gradually transformed into an intelligent one. This paper uses PIC microcontrollers to realize real-time measurement of rotation speed. By deriving the measurement error algorithm of the multiple period method, an effective method for determining the period multiple N in the multiple period method is obtained, so that there is a small error in both high and low speed measurements. The hardware structure of this design is simple, the measurement speed is fast, the accuracy is high, and the operation is reliable, which can meet people's increasingly high requirements for speed accuracy and real-time performance.
1 Main performance characteristics of the system
(1) The hardware structure is simple in design, with fast measurement speed, high accuracy and reliable operation.
(2) Using a PIC microcontroller with EEPROM, a simple and reliable power-off protection function is designed.
(3) Two measurement modes: rotation speed and speed (when measuring speed, the circumference of the turntable must be entered in advance using the key).
(4) It has upper and lower limit alarm functions, which is suitable for occasions where there are restrictions on speed or rotation speed.
(5) There are 3 independent buttons for conveniently setting the upper and lower alarm limits, measurement mode and turntable circumference.
2 System Hardware Design
Figure (1) System architecture
PIC16F874A is an 8-bit Flash microcontroller produced by Microchip Corporation of the United States. It has the characteristics of low function, low working voltage, high performance, high speed, full static, strong pin direct drive capability, etc. Due to the use of Harvard dual bus and two-level instruction pipeline structure, instruction execution and instruction fetching operations are carried out simultaneously, so it can achieve a very high execution speed. This series of microcontrollers has only 35 single-byte instructions. Except for the jump instruction which is a 2-cycle instruction, all other instructions are single-cycle instructions. Compared with other 8-bit microcontrollers, this saves 1/2 of the program space and has a speed advantage of 4:1. PIC16F874A has 4K×14 program memory, 192 bytes of general registers, 128 bytes of EEPROM, 33 I/O ports, 3 timers/counters and 2 capture/compare/PWM modules, 2 serial ports, A/D converter with 5 analog input terminals, and clock, reset, watchdog timer, etc. Because the microcontroller has very rich resources, the hardware circuit is simplified, thereby reducing costs.
2.1 Signal input circuit
The device used in the design of this part of the circuit is the OPTC photointerrupter produced by Sharp. In fact, other devices can also be used as long as they can generate a pulse signal that can be detected by the microcontroller. The photointerrupter integrates the GaAs infrared light-emitting diode of the light-emitting part, the photodiode of the light-sensitive part, and the signal processing circuit (amplifier, Schmitt trigger and voltage regulator circuit, etc.) on a chip. This photointerrupter has the following characteristics:
(1) Small size and high reliability;
(2) Few peripheral circuits;
(3) Can be directly connected to TTL, LSTTL, and CMOS devices;
(4) Wide operating voltage range (Vcc=4.5-16V)
2.2 Power-off protection circuit
When the microcontroller is working, if there is a sudden power failure due to some reason, the data in the data memory (RAM) will be lost, and all the information of the previous work will be flushed. Although there is a large-capacity filter capacitor in the main power supply of the microcontroller, when the power is off, the microcontroller can generally maintain operation for about 10ms by relying on the energy stored in the capacitor. For this reason, it is required that once the main power is cut off, the data in the RAM must be promptly transferred to the EEPROM data register within less than 10ms, and the data must be retrieved from the EEPROM when the power is turned on next time to ensure that the microcontroller system can operate normally. Since 128 bytes of EEPROM are integrated in the PIC16F874A microcontroller, the protection circuit is very simple. The specific circuit is shown in Figure (2). Its working principle is as follows: When the RB4-RB7 pins of the B port of the PIC microcontroller are set to input mode, when the input level changes from high to low or from low to high, the microcontroller can generate an interrupt, which is usually called a pin state change interrupt. When the 12V power supply voltage is within the normal range, the level of the MCU RB4 pin is high; when the 12V power supply is cut off, the unidirectional conductivity of the diode D1 blocks the loop of the filter capacitor C3, causing the voltage on the RB4 pin to drop rapidly enough to trigger the level reversal of the internal circuit of the RB4 pin, triggering an interrupt, and completing the burning of the data to be protected into the EEPROM in the interrupt program. At the moment of burning, the working power of the MCU is sufficient to be maintained by the power filter capacitor.
3. Detection Method and Error Handling
Usually, the measurement of rotation speed or speed can be converted into the detection of signal frequency (or period). The three most commonly used methods for detecting signal frequency are: counting method, period method and multiple period method. Among them, the counting method is suitable for measuring high frequency, and it takes a long time to measure low frequency, so the error is large; the period method is suitable for measuring low frequency, and the frequency of the reference pulse required for measuring high frequency signal is high, so the error is large; the common advantage of these two methods is that they are relatively simple to implement. The multiple period method can solve the contradiction between high and low frequency to a certain extent, but it is relatively difficult to implement. Because the multiple period method requires a proper multiple N to be determined in advance, and it is difficult to determine N in advance. If N is not determined properly, it will also increase the detection time or have a large error at high frequency. In actual design, this paper makes some improvements to the multiple period method and proposes a simple algorithm for determining N, which can automatically determine the appropriate N and meet the detection requirements of high and low frequency signals.
The multiple period method is improved from the period method. When measuring the period of a signal, a reference pulse with a fixed frequency is used as the clock signal of the adder counter. The adder counter is started at the beginning of a period of the measured signal; then, the counting is stopped at the end of this period. Assuming that the value of the counter is M at this time and the period of the reference pulse is Tm, then M, Tm and the period T of the measured signal have the following relationship:
T = M * Tm Speed n = 60/T = 60/(M * Tm) (rpm)
In this section, we only discuss the detection method and error processing of rotation speed, because the detection method and error processing of rotation speed and speed are similar. The relationship between rotation speed n and speed v is: v = n * L/ 60 (m/s) (where L is the circumference of the turntable)
The speed corresponding to one Tm cycle is: n/M = 60/(M * M * Tm)
As shown in Figure (3), the maximum error is 2 * n/M , that is, the maximum error = 2 * n /M = 120/(M * M * Tm) .
Figure (3) Relationship between reference pulse signal and detected signal
This explains why the periodic method is suitable for measuring low-frequency signals. From the error relationship, it can be seen that when n is large, the error is large; when n is small, the error is small. From the above formula, we can also get two ways to reduce the error n: one is to increase M; the other is to increase Tm. For a certain detector, Tm is a fixed constant. In this way, the M value can only be increased. However, for a speed n, M within a cycle is also a relatively fixed value. Therefore, to increase the M value, the only way is to increase the number of detection cycles, that is, to expand the measurement from one cycle to multiple cycles. If it is assumed that the count value within N cycles is Mn, then:
It can be seen that these two formulas are contradictory. To reduce the error, N must be increased, and the measurement time will increase accordingly; to reduce the measurement time, N must be reduced, and the error will increase accordingly. Obviously, it is difficult to determine an appropriate N value in advance, because different speeds correspond to different N values.
In view of the problem that it is difficult to determine the value of N, this article adopts a more reasonable method to determine the value of N. For a single-chip microcomputer, the number of bits of its counter is limited, assuming it is P bits. For a speed n, when the counter reaches the full scale, the corresponding error is the smallest. Therefore, in order to minimize the detection error, the N value corresponding to a speed n can be determined based on whether the counter reaches the full scale. Assuming that the single-chip microcomputer instruction execution cycle is Tm, the counter overflow time is Tn, the number of detected signals is N, and the speed at this time is n, there is the following relationship:
Tn = ( ) Tm error: n = 120 / [( )( ) Tm / N]
Speed: n = 60N/ ( ) Tm (rev/min)
From the relationship between n and N, we can see that different n has different N values. To find the N value when the counter reaches full scale, the specific method is: use the counter 1 of the microcontroller to count, and then use software to design a counter to count the measured signal. When counter 1 overflows, the value of the counter can be taken to calculate the required N value. In this way, there is no need to predetermine an N value as in the usual multiple period method.
4 Speed measurement algorithm and system implementation program
This article uses PIC microcontroller to implement the speed measurement system. In the PIC mid-range series microcontroller, timer TMR1 is a standard configuration, which is a 16-bit timer/counter. As shown in Figure (2), we input the detection signal to the INT terminal of the microcontroller. The timing of timer 1 and the interrupt function of INT are used to achieve measurement.
4.1 Main program flow chart see Figure (4)
(1) Initialization program: Initialize timer 1, INT1 and various input and output port settings, clear the display buffer, etc.
(2) Key scanning program: When a key is pressed, the program responds accordingly to set the upper and lower alarm limits, measurement mode, and the circumference of the turntable being measured.
(3) Measurement value comparison and alarm: The value in the display buffer is compared with the upper and lower limit alarm values preset in the EEPROM one by one. When it is greater than the upper limit or less than the lower limit, an alarm is triggered.
(4) Display program: The BCD code in the display buffer is decoded by table lookup and sent to the seven-segment digital tube for display.
4.2 Interrupt service program flow chart see Figure (5)
(1) Interrupt type judgment: When TMR1 interrupts, the number of overflows of counter 1 W = W + 1; when INT interrupts, the number of cycles of the detected signal N = N + 1; when RB4 level changes, the data that needs power-off protection is saved in EEPROM;
(2) The formula for calculating the rotation speed n is: , where Tm is the instruction execution cycle; the formula for calculating the speed is: v =n*L/60 (m/s) where L is the circumference of the wheel.
Figure (5) Interrupt program flow chart
Cycle; The speed is calculated as:
v =n*L/60
(m/s)
where L is the circumference of the wheel.
Figure (4) System main flow chart
5 Conclusion
This paper introduces a system that uses a single-chip microcomputer as the core device to achieve high-precision rotation speed and speed measurement. After analyzing the error of the speed measurement system, the feasibility and practicality of this method are demonstrated, and the system is successfully used to measure the speed of the winch. During the test, all functions are normal, the operation is reliable, the use is convenient, the effect is good, and the design requirements are met.
The author of this article innovates: he adopts a method of determining the multiple N of the multiple period method based on the overflow of the microcontroller timer, successfully solving the difficulty of determining the multiple N; he designs two measurement modes, namely, rotation speed measurement and speed measurement, and has upper and lower limit alarm functions, which makes the system have a wider application prospect.
References :
[1] Jiang Qingming, Yang Xu, Gan Yongmei, Wang Xiaoyu, Wang Zhaoan. A high-precision speed and acceleration measurement method based on photoelectric encoder [J]. Microcomputer Information, 2004, 6: 48-50.
[2] Zhang Mingfeng. Introduction and Practice of PIC Microcontroller. Beijing University of Aeronautics and Astronautics Press, 1st edition, 2004.
Previous article:Microcontroller Controlled Analog Phase Shifter
Next article:Using the MCLR pin as an output on a PIC microprocessor
Recommended ReadingLatest update time:2024-11-16 19:54
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- LTC2325-16 Sampling Issues
- Design considerations for single-chip microcomputer key scanning program
- How to change the library file in the schematic diagram in orcad?
- Free application: Domestic FPGA Gaoyunjia Little Bee Family GW1N Series Development Board
- Taking stock of the college entrance examination experience of Internet tycoons! How many points did you get in the exam?
- Without American EDA software, we can’t make chips?
- 【Share】Flash management tools: FAL (Flash Abstraction Layer) library
- Good morning my love——One Xiao and One Jian
- [Awards awarded] Grab the post! Download the TWS headset white paper, write a wonderful review, and win a JD card!
- [RVB2601 Creative Application Development] Record the startup process of the hello world system