Design of a DC motor speed measurement system based on Hall effect sensor
2026-04-06 07:12:50··#1
Introduction With the continuous innovation of microcontrollers, especially the emergence of high-performance, cost-effective microcontrollers, speed measurement and control have widely adopted digital and intelligent systems centered on microcontrollers. This paper introduces a DC motor speed measurement system using a C8051F060 microcontroller as the main controller and a Hall sensor for measurement. 1. Basic Principles of Speed Measurement and Control 1.1 Speed Measurement Principle There are many methods for measuring speed. The main methods based on pulse counting for speed measurement include the M-method (frequency measurement method), the T-method (period measurement method), and the MPT method (frequency-period method). This system uses the M-method (frequency measurement method). Since speed is measured in revolutions per unit time, most of the changes are regular repetitive motions. Based on the Hall effect principle, a permanent magnet is fixed to the edge of a turntable on the motor shaft. The turntable rotates with the shaft, and the magnet rotates synchronously. A Hall device is installed below the turntable. When the turntable rotates with the shaft, influenced by the magnetic field generated by the magnet, the Hall device outputs a pulse signal, the frequency of which is proportional to the speed. The period of the pulse signal is related to the speed of the motor as follows: Where: n is the motor speed; P is the number of pulses per revolution of the motor; T is the period of the output square wave signal. The speed of the DC motor can be calculated according to formula (1). A Hall device is a thin film made of semiconductor material. When an external magnetic field B is applied in the direction perpendicular to the plane and an external electric field is applied at both ends along the plane, electrons move in the magnetic field, resulting in a Hall potential between the two sides of the device. Its magnitude is proportional to the magnitude of the external magnetic field and the current. Hall switch sensors are widely used in the field of measuring the rotational speed of rotating objects due to their small size, no contact, good dynamic characteristics, and long service life. Here, the 3013 Hall switch sensor of the 3000 series produced by Sprague Corporation of the United States is selected. It is a silicon monolithic integrated circuit. The device contains a voltage regulator circuit, a Hall potential generator, an amplifier, a Schmitt trigger and an open collector output circuit. It has the characteristics of wide operating voltage range, high reliability, simple external circuit and output level compatibility with various digital circuits. 1.2 Speed Control Principle The speed of a DC motor is related to the voltage applied across the motor terminals. The output of the D/A converter DAC0 within the C8051F060 chip can be used to control the DC motor voltage, thereby controlling the motor speed. Here, a simple proportional regulator algorithm (simple add-one, subtract-one method) is adopted. The output system formula of the proportional regulator is: Where: Y is the output of the regulator; e(t) is the input of the regulator, generally the deviation value; Kp is the proportional coefficient. It can be seen from equation (2) that the output Y of the regulator is proportional to the input deviation value e(t). Therefore, as soon as the deviation e(t) appears, a proportional regulation effect is generated, which has the characteristic of timely regulation. This is a basic regulation law. The magnitude of the proportional regulation effect depends mainly on the proportional coefficient Kp, in addition to the deviation e(t). The larger the proportional regulation coefficient, the stronger the regulation effect and the greater the dynamic characteristics. Conversely, the smaller the proportional coefficient, the weaker the regulation effect. For most inertial links, Kp too large will cause self-excited oscillation. The main drawback of proportional control is the existence of steady-state error. For inertial elements with disturbances, a large Kp will cause self-excited oscillation. For systems with large disturbances and large inertia, it is difficult to balance dynamic and static characteristics using a simple proportional controller. A more complex PI (proportional-integral) or PID (proportional-integral-derivative) algorithm is required. 2. System Hardware and Software Design 2.1 Hardware Design This system uses a C8051F060 microcontroller as the main controller. A Hall sensor is used to measure the motor speed, and the test results are finally displayed on an LED via a 7279 chip. In addition, the motor speed can be adjusted as needed. The hardware composition is shown in Figure 1. The C8051F060 controller mainly completes the acquisition of speed pulses, counting and timing with a 16-bit timer/counter, calculation and comparison, and the integrated 12-bit DAC0 controls the speed. It also implements digital display and other functions through a 7279 display interface chip. The system uses an external crystal oscillator. The system clock SYSCLK is equal to 18432000. T0 is timed 1 ms. During initialization, TH0 = (-SYSCLK/1000) > 8; TL0 = -SYSCLK/1000. After waiting for 1 second, the number of speed pulses N is output, and the motor speed value is calculated. The speed value within 1 second is converted into the motor speed value within 1 minute, and the measurement result is output on the LED. 2.2 Software Design This system uses the INT0 interrupt in C8051F060 to count the speed pulses. Timer T1 works in external event counting mode to count the speed pulses; T0 works in timer mode, both working in mode 1. The count value is read once every 1 second. This value is the frequency of the pulse signal. The motor speed can be calculated according to formula (1). Since the speed of a DC motor is related to the voltage applied across the motor, the actual measured speed value is compared with the preset speed value. If it is greater than the preset speed value, the value of DAC0 is decreased; if it is less than the preset speed value, the value of DAC0 is increased to adjust the motor speed until the speed value equals the preset value. This achieves the control of the motor speed. The main program and T0 interrupt flowchart are shown in Figures 2 and 3. 3 Experimental Test Results First, the preset speed value is given in the software, that is, the value of the constant speed is given. The value of the seven-segment digital tube is observed after the speed stabilizes. The actual measured speed value and the preset speed value are compared, the measurement error is calculated, and the accuracy of the measurement is evaluated. The test results are shown in Table 1. The measurement error curve is plotted based on the experimental test and error analysis, as shown in Figure 4. Error analysis shows that the speed measurement error is within 5%, and the measurement error decreases exponentially with the increase of the preset speed value. The functional relationship is shown in Equation (3). 4 Conclusion This speed measurement system uses an integrated Hall sensor to sense the speed signal, which has the characteristics of fast frequency response and strong anti-interference ability. The output signal of the Hall sensor, after signal conditioning, is used by a microcontroller to count continuous pulses to achieve speed measurement and control. This method fully utilizes the microcontroller's internal resources, offering high cost-effectiveness. Testing and error analysis revealed that the system's measurement error is within 5%, and the measurement accuracy increases with the higher the speed within the measurement range. Therefore, this system can be applied to general speed detection and control applications.