Method, device and system for controlling motor

文档序号:1641225 发布日期:2019-12-20 浏览:29次 中文

阅读说明:本技术 一种控制电机的方法、装置和系统 (Method, device and system for controlling motor ) 是由 王智玮 王聪 李龙剑 杨庆庆 于 2019-08-13 设计创作,主要内容包括:本发明提供一种控制电机的方法和系统,涉及电子领域。所述方法包括:获得MCU存储的预设脉冲数值,对旋转编码器产生的脉冲数值进行计数,并比较当前计数的脉冲数值和预设脉冲数值是否相等,在当前计数的脉冲数值和预设脉冲数值相等的情况下,同时获得MCU存储的下一预设脉冲值,其中,中断信号用于使MCU对电机进行换相操作。本发明的控制电机的方法和系统,在使用过程中,不用改变已有的电路结构和各个设备自身的结构,简单方便、精确度高,并且可以根据旋转编码器的具体性能,适应性的进行调整,整个方法清晰简洁,可操作性强,适用范围较广。(The invention provides a method and a system for controlling a motor, and relates to the field of electronics. The method comprises the following steps: and obtaining a preset pulse value stored by the MCU, counting the pulse value generated by the rotary encoder, comparing whether the currently counted pulse value is equal to the preset pulse value, and obtaining a next preset pulse value stored by the MCU under the condition that the currently counted pulse value is equal to the preset pulse value, wherein an interrupt signal is used for enabling the MCU to carry out phase change operation on the motor. The method and the system for controlling the motor do not need to change the existing circuit structure and the structure of each device in the using process, are simple, convenient and high in accuracy, can be adjusted adaptively according to the specific performance of the rotary encoder, and have the advantages of clear and concise whole method, strong operability and wider application range.)

1. A method of controlling an electric motor, the method being applied to a counter in an MCU, the counter being connected to a rotary encoder, the method comprising:

acquiring a preset pulse value stored by the MCU, wherein the preset pulse value is a pulse value corresponding to a phase change point of the motor;

counting the pulse values generated by the rotary encoder, and comparing whether the currently counted pulse values are equal to the preset pulse values or not;

and sending an interrupt signal to the MCU under the condition that the currently counted pulse numerical value is equal to the preset pulse value, and simultaneously obtaining the next preset pulse value stored by the MCU, wherein the interrupt signal is used for enabling the MCU to carry out phase change operation on the motor.

2. The method of claim 1, wherein the counter comprises an input capture channel; before obtaining the preset pulse value stored by the MCU, the method further comprises the following steps:

capturing a first null pulse emitted by the rotary encoder through the input capture channel;

when the first zero pulse is captured through the input capture channel, clearing a count value of a pulse value generated by the rotary encoder, and setting the current position of the rotary encoder as the zero position of the rotary encoder;

and when the MCU is used for electrifying each phase of the motor through the driving circuit, counting pulse values generated in the process that the rotary encoder changes from a rotating state to a stopping state by taking the zero-degree position as an initial position to obtain the pulse values of the phase change points of the motor.

3. The method of claim 1, wherein the number of the preset pulse number values is plural; the counter further comprises: the pulse counting channel is used for counting pulse values generated by the rotary encoder, and the comparison register is used for storing preset pulse values stored by the obtained MCU; after sending an interrupt signal to the MCU, the method further comprises:

and triggering direct memory access through the pulse counting channel to obtain a next preset pulse value stored by the MCU, and storing the next preset pulse value in the comparison register.

4. The method according to claim 1, wherein the rotary encoder corresponding to the preset pulse value takes the zero degree position as a starting position, and a pulse value generated in a process of changing from a rotating state to a stopping state is a phase change point of the motor.

5. A device for controlling an electric motor, said device being applied to a counter in an MCU, said counter being connected to a rotary encoder, said device comprising:

the acquisition module is used for acquiring a preset pulse numerical value stored by the MCU, wherein the preset pulse numerical value is a pulse numerical value corresponding to the motor phase change point;

the counting comparison module is used for counting the pulse values generated by the rotary encoder and comparing whether the currently counted pulse values are equal to the preset pulse values or not;

and the sending interruption obtaining module is used for sending an interruption signal to the MCU and simultaneously obtaining the next preset pulse value stored by the MCU under the condition that the currently counted pulse value is equal to the preset pulse value, wherein the interruption signal is used for enabling the MCU to carry out phase change operation on the motor.

6. The apparatus of claim 5, wherein the counter comprises an input capture channel; the device further comprises:

the capture module is used for capturing a first zero pulse emitted by the rotary encoder through the input capture channel;

the zero clearing module is used for clearing a count value of a pulse value generated by the rotary encoder when the first zero pulse is captured through the input capture channel and setting the current position of the rotary encoder as the zero position of the rotary encoder;

and the phase change point pulse value determining module is used for counting pulse values generated in the process that the rotary encoder changes from a rotating state to a stopping state by taking the zero-degree position as an initial position when the MCU energizes each phase of the motor through the driving circuit so as to obtain the pulse values of the phase change points of the motor.

7. The apparatus of claim 5, wherein the number of the preset pulse number values is plural; the counter further comprises: the pulse counting channel is used for counting pulse values generated by the rotary encoder, and the comparison register is used for storing preset pulse values stored by the obtained MCU; the device further comprises:

and the trigger obtaining module is used for triggering the direct memory access through the pulse counting channel, obtaining the next preset pulse value stored by the MCU and storing the next preset pulse value in the comparison register.

8. A system for controlling an electric machine, the system comprising: MCU, rotary encoder and motor, MCU includes: a counter, said rotary encoder being connected to said MCU and said motor respectively, said counter being adapted to perform the method of any of claims 1-4.

Technical Field

The invention relates to the field of electronics, in particular to a method, a device and a system for controlling a motor.

Background

The brushless direct current motor is composed of a motor main body and a driver, and is a typical electromechanical integration product. The brushless motor is a motor without a brush and a commutator (or a collecting ring), which is also called a commutator-free motor, and when the motor is produced in nineteenth ages, the produced practical motor is in a brushless form, namely an alternating current squirrel cage type asynchronous motor, and the motor is widely applied. However, asynchronous motors have a number of insurmountable drawbacks, which have led to slow motor technology development. The transistor is produced in the middle of the last century, so that a direct current brushless motor adopting a transistor commutation circuit to replace an electric brush and a commutator is produced, the novel brushless motor is called an electronic commutation type direct current motor, and the defects of the first generation brushless motor are overcome.

At present, a brushless direct current motor widely applied is a three-phase brushless direct current motor, the rotating speed and the steering of the three-phase brushless direct current motor are controlled to generally detect the position of a motor rotor, a Hall sensor or a rotary encoder is used for detecting the position of the rotor in the prior art, advantages and disadvantages exist between the Hall sensor and the rotary encoder, and the specific device used for detecting the position of the rotor can be specifically determined according to the use requirement.

At present, incremental rotary encoders are used for detecting the positions of motor rotors, one of the problems is that pulse signals generated by one rotation circle of the incremental rotary encoders are many, and along with the increase of running time in the running process of the motors, the number of the pulse signals generated by the incremental rotary encoders is huge, so that the data processing number of control equipment (such as an MCU) is huge, the working efficiency of the control equipment is very low, the control equipment can not accurately control the motor phase change seriously, the normal running of the motor is influenced, and the user loss is caused.

Disclosure of Invention

In view of the above, the present invention provides a method and system for controlling a motor that greatly reduces the amount of data that needs to be processed by the control device.

The embodiment of the invention provides a method for controlling a motor, which is applied to a counter in an MCU (microprogrammed control Unit), wherein the counter is connected with a rotary encoder, and the method comprises the following steps:

acquiring a preset pulse value stored by the MCU, wherein the preset pulse value is a pulse value corresponding to a phase change point of the motor;

counting the pulse values generated by the rotary encoder, and comparing whether the currently counted pulse values are equal to the preset pulse values or not;

and sending an interrupt signal to the MCU under the condition that the currently counted pulse numerical value is equal to the preset pulse value, and simultaneously obtaining the next preset pulse value stored by the MCU, wherein the interrupt signal is used for enabling the MCU to carry out phase change operation on the motor.

Optionally, the counter comprises an input capture channel; before obtaining the preset pulse value stored by the MCU, the method further comprises the following steps:

capturing a first null pulse emitted by the rotary encoder through the input capture channel;

when the first zero pulse is captured through the input capture channel, clearing a count value of a pulse value generated by the rotary encoder, and setting the current position of the rotary encoder as the zero position of the rotary encoder;

and when the MCU is used for electrifying each phase of the motor through the driving circuit, counting pulse values generated in the process that the rotary encoder changes from a rotating state to a stopping state by taking the zero-degree position as an initial position to obtain the pulse values of the phase change points of the motor.

Optionally, the number of the preset pulse values is multiple; the counter further comprises: the pulse counting channel is used for counting pulse values generated by the rotary encoder, and the comparison register is used for storing preset pulse values stored by the obtained MCU; after sending an interrupt signal to the MCU, the method further comprises:

and triggering direct memory access through the pulse counting channel to obtain a next preset pulse value stored by the MCU, and storing the next preset pulse value in the comparison register.

Optionally, the rotary encoder corresponding to the preset pulse value takes the zero-degree position as a start position, and a pulse value generated in a process of changing from a rotating state to a stopping state is a phase change point of the motor.

The embodiment of the invention also provides a device for controlling the motor, which is applied to a counter in the MCU, wherein the counter is connected with the rotary encoder, and the device comprises:

the acquisition module is used for acquiring a preset pulse numerical value stored by the MCU, wherein the preset pulse numerical value is a pulse numerical value corresponding to the motor phase change point;

the counting comparison module is used for counting the pulse values generated by the rotary encoder and comparing whether the currently counted pulse values are equal to the preset pulse values or not;

and the sending interruption obtaining module is used for sending an interruption signal to the MCU and simultaneously obtaining the next preset pulse value stored by the MCU under the condition that the currently counted pulse value is equal to the preset pulse value, wherein the interruption signal is used for enabling the MCU to carry out phase change operation on the motor.

Optionally, the counter comprises an input capture channel; the device further comprises:

the capture module is used for capturing a first zero pulse emitted by the rotary encoder through the input capture channel;

the zero clearing module is used for clearing a count value of a pulse value generated by the rotary encoder when the first zero pulse is captured through the input capture channel and setting the current position of the rotary encoder as the zero position of the rotary encoder;

and the phase change point pulse value determining module is used for counting pulse values generated in the process that the rotary encoder changes from a rotating state to a stopping state by taking the zero-degree position as an initial position when the MCU energizes each phase of the motor through the driving circuit so as to obtain the pulse values of the phase change points of the motor.

Optionally, the number of the preset pulse values is multiple; the counter further comprises: the pulse counting channel is used for counting pulse values generated by the rotary encoder, and the comparison register is used for storing preset pulse values stored by the obtained MCU; the device further comprises:

and the trigger obtaining module is used for triggering the direct memory access through the pulse counting channel, obtaining the next preset pulse value stored by the MCU and storing the next preset pulse value in the comparison register.

An embodiment of the present invention further provides a system for controlling a motor, where the system includes: MCU, rotary encoder and motor, MCU includes: and the rotary encoder is respectively connected with the MCU and the motor, and the counter is used for executing any one of the methods.

Compared with the prior art, the method for controlling the motor, provided by the invention, comprises the steps of obtaining the preset pulse numerical value stored by the MCU, counting the pulse numerical value generated by the rotary encoder, comparing whether the currently counted pulse numerical value is equal to the preset pulse numerical value or not, sending an interrupt signal to the MCU under the condition that the currently counted pulse numerical value is equal to the preset pulse numerical value, so that the MCU carries out phase change operation on the motor, and obtaining the next preset pulse numerical value stored by the MCU while sending the interrupt signal to the MCU. The method does not need to change the existing circuit structure and the structure of each device, is simple and convenient, has high accuracy, can be adjusted adaptively according to the specific performance of the rotary encoder, and has clear and concise whole method, strong operability and wider application range.

Drawings

Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:

FIG. 1 is a flow chart of a method of controlling a motor in accordance with an embodiment of the present invention;

FIG. 2 is a schematic view of a rotary encoder and counter according to an embodiment of the present invention;

fig. 3 is a block diagram of an apparatus for controlling a motor according to an embodiment of the present invention.

Detailed Description

In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below. It should be understood that the specific embodiments described herein are merely illustrative of the invention, but do not limit the invention to only some, but not all embodiments.

The inventor finds that the incremental rotary encoder mainly has the following 3 technical problems when detecting the rotor position of the direct current brushless motor at present:

1. the signals generated by a typical incremental rotary encoder are only incremental in position, for example: after the motor is started, the motor rotates clockwise by 10 degrees to a position of 90 degrees, but the incremental rotary encoder can only detect that the motor rotor rotates by 10 degrees and does not know the current absolute position of the motor rotor, and the absolute position of the motor rotor must be known to determine the position of the motor rotor.

2. The general incremental rotary encoder is arranged outside the motor, the corresponding relation between the position of the rotor of the motor and the position of the phase change point of the motor obtained by the encoder is not clear, and the phase change of the motor is not known when the rotor rotates to some degrees.

3. The precision of the incremental rotary encoder is high, which divides 360 ° into thousands of parts, but this also results in thousands of pulse signals generated by the incremental rotary encoder per rotation of the motor, and the number of pulse signals is extremely huge after the motor is operated, which naturally causes great pressure to the operation of the control device.

Based on the above problems, the inventor of the present invention has made extensive research, combined with the characteristics of the MCU, and through a large number of field tests and simulation calculations, creatively proposed the method for controlling the motor of the present invention, in which the counter is used to complete the processing of the pulse signal, and the MCU only needs to execute the motor commutation, thereby solving the above problems. The solution proposed by the inventors is explained and illustrated in detail below.

Referring to fig. 1, a flowchart of a method of controlling a motor according to an embodiment of the present invention is shown, the method including:

step 101: and acquiring a preset pulse value stored by the MCU, wherein the preset pulse value is a pulse value corresponding to a motor phase change point.

In the embodiment of the present invention, referring to fig. 2, a schematic diagram of a rotary encoder and a counter according to the embodiment of the present invention is shown, where the counter is a module in an MCU, and is embedded in the MCU, and the counter has three channels, two of which are pulse counting channels, and are respectively connected to an output a phase and an output B phase of the rotary encoder, and the other is an input capture channel, and is connected to an output Z of the rotary encoder; the pulse counting channel is used for counting the pulse values of the A phase and the B phase output by the rotary encoder; the input capture channel is used for capturing zero pulses emitted by the output Z phase of the rotary encoder. The counter also has a compare register for holding a predetermined pulse value.

The MCU is stored with a preset pulse value, and the preset pulse value is a pulse value which is determined by the rotary encoder and corresponds to a motor phase change point. Before the motor is formally operated, the MCU writes a preset pulse value corresponding to the first commutation point into a comparison register of a counter according to the required steering of the motor, the counter has a channel comparison function, and the channel comparison function is as follows: and the function of comparing the value in the pulse counting channel in the counter with the value in the comparison register.

As an example: assume that the MCU chip used is: the GD32F303RCT6 comprises a counter, an incremental rotary encoder is rigidly connected with a motor rotor, 3600 pulse signals are generated by one rotation of the incremental rotary encoder, the corresponding motor rotor angle is 360 degrees, namely the rotating angle of the rotary encoder corresponding to each 10 pulse signals is 1 degree of the motor rotor angle, the preset pulse values are 300, 1500 and 2700, if the motor needs to rotate forwards, the MCU writes the first preset pulse value 300 into a comparison register of the counter before the motor is formally operated.

Optionally, before obtaining the preset pulse value stored by the MCU, it is first required to determine the preset pulse value, that is, it is required to determine how many degrees the rotary encoder rotates to reach the phase change point of the motor with the zero-degree position as the standard, that is, how many pulse values the rotary encoder generates with the zero-degree position as the standard reach the phase change point of the motor. The method for determining the zero-degree position and the preset pulse value comprises the following steps:

step S1: capturing a first zero pulse emitted by a rotary encoder through an input capturing channel;

in the embodiment of the invention, the zero position of the rotary encoder needs to be determined firstly, and the driving motor is rotated in a time-delay reversing mode until the first zero pulse signal on the Z phase of the rotary encoder is captured through the input capturing channel.

Step S2: when capturing a first zero pulse through an input capturing channel, clearing a count value of a pulse value generated by a rotary encoder, and setting the current position of the rotary encoder as a zero position of the rotary encoder;

in the embodiment of the invention, when the first zero pulse signal on the Z phase of the rotary encoder is captured through the input capture channel, the counter clears the count value of the pulse counting channel at the moment, and sets the current position as the zero position of the rotary encoder: 0 degrees, so that 0 degrees of the rotary encoder corresponds to 0 degrees of the counting value of the pulse counting channel, each pulse signal of the rotary encoder counts once, 3600 pulses can be generated by the rotary encoder per 360 degrees of rotation, namely, the counting value 10 corresponds to 1 degree of the rotary encoder. The zero-degree position of the rotary encoder is accurately positioned by adopting the method.

Step S3: when the MCU energizes each phase of the motor through the driving circuit, the rotary encoder counts pulse values generated in the process of changing from a rotating state to a stopping state by taking a zero-degree position as an initial position, and pulse values of phase change points of the motor are obtained.

In the embodiment of the invention, after the zero-degree position is determined, a pulse numerical value corresponding to a motor commutation point needs to be determined, namely a preset pulse numerical value, firstly, the MCU conducts long-time electrification on the AB phase of the motor through the driving circuit, a rotor of the motor is forced to stop at the position of the commutation point, then the MCU reads the pulse numerical value generated by the rotary encoder corresponding to the rotated angle when the rotary encoder rotates to the stop position by taking the zero-degree position as the initial position, the absolute position of the motor commutation point can be obtained, if the rotated angle of the rotary encoder relative to the zero-degree position is 10 degrees, the correspondingly generated pulse numerical value is 100, the first preset pulse numerical value is obtained, then, the BC phase is obtained in the same mode, and the CA phase is obtained in the same mode, and the third preset pulse numerical value is 2500. After all the preset pulse values are obtained, the preset pulse values are stored in the MCU. The method is adopted to accurately position the pulse numerical value of the rotary encoder corresponding to the phase change point of the motor.

Step 102: and counting the pulse values generated by the rotary encoder, and comparing whether the currently counted pulse values are equal to the preset pulse values.

In the embodiment of the invention, after the motor is started to operate formally, the counter counts the pulse value generated by the rotary encoder through the pulse counting channel. When the motor runs, each phase of the motor is sequentially electrified, the rotary encoder is driven to rotate through the motor rotor, the motor rotor is in rigid connection, the rotating angle of the motor rotor is the same as the rotating angle of the rotary encoder, in the rotating process of the rotary encoder, when the output phase A is the same as the output phase B, a pulse signal is generated, the phase difference between the output phase A and the output phase B is 90 degrees, and the pulse counting channel counts the pulse signals generated when the phase A is the same as the output phase B to obtain a pulse value. When the pulse counting channel of the counter counts, the current pulse value in the pulse counting channel is compared with the preset pulse value in the comparison register through a channel comparison function, and whether the current pulse value and the preset pulse value are equal is compared.

Following the above example: the output A phase and B phase of the incremental rotary encoder are respectively connected with a pulse counting channel, and if the incremental rotary encoder rotates by 1 degree, the output A phase and B phase of the incremental rotary encoder generate 10 pulse signals, and the pulse counting channel counts the 10 pulse signals to obtain a pulse value: 10. along with the motor rotation, the pulse counting channel can carry out real-time counting on the pulse signals generated by the rotary encoder to obtain a pulse value, if the pulse value is 100, the preset pulse value in the comparison register is 300, the channel comparison function of the counter compares the two values in real time, and along with the rotation of the rotary encoder, the pulse value of the pulse signals is increased until the currently counted pulse value is equal to the preset pulse value 300.

Step 103: and under the condition that the currently counted pulse value is equal to the preset pulse value, sending an interrupt signal to the MCU, and simultaneously obtaining the next preset pulse value stored by the MCU, wherein the interrupt signal is used for enabling the MCU to carry out phase change operation on the motor.

In the embodiment of the invention, under the condition that the currently counted pulse value of the pulse counting channel is equal to the preset pulse value, the counter sends an interrupt signal to the MCU, the MCU receives the interrupt signal and interrupts all operations, and the MCU controls the driving circuit to electrify the next phase of the motor according to the phase sequence required by the rotation direction of the motor, so that the motor is phase-changed and the motor continues to run. And when the counter sends an interrupt signal to the MCU, the counter triggers a Direct Memory Access (DMA) technology to obtain the next preset pulse value from the MCU by the DMA, and the next preset pulse value is stored in a comparison register.

Following the above example: assuming that the motor is a single-stage motor and rotates forwards, when the motor operates, the AB phase of the motor is firstly electrified, when the real-time counting value of a pulse signal generated by a pulse counting channel to a rotary encoder reaches 300, the counting channel is equal to the preset pulse value of 300, a counter sends an interrupt signal to an MCU (microprogrammed control unit), the MCU controls a driving circuit to electrify a motor BC according to the forward rotation electrifying phase sequence of the motor, and then the motor continues to rotate and operate. When the counter sends an interrupt signal to the MCU, the counter triggers the DMA to obtain the next preset pulse value from the MCU: 1500 and save 1500 in the compare register.

In summary, assuming that the motor is a single-stage motor and needs to be rotated reversely, 1800 pulse signals are generated by the rotary encoder during one rotation, the zero position of the rotary encoder needs to be determined first, the driving motor is rotated in a "delayed commutation" manner until a zero pulse signal is detected to be generated on the Z phase of the rotary encoder, at this time, the count value of the pulse counting channel in the counter is cleared, and the current position is set as the zero position of the rotary encoder: 0 ° so that 0 ° of the rotary encoder corresponds to 0 ° of the count value of the pulse count channel, each pulse signal of the rotary encoder counts once, 1800 pulses are generated per 360 ° revolution of the rotary encoder, i.e., the count value 50 corresponds to 1 ° of the rotary encoder.

After the zero-degree position of the rotary encoder is determined, a pulse numerical value corresponding to a motor commutation point is determined, namely a preset pulse numerical value, firstly, the MCU conducts long-time electrification on the AB phase of the motor through the driving circuit, the rotor of the motor is forced to stop at the position of the commutation point, then, the pulse numerical value correspondingly generated by the current rotary encoder relative to the angle rotated by the zero-degree position is read, the absolute position of the motor commutation point can be obtained, if the angle rotated by the rotary encoder relative to the zero-degree position is 6 degrees, the pulse numerical value correspondingly generated is 300, namely the first preset pulse numerical value, then, the BC phase is subjected to the same mode to obtain a second preset pulse numerical value 1500, and the CA phase is subjected to the same mode to obtain a third preset pulse numerical value 2700. These three preset pulse values are stored in the MCU.

Assuming that the value of the real-time counting of the pulse signal generated by the rotary encoder by the pulse counting channel reaches 1000 when the motor stops last time, when the motor normally starts to normally operate this time, first a first preset pulse value 1500 is written into a comparison register in the counter, then the BC is electrified, the rotary encoder continuously generates the pulse signal along with the operation of the motor, the pulse counting channel starts to count the pulse signal in real time by 1000, and the counter compares the count value in the pulse counting channel with the preset pulse value in the comparison register in real time.

When the real-time counting value of the pulse signal generated by the rotary encoder through the pulse counting channel reaches 1500, the real-time counting value is equal to the preset pulse value 1500, the counter sends an interrupt signal to the MCU, the MCU controls the driving circuit to conduct electricity for the motor CA according to the forward rotation electrifying phase sequence of the motor, and then the motor continues to rotate and run. When the counter sends an interrupt signal to the MCU, the counter triggers the DMA to obtain the next preset pulse value from the MCU: 2700 and saves 2700 in the compare register. When the value of the pulse signal real-time count generated by the pulse counting channel to the rotary encoder reaches 2700, the pulse counting channel is equal to the preset pulse value 2700, the counter sends an interrupt signal to the MCU, the MCU controls the driving circuit to be electrified for the motor AB according to the motor reversal electrifying phase sequence, and then the motor continues to rotate and run. When the counter sends an interrupt signal to the MCU, the counter triggers the DMA to obtain the next preset pulse value from the MCU: 300 and stores 300 in the compare register.

The rotary encoder continuously generates pulse signals along with the continuous operation of the motor, when the real-time counting value of the pulse signals generated by the rotary encoder reaches 3600 through the pulse counting channel, the rotary encoder rotates for 360 degrees for one circle, so that zero-position pulses are emitted by the output Z phase of the rotary encoder, when the zero-position pulses are captured by the counter through the input capturing channel, the counting value of the pulse counting channel is cleared, and the pulse values generated by the pulse counting channel to the rotary encoder start to be counted again from 0.

When the real-time counting value of the pulse signal generated by the rotary encoder through the pulse counting channel reaches 300, the pulse counting channel is equal to the preset pulse value 300, the counter sends an interrupt signal to the MCU, the MCU controls the driving circuit to conduct electricity for the motor BC according to the reverse power-on phase sequence of the motor, and then the motor continues to rotate and run. When the counter sends an interrupt signal to the MCU, the counter triggers the DMA to obtain the next preset pulse value from the MCU: 1500 and save 1500 in the compare register.

And repeating the steps, so as to ensure the normal reverse rotation operation of the motor until the motor stops operating.

It should be noted that, if the rotary encoder is loose for various reasons and cannot ensure that the rotation of the rotary encoder is synchronous with the rotation of the motor rotor, or the MCU loses power, the rotary encoder is fixed again to achieve the rotation synchronization with the motor rotor, or after the MCU is powered again, the rotary encoder needs to determine the zero position and determine the commutation point again, which is to ensure that the rotary encoder can accurately detect the absolute position of the motor rotor, so as to achieve the purpose of the MCU accurately controlling the commutation of the motor.

Fig. 3 is a block diagram showing an apparatus for controlling a motor according to an embodiment of the present invention, the apparatus being applied to a counter in an MCU, the counter being connected to a rotary encoder, the apparatus for controlling a motor including:

an obtaining module 310, configured to obtain a preset pulse value stored by the MCU, where the preset pulse value is a pulse value corresponding to a phase change point of the motor;

a counting and comparing module 320, configured to count a pulse value generated by the rotary encoder, and compare whether the currently counted pulse value is equal to a preset pulse value;

and a sending interruption obtaining module 330, configured to send an interruption signal to the MCU when the currently counted pulse value is equal to the preset pulse value, and obtain a next preset pulse value stored by the MCU at the same time, where the interruption signal is used to enable the MCU to perform a phase change operation on the motor.

Optionally, the counter comprises an input capture channel; the apparatus for controlling a motor further includes:

the capture module is used for capturing a first zero pulse emitted by the rotary encoder through an input capture channel;

the zero clearing module is used for clearing a count value of a pulse value generated by the rotary encoder when capturing a first zero pulse through the input capturing channel and setting the current position of the rotary encoder as the zero position of the rotary encoder;

and the phase change point pulse value determining module is used for counting pulse values generated in the process that the rotary encoder changes from a rotating state to a stopping state by taking a zero-degree position as an initial position when the MCU energizes each phase of the motor through the driving circuit to obtain the pulse values of the phase change points of the motor.

Optionally, the number of the preset pulse values is multiple; the counter further comprises: the pulse counting channel is used for counting pulse values generated by the rotary encoder, and the comparison register is used for storing and obtaining preset pulse values stored by the MCU; the apparatus for controlling a motor further includes:

and the trigger acquisition module is used for triggering the direct memory access through the pulse counting channel, acquiring the next preset pulse value stored by the MCU and storing the next preset pulse value in the comparison register.

An embodiment of the present invention further provides a system for controlling a motor, where the system includes: MCU, rotary encoder and motor, MCU includes: and the counter is connected with the MCU and the motor respectively and used for executing any one of the methods.

In conclusion, the method, the device and the system for controlling the motor do not need to change the existing circuit structure and the structure of each device in the using process, are simple, convenient and high in accuracy, can be adjusted adaptively according to the specific performance of the rotary encoder, and have the advantages of clear and concise whole method, strong operability and wider application range.

While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.

Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.

While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.

12页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种高动态性的无刷直流电机内功角控制方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!