In this article,we prepare to discuss the question of motor current close-loop control.you will view more and more professional words and multisim.I promise to you i will try my best to describe it by simply vocabularies.in next chapter, it contains current sensor,transfer function of system,and PI controller.
在本文中,我将会和大家一起讨论电机控制中的电流闭环控制问题。从这一节开始,文中将会出现大量的专业术语和仿真分析。我会尽量使用通俗易懂的语言来阐述这些名词。以便读者理解。这一章节内容包含以下几个部分:一是电流传感器,二是系统的传递函数,最后一部分就是PID控制器。
Firstly,we need current,but where is it from?there is a great many of answers.the principle of measuring current also beyond count.we can measure the voltage of resistant so that caculate the current.Besides,wo also can use hall sensor to measure it.and current transformer.but it is not ofen needed.Let's skip it.
既然我们要实现电机的电流控制,第一个问题是电流从哪里来。单从原理来看,测量电流的方法有很多,电阻分压,霍尔传感器,电流互感等方式都可以测量电路中的电流量。但在实际应用中,最多的时采样电阻法和霍尔传感器测量法。此外,还有电流互感法。但它应用并不广泛,我在这里省略不讲。
According to Ampere's law,when current through to wireway,it product magenetic filed.its intensity proportional to the size of current.when current perpendicular external magenatic filed and through to semiconductor,carrier will deflection.in the direction of perpendicular to current and magnetic filed will generate a addtional electric filed.then creat a voltage at both ends of semiconductor.the phenomenon of this called Hall Effective.the voltage also named Hall Voltage.therefore,we just get this voltage then deduction the current of circuit.
安培定律告诉我们:电流通过导线时,会在周围产生磁场,且该磁场的强度与电流大小成正比。由于电流的这一特性,我们可以通过霍尔效应测量电流。那么什么是霍尔效应呢?当电流垂直于外磁场通过半导体时,载流子发生偏转,垂直于电流和磁场的方向会产生一附加电场,从而在半导体的两端产生电势差,这一现象就是霍尔效应,这个电势差也被称为霍尔电势差。测量这个电势差,可以间接测量出导线中的电流。相关公式请读者自行查阅。
Next,i will introduce the chip to you,its CC6902 of CROSSCHIP company.we can check the datasheet and know how to apply it.just need a IO port to MCU,and A/D transform,we can get the current of circuit.the most typical character is linear,The linearity is 0.4%.
我以CROSSCHIP的CC6902电流传感器芯片为例,讲解一下霍尔传感器测量电流的应用。下图是CC6902的管脚定义。将该芯片串联在需要测量的电路中,OUT脚将输出一个电压值,通过单片机对该电压值进行采样计算,可以得到电路中电流的大小。该芯片的线性度大概为0.4%。
This way is used widely in the field of motor control.Give the woltage and the resistance,the current can be determined according to Ohm`s Law.In series with the H-bridge,we measure the voltage of sampling resistance then calculate the current of circuit.But we also need consider some factors,for one thing are power dissipation,we gain the conclusion that power will become greater with increasing sampling resistance.so the range of value of resistance is mΩ.for another are amplifier.low-resistance mean low voltage.we assume the value of current is 10A in the circuit.it can be caculated easily.about 50mV voltage will be measured when sampling resistance is 5mΩ. For STM32,it owms 16 bits ADC transformer.when reference voltage is 3.3V,we can get min resolution is 0.05mV.you may think it is enough to measure.but in fact,we need amplifier all along.Why?One reason is it has the funtion of amplification andconditioning.it will have more high-precision.In my design,AD8414 has 20x magnification ability.it change the voltage from 50mV to 1V.if you have a low-precition ADC converter.it is friendly.Another reason is impebance converter.its dangerous for MCU that through high current.
使用采样电阻测量电流是目前电机控制领域,应用最广泛的一种方法。由欧姆定律:I = U/R,将采样电阻串联在H桥中。我们只需要采集电阻上的电压就能计算出电流。但是这也有一些需要考虑的因素:一个是热耗散问题,由 P = I^2*R 可知,电阻值越大,功耗越大,所以我们的采样电阻的阻值一般选取在mΩ级别。另外一个是需要运算放大器,阻值过小意味着电流在该电阻上产生的压降会很小。有多小呢?假设电路中的电流是10A,采样电阻的阻值为5mΩ,可以计算出电阻上的压降值大概在50mV附近。那么单片机的IO口能不能直接读取呢?以STM32为例,它的ADC是16位的,我们假设ADC的参考电压是3.3V,那么该ADC最小分辨率约为0.05mV。乍看之下,好像可以。但是我们始终需要配合运算放大器一起使用。为什么呢?一个原因是运放具有放大调理的功能。如果直接使用IO口的ADC,0.05mV到50mV只有100个单位。显然精度是不够的。以我开源的资料为例,AD8418这款芯片的放大能力是20倍,刚才的50mV电源,放大后可以到1V,这对于很多低分辨率的ADC很友好。另外一个原因就是阻抗变换,如果直接分压进单片机的IO口,势必会造成单片机烧毁。有关运放的使用,可以参照TI的应用手册,里面讲的很详细。
In the previous series of articles, we have always emphasized two formulas: one is the relationship between the back EMF generated by the motor as a generator and the shaft speed; the other is the relationship between the output torque of the motor shaft and the current passing through the motor coil. I put these two formulas below:
在之前的系列文章中,我们一直强调了两个公式,一是电机作为发电机时,其产生的反电势与轴转速的关系,二是电机轴的输出转矩与电机线圈上通过的电流之间的关系。我把这两个式子放在下面:
U = Ke*n
T = Kt*I
By the way, I would like to mention that the prototypes of these two formulas are actually:
我这里顺带提一下,这两个公式的原型其实是:
U = Ke * φ *n
T = Kt * φ * I
Here, φ is the magnetic flux of the motor, unit: Weber. It is omitted because the motor generally uses permanent magnet as its stator, and its magnetic flux is often constant. So we usually omit it. Let's discuss the transfer function of DC brush motor. Let's start with the mathematical model and deduce the transfer function relationship between armature voltage and winding current.
这里的φ是电机的磁通量,单位为韦伯,之所以把它省略,是因为电机一般使用永磁体作为定子,其磁通往往恒定。所以我们一般把它省略。下面我们来讨论直流有刷电机的传递函数。让我们从数学模型入手,逐步推导出电机电枢电压和绕组电流之间的传递函数关系。
First of all, in the previous discussion, we said that the motor is equivalent to the following model, and then review one side, DC motor is equivalent to a resistance (internal resistance of the motor), series inductance (coil) and a voltage source (back EMF).
首先,我们在之前的讨论中,我们讲电机等效为以下模型,再来复习一边,直流电机等效为一个电阻(电机内阻)串联电感(线圈)以及一个电压源(反电动势)。
From the above model, we can deduce the armature voltage balance equation as follows:
由以上模型,我们可以推出电机电枢电压平衡方程为 :
Um = Rm*Im + Lm*di/dt+Vs
Where: vs = Ke * φ * n
其中:Vs = Ke * φ *n.
In addition, the motor torque balance equation is as follows:
此外,电机转矩平衡方程为:
J*dn/dt = M - Ml
Where: M = KT * φ * I
其中:M = Kt * φ * I.
Readers who have read my previous series of articles must be familiar with these two formulas. They are the electrical equation and the mechanical equation of the motor. From the principle of automatic control, we know that the transfer function of the system is the output / input of the system, that is, G (s) = C (s) / R (s). Here, it should be noted that the input is the motor armature voltage and the output is the motor coil current. You may have doubts, that the current is the input and the voltage is the output. But we think carefully, we control the motor, the most fundamental is to control the power of the motor. Power is determined by voltage and current. In fact, pulse width modulation is widely used now. So our final input is the voltage.
看过我之前系列文章的读者对这两个公式想必并不陌生。它们分别是电机的电气方程和机械方程。由自动控制原理,我们知道系统的传递函数是该系统的输出/输入,即G(s) = C(s)/R(s).在这里,需要注意的是,输入是电机电枢电压,输出是电机线圈电流。 可能大家会有疑问,觉得电流是输入,电压是输出。但是我们仔细想一想,我们控制电机,最根本的是控制电机的功率大小。而功率由电压和电流决定。实际上,我们现在普遍采用的是脉宽调制技术。那么我们最终的输入量,就是电压值。
Two transfer functions can be obtained by making a pulldown transformation of the two equations
我们把这两个方程分别做一下拉氏变换,可以得到两个传递函数,它们分别是:
Transfer function between armature current and armature voltage:
电枢电流于电枢电压之间的传递函数:
im /(Um - Vs)= (1/R)/(1+s*Lm/Rm)= Ka / (1+s*Ta)
The transfer function between rotor speed n and dynamic torque (M - ml) is as follows
转子转速n与动态转矩(M - Ml)之间的传递函数:
n / (M - Ml) = 1 / s*J
Where the armature gain Ka = 1 / RM and the armature time constant TA = LM / RM.
其中,电枢增益Ka = 1/Rm,电枢时间常数Ta = Lm/Rm。
If I only discuss the current loop here, we only need to look at the transfer function g (s) = (1 / R) / (1 + s * LM / RM) = Ka / (1 + s * TA). The function is a typical first-order inertial link. Using the DC motor module of Simulink, we can easily get the current curve of the motor. I use the official example of MATLAB to modify the parameters to the parameters of my own motor. The simulation schematic diagram of Simulink is shown in Fig. 1. The PWM reference voltage is set to full scale (i.e. the voltage is directly from 0V to 24V), and the motor current curve is shown in Fig. 2. As can be seen from Figure 2: on the one hand, the motor starts with a large current, which is similar to current charging. On the other hand, when the motor enters the rated working state, the condition I mentioned here is under no load condition. The required current will return to normal. I actually measured it, and the simulation value is very close to the actual value. We have to boast about the power of Simulink.
我这里只讨论电流环的话,我们只需要看G(s) = (1/R)/(1+s*Lm/Rm)= Ka / (1+s*Ta)这个传递函数。该函数为典型的一阶惯性环节。使用Simulink的直流电机模块,我们可以很方便的得到电机上电流的变化曲线。我使用的是Matlab的官方示例,将参数修改为自己电机的参数。Simulink仿真原理图如图1所示,设置PWM参考电压为满量程(即电压由0V直接到24V),得到的电机电流曲线如图2所示。由图2可以知道:一方面,电机启动瞬间电流很大,这个过程类似于电容充电。另一方面,当电机进入额定工作状态时,这里我所说的状况是在无负载的状态下。电机线圈上的电流会回到正常值。我实际测量了一下,仿真值和实际值很接近。这里不得不夸一夸Simulink的强大。
The response curve of the motor shows the physical characteristics of the motor itself. There is inherent hysteresis in the motor current response. This tells us that the control frequency of the motor current should not be lower than this value or too high. If the control frequency is too high, the motor can not respond in time, which will increase the cost of MCU. Too low control frequency is not enough to counteract the influence of inertia of motor itself, which affects the continuity of control.
这个电机的响应曲线,说明了电机本身的物理特性。电机电流响应天生存在滞后。这一点告诉我们,对电机电流的控制频率不能低于这个值,也不能太高。过高的控制频率电机无法及时响应,还会增加单片机的开销。过低的控制频率不足以抵消电机本身惯性的影响,影响控制的连续性。
I don't want to talk more about PID controller. Readers can search by themselves. My main problems here are as follows:
有关PID控制器,我并不想多讲,读者可以自行搜索。我这里主要解决的问题是:
Let's start with the first question. In this chapter, we discuss the current loop. Maybe after talking for a long time, I still don't know what the current loop is. What we need to understand is that a closed-loop control system contains inputs and outputs as well as feedback. Here, our input is the voltage at both ends of the motor, and the output is the current flowing through the motor. So what is feedback? It's the current that we collect through the sensor. In practical engineering application, our feedback is the A / D conversion value of the voltage at both ends of the sampling resistor. Our input is the target current value and the output is the duty cycle of PWM. From the whole control logic point of view, it is like this. As shown in the figure below.
首先来看第一个问题,在这一章节里,我们讨论电流环。一个闭环控制系统,必然包含输入输出和反馈。对于电机而言,我们的输入是电机两端的电压,输出是电机电枢上流过的电流。对于我们整个电流控制系统而言,输入(我喜欢称之为期望)就是我们希望电机电枢上流过的电流。输出是电机上的电压(通过PWM来实现),那么反馈是什么呢?反馈就是我们传感器实际采集到的电流值。如下图所示。
The next question is why only PI controllers are used instead of classic PID controllers. My point of view is: there is a lag link in the motor itself, and adding D will only affect the dynamic performance. The differential part of PID controller can amplify the error. Due to the limitation of measurement principle, there will be noise in our current value. Therefore, reliable hardware design and PCB layout are also very important parts of motor drive. In addition, in my personal understanding, the differential link can reduce the steady-state time of the system. Relative to the motor's dependent time, this speed is too fast to work at all.
接下来的问题是, 为什么只使用PI控制器而不是经典的PID控制器。一方面来自经验。我的观点是:电机本身存在滞后环节,但并未达到大滞后的状况。对于温度量这种严重滞后的控制环节,D必不可少。电流加D只会影响动态性能。此外,控制器中的微分环节对误差有放大作用,由于测量原理的限制,我们的电流值会存在噪声,D环节容易放大噪声。所以可靠的硬件设计和PCB布局也是电机驱动中很重要的部分。
The last question is also the one that bothers me the most for a long time. Here I give a pertinent answer: not sure. The output of the current loop is finally reflected in the motor torque. It is used for constant torque control of motor. If my controlled object is the CPU cooling fan, in fact, what I need to control is the speed of the fan, and the effect of torque is not obvious here. If I control the spindle cutting, then torque control is very important here. In fact, this also explains a truth, specific analysis of specific issues. Most importantly, torque control is generally used as the most internal loop of the system, because it directly controls the motor. The speed loop is often in the outer ring, which is what I need to talk about in the next chapter. Generally, it is current ring + speed ring, or speed ring + position ring. Because the current loop directly controls the motor and acts as a voltage current converter, its processing cycle is usually a PWM cycle.
最后的问题也是困扰我最久的问题,我在这里给出一个中肯的回答:不确定。电流环的输出最终体现在电机的转矩上。用于电机的恒转矩控制。如果我的被控对象是CPU散热的风扇,那么实际上,我需要控制的就只有风扇的转速,转矩在这里的作用并不明显。如果我是控制主轴切削,那么转矩控制在这里就显得非常重要了。电流环一般作为串级控制的最内环,因为它直接作用于电机,所以一般用它提高响应。上一段我们提到了电流噪声的问题,我会再下一章节专门讲。
This chapter mainly introduces the role of current loop in motor control and the need to use PI controller when selecting controller. And the processing time of the current loop.
本章节主要介绍了电流环在电机控制中的作用,以及在选择控制器时需要使用PI控制器。以及电流环的处理时间等问题。
Next is the author's words: when it comes to the control principle, this part of the content is more and more difficult. It's a big head. Due to the limited level, there are some fallacies in the article. I hope the readers can point out the common progress. As I am crossing the river by feeling the stone, some things can only be improved slowly. I hope you don't mind. In addition, after a long delay, I will put the source code of supporting hardware on the agenda as soon as possible. Although the road is endless and faraway, I still want to pursue the truth in the world. I'd like to share with you.
接下来是笔者的话:涉及到控制原理,这一部分的内容越来越难。令人头大。由于水平有限,文章中有谬误的地方希望读者能够指出,共同进步。由于我也是在摸着石头过河,所以有些东西也只能慢慢完善,希望大家不要介意。另外,稍微拖更了一久,我会尽快把配套硬件的源码提上日程。路漫漫其修远兮,吾将上下而求索。与诸君共勉。
1.《STM32 电机教程 4 - 直流有刷电机闭环电流控制》
2.《德国人怎么学电机——电机驱动控制(一):直流电机》
3.《Simulink 控制设计入门之旅》
4.《有刷直流电机的数学模型及参数测量方法》金国强 1000-0712(2014)01-0056-05
5. 贺益康 许大中 《电机控制》
6. 阮毅 陈伯 《电力拖动自动控制系统-运动控制系统》
日志:2020年10月30日第一次修改