Design of a camera motion control system based on a microcontroller
2026-04-06 06:00:13··#1
Abstract: This paper constructs a pan-tilt controller based on the AT89S52 microcontroller. External control information input and stepper motor speed display are achieved through an 8279 keyboard and display interface chip, controlling the camera to move in the up, down, left, and right directions. To ensure control reliability, the stepper motor control signals are not generated by the microcontroller but by a dedicated stepper motor driver module. Keywords: Microcontroller; Pan/Tilt Controller; Stepper Motor; Speed; Keyboard Abstract: This paper designs a YunTan controller based on the AT89S52 SCM. The function of inputting external control signals and displaying step-motor speed is realized by the 8279 keyboard/display chip, in order to control the movement of the vidicon toward the up, down, left, and right directions. To ensure the reliability of control, the production of step-motor control signals is achieved by a special driving module for the step-motor, not by the SCM. Keywords: SCM; YunTan Controller; Step-motor; Speed; Keyboard 0 Introduction A pan/tilt controller designed with a microcontroller as its core can control cameras to move over a wide range and at a wide angle in monitoring applications, enabling the camera to achieve near 360° panoramic imaging. It also has unique advantages in terms of economy, flexibility, expandability, and maintainability. 1. System Overall Structure The system consists of the following parts: ① Microcontroller: The core of the design, which, with the cooperation of software, recognizes the information input from the keyboard and sends commands to the stepper motor in the pan-tilt unit to achieve functions such as forward/reverse rotation, speed control, and program control. The stepper motor speed is displayed on a digital tube. ② Stepper Motor and Driver: Responsible for the vertical and horizontal rotation of the pan-tilt system, it is the system's execution component. ③ Keyboard: An external information input device, an important component for operators to control the pan-tilt system. ④ Display Device: Displays the real-time speed of the stepper motor, allowing operators to determine the control strategy for the pan-tilt unit based on the speed. 2. System Hardware Design The hardware circuit is divided into three parts according to system function: the stepper motor and its driver module, the microcontroller and its peripheral circuits, and the keyboard and display circuit. The system hardware functional block diagram is shown in Figure 1. 2.1 Selection of Stepper Motor Control and Driver Module After receiving a pulse signal, the driver drives the stepper motor to rotate a fixed angle in a set direction. Its rotation is a step-by-step movement at fixed angles. The angular displacement can be controlled by controlling the number of pulses to achieve accurate positioning; simultaneously, the speed and acceleration of the motor can be controlled by controlling the pulse frequency to achieve speed regulation. The selected stepper motors are two hybrid stepper motors (57BYG250C), capable of two-phase/four-phase operation, with a step angle of 1.8° in four-phase operation and 0.9° in eight-phase operation. The stepper motor driver module is model HB202A, featuring 4/8-phase conversion control signals, free control signals, and input signal opto-isolation. A free control button is added to the design, allowing both motors to be put into offline mode during faults or debugging, enabling manual adjustment of the stepper motors. The free control button is directly connected to the microcontroller's INT0 pin, with INT0 set as the highest priority for rapid offline control in case of faults. Since it connects directly to the microcontroller without going through the 8279, a keyboard debouncing circuit must be implemented to prevent erroneous operation by the microcontroller. 2.2 Keyboard and Display Circuit Design The keyboard and display circuit is implemented using the Intel 8279. The keyboard uses an N-key cycle mode, and the display is 8 bits with the left end input. The 8279 connects to a 2*8 keyboard and an 8-bit display, using an encoded scanning method. The IRQ of the 8279 is connected to the INT1 of the microcontroller; an interrupt is requested whenever a key is pressed. When the microcontroller is connected to a 12MHz crystal oscillator, ALE is 2MHz, and since it is connected to CLK, its frequency division command word is 34H. A total of 16 keys are extended through the 8279: 8 keys control the forward and reverse rotation of the stepper motors in both directions, and 8 are function keys, responsible for stepper motor acceleration/deceleration, program control, and stepper motor limit switches, respectively. 3 System Software Design The system software mainly consists of an initialization program, a keyboard program, a speed control program, and a speed detection and display program. Except for the initialization program, all other programs use interrupt-driven operation, improving CPU utilization. 3.1 System Initialization Program Design First, the microcontroller's interrupt sources are initialized, using five interrupt sources: INT0, INT1, T0, T1, and T2. INT0, T0, and T1 have high priority, while INT1 and T2 have low priority. When INT0 requests an interrupt, the program immediately puts the stepper motor into offline control mode. The stepper motor is no longer controlled by the microcontroller and is level-triggered. The microcontroller continuously executes the offline program until the external trigger signal is manually canceled by the operator, at which point the system returns to normal operation. Then, the operating modes of T0, T1, and T2 are set, and counter handling is written. The enable bits for these interrupt sources are enabled, thus enabling CPU interrupts. 3.2 Keyboard Program Design When a key is pressed, an interrupt request is generated. After responding to the interrupt, the microcontroller begins executing the interrupt program. The generated key value is read from the 8279 internally, and the corresponding program is executed based on the key value. The CPU receives this information but does not act immediately. To ensure the stability of stepper motor speed control, the command corresponding to the key value is first saved. After T0/T1 reaches the set count value, when a pulse needs to be output at a certain speed, this information is sent to the stepper motor. 3.3 Stepper Motor Speed Control Software Design The speed of the stepper motor is changed by altering the frequency of the CP signal in the drive module. Changing the frequency of the CP signal can be achieved using a timer/counter. First, the timer/counter is initialized, then it starts running. After the specified time, an interrupt routine is executed. At this time, the program that generates the CP signal can be placed in this interrupt routine, thus achieving the purpose of changing the stepper motor speed. T0 and T1 inside the S52 correspond to the speed control of two stepper motors respectively, and their working process is shown in Figure 2. 3.4 Speed Detection and Display Software Design A timer counting method is used to count the stepping pulses sent by the microcontroller to the stepper motor within a certain time period. Let the microcontroller detect the number N pulses sent to the stepper motor every 50ms. The relationship between N and the rotational speed is as follows: Multiplying the detected pulse count N by 3 gives the rotational speed per minute. The 50ms timing is achieved by the third timer/counter T2 within the S52 microcontroller. 4. Conclusion Microcontroller-based gimbal controllers not only feature high control precision, flexible control methods, simple programming, low power consumption, and high reliability, but some newer microcontrollers also have in-circuit programming capabilities. This allows for program updates without removing the microcontroller from the operating environment, facilitating software maintenance. Furthermore, pre-programmed programs can automatically coordinate the control of the drive motors in both directions as needed. References [1] Chen Libi. Stepper Motor and Its Application [M]. Shanghai: Shanghai Science and Technology Press, 1989. [2] Liu Baoyan. Stepper Motor and Its Drive Control System [M]. Harbin: Harbin Institute of Technology Press, 1997. [3] Xue Yongyi, Wang Shuying, He Xicai. Application Examples of New Power Supply Circuits [M]. Beijing: Electronic Industry Press, 2003. [4] Liu Fuqiang. Development and Application of Digital Video Surveillance System [M]. Beijing: Machinery Industry Press, 2003. [5] Zhang Yingxin. Principles, Applications and Interface Technology of Single-Chip Microcomputer [M]. Beijing