Utility model content
The purpose of this utility model is to provide a kind of STM32 to control multi-path stepping motor synchronous operation
Control system and control method, to solve Synchronization Control motor in prior art, there are the following problems:
1. although use the chips such as FPGA or CPLD accurately multichannel motor to be controlled simultaneously, but
It is with high costs.
2. to use chip microcontroller Synchronization Control N+1 the to be used block single-chip microcomputer to N number of motor,
Waste very much mcu resource.
The technical solution of the utility model is as follows:
A kind of STM32 controls the control system of multi-path stepping motor synchronous operation, wherein, including a STM32
Single-chip microcomputer, stepper motor driver and multi-path stepping motor, described STM32 single-chip microcomputer and described stepping
Motor driver connects, stepper motor driver drive stepping motor, Single-chip Controlling multichannel stepping electricity
Machine runs simultaneously.
Described STM32 controls the control system of multi-path stepping motor synchronous operation, wherein, described often
One tunnel stepper motor arrangement has one for the position sensor resetted.
Described STM32 controls the control system of multi-path stepping motor synchronous operation, wherein, described STM32
Single-chip microcomputer include least one set for recommending the GPIO of output, GPIO connects described stepper motor driver,
Drive level signal exports on multi-path stepping motor after comparing amplification.
Described STM32 controls the control system of multi-path stepping motor synchronous operation, wherein, described STM32
Single-chip microcomputer also includes that external interrupt, described external interrupt are configured to pull-up input and described position sensing
Device connects, and is used for receiving reset motor signal.
Described STM32 controls the control system of multi-path stepping motor synchronous operation, wherein, described STM32
Single-chip microcomputer also includes intervalometer, and described intervalometer, for producing the clock signal of a certain frequency, controls electricity
The step number of machine operation and the speed of operation.
Described STM32 controls the control system of multi-path stepping motor synchronous operation, wherein, described STM32
Single-chip microcomputer also includes the RS232 serial ports of one and extraneous communication.
The beneficial effects of the utility model: this utility model utilizes the timer resource of single-chip microcomputer to simulate
CLK clock signal in FPGA, is approximated to one the code execution time in timer interruption function
Moment point (relative to the motor of low speed), simulates the executed in parallel effect of FPGA, to multichannel
Motor carries out Synchronization Control, controls flexibly, low cost.
Detailed description of the invention
For making the purpose of this utility model, technical scheme and advantage clearer, clear and definite, referring to
Accompanying drawing develops simultaneously embodiment to this utility model further description.
Refering to Fig. 1, this utility model provides a kind of STM32 to control the control of multi-path stepping motor synchronous operation
System processed, wherein, including a STM32 single-chip microcomputer 1, stepper motor driver 2 and multi-path stepping motor
3, described STM32 single-chip microcomputer 1 and described stepper motor driver 2 connect, and stepper motor driver drives
Dynamic motor 3, Single-chip Controlling multi-path stepping motor 3 runs simultaneously.
Further, described each road motor 3 is configured with one for the position sensor resetted
31.In this utility model, motor is used for photographing unit or the camera lens of other imaging devices, fuselage
Auto-focusing, electronic zoom, position sensor 31 is for accurately detecting the accurate position of motor 3
Put so that motor 3 accurately resets.
Further, described STM32 single-chip microcomputer 1 includes some GPIO 11, GPIO for recommending output
11 connect described stepper motor driver 2, and drive level signal exports multichannel after comparing amplification and walks
Enter on motor 3.
Further, described STM32 single-chip microcomputer also includes that external interrupt 12, described external interrupt 12 are joined
It is set to pull-up input and connects with described position sensor 31, for receiving the reset letter of motor 3
Number.
Further, described STM32 single-chip microcomputer 1 also includes that intervalometer 13, described intervalometer 13 are used for
Control the step number that motor runs.Motor 3 receives a pulse, needs time delay about 250
Microsecond could be run, if the pulse frequency that motor 3 receives is too fast, can cause motor 3
Can not start.In the present embodiment, intervalometer 13 frequency setting is 40K, and timer interruption function is every
Will be called once every 25 microseconds.
Further, described STM32 single-chip microcomputer 1 also includes the RS232 serial ports of and extraneous communication
14。
Singlechip main program flow chart refering to Fig. 2, Fig. 2, single-chip microcomputer start after powering on to serial ports, GPIO,
Intervalometer and external interrupt initialize.Initialization complete after reset motor 3, if stepping
Motor 3 is not detected by position sensor 31 program and will halt and point out error message, otherwise journey
Sequence enters into a major cycle.In this circulation, program disappearing in 5 milliseconds of acquisition message queues
Breath, if message queue is empty, there is no order, then continues after waiting 5 milliseconds to obtain;If obtained
The message got is not for sky, the then corresponding order of execution.If order runs succeeded, wait 5 milliseconds
After continue to repeat to operate as above;If order performs failure, again attempt to perform, if the attempt to 3 times
After all failed, abandon this order and point out error message.
Fig. 3 is serial ports interrupt function flow chart, and serial ports 14 has initialized rear serial ports interrupt function and just may be used
Response external event.After serial ports 14 receives order, first order is resolved by interrupt function, resolves
After order be stored in message queue notice principal function read, then branch in principal function.
Refering to Fig. 4, the control work of this utility model STM32 Single-chip Controlling multichannel motor synchronous operation
Flow process is as follows:
Step a: single-chip microcomputer principal function actuating motor initialization function, initializes motor,
According to specifically being used for setting the frequency of intervalometer, in the present embodiment, due to motor operation
Altofrequency is 4K, and therefore arranging timer frequency is 40K, leaves regulation remaining of power supply machine acceleration and deceleration
Ground;
Step b: according to user's request, the motor calling user's request runs function, will corresponding electricity
The operational factor of machine is delivered in timer interruption function by global variable, arranges in interrupt function
The parameters such as the corresponding switch of motor, motor speed;
Step c: be called if there being motor to run function, then trigger timer interruption function, perform step
D operates, and otherwise performs the operation of step m.
Step d: if first via motor function calls, performs the operation of step e, otherwise performs
I operates.
Step e: in intervalometer, opens the switch of corresponding motor, further according to the speed ginseng of corresponding motor
Numerical value arranges the timer clock number needing to wait;
Step f: in the case of not being triggered to level sensor, performs the operation of step g;Otherwise redirect
Operation is performed to step h.
Step g: motor elder generation Accelerating running, starts to travel at the uniform speed after reaching the speed specified, last pre-
Do retarded motion in the step number of meter, finally stop on predetermined position, then jump to step i and hold
Row operation.
Step h: after decelerating through motor to user preset value, the more certain step number of inverted running.
Step i: program enters the execution function entrance of next motor.
Step j: if No. second motor function calls, performs the operation of step e-h;Otherwise perform step
Rapid i operation.
Step k: if No. threeth motor function calls, performs the operation of step e-h;Otherwise perform step
Rapid i operation.
Step l: until last N road motor function is called, process repeats steps e-h operates;No
Then perform the operation of step m.
Step m: exit timer interruption function, returns mastery routine and performs.
Although substantially single-chip microcomputer is the most proper sends the pulse to multi-path stepping motor 3 simultaneously,
But according to sequencing, each road motor 3 sent pulse, but owing to single-chip microcomputer performs a finger
Making a few to tens of nanoseconds of time about ten, relative to the motor of low cruise, (interpulse time delay is extremely
Need 250 microseconds less) for, all codes in whole interrupt function are it is believed that at synchronization
Complete, add interrupt function and perform once every 25 microseconds, it is possible to equivalence becomes FPGA's
Parallel effect.When this utility model utilizes the CLK in the timer resource simulation FPGA of single-chip microcomputer to synchronize
Clock signal, in timer interruption function code perform the time be approximated to a moment point (relative to
The motor of low speed), simulate the executed in parallel effect of FPGA, carry out multichannel motor synchronizing control
System, controls flexibly, low cost.
Certainly, the control system of this utility model control multi-path stepping motor synchronous operation is not only applied
In STM32 single-chip microcomputer, this utility model can be applied equally to the single-chip microcomputer of other models.
It should be appreciated that application of the present utility model is not limited to above-mentioned citing, common to this area
For technical staff, can be improved according to the above description or be converted, all these modifications and variations
All should belong to the protection domain of this utility model claims.