电机控制 pid例子
- 格式:pdf
- 大小:1.08 MB
- 文档页数:29
飞思卡尔智能车电机PID提到小车的控制必然想到的PID控制,这也是各技术报告都不会漏掉的名词,在飞思卡尔XS128系列(二)PWM模块中已经提到了一些电机控制方面的东西,主要讲了用PID和BANG-BANG 控制相结合的方式来控制电机,就是由BANG-BANG来控制力度,用PID来控制精度,下面就具体来讲讲。
先说控制,所谓控制首先由闭环控制和开环控制之分,就是所谓的有反馈和无反馈,当然PID显然是有反馈的控制。
所谓的闭环控制就是要根据被控制量的实际情况参与运算来决定操作量的大小或者方向。
因为在单回路控制系统中,由于扰动的作用使被控参数偏离给定值,从而产生偏差,而自动控制系统的调节单元将来自变送器的测量值与给定值相比较后产生的偏差进行比例、积分和微分运算,并输出统一标准信号,去控制执行机构的动作,以实现对温度、压力、流量和速度等的自动控制。
然而牵扯到高级PID,像有自适应控制、模糊控制、预测控制、神经网络控制、专家智能控制等等,里面也就模糊控制搞过一定时间,其它我也不懂,就不瞎扯了。
比例、积分和微分的线性组合,构成控制量u(t),称为:比例(Proportional)、积分(Integrating)和微分(Differentiation)控制,简称PID控制。
比例作用P只与偏差成正比,积分作用I是偏差对时间的累积,而微分作用D是偏差的变化率。
用一句形象的比喻,比例P代表着现在,积分I代表着过去,而微分D则代表着未来。
公式如图:具体于比例、积分和微分,网上有很多这方面的资料,我就不多说了。
下面是关于参数的调整,比例系数、积分系数和微分系数的合理调整时整个PID系统可以正常温度工作的关键。
而最好的寻找PID参数的办法是从系统的数学模型出发,从想要的反应来计算参数。
很多时候一个详细的数学描述是不存在的,这时候就需要从实际出发去调整PID参数了。
Ziegler——Nichols方法Ziegler——Nichols方法是基于系统稳定性分析的PID整定方法,在设计过程中无需要考虑任何特性要求,整定方法简单。
PID算法介绍:本次设计主要研究的是PID控制技术在运动控制领域中的应用,纵所周知运动控制系统最主要的控制对象是电机,在不同的生产过程中,电机的运行状态要满足生产要求,其中电机速度的控制在占有至关重要的作用,因此本次设计主要是利用PID 控制技术对直流电机转速的控制。
其设计思路为:以AT89S51单片机为控制核心,产生占空比受PID算法控制的PWM脉冲实现对直流电机转速的控制。
同时利用光电传感器将电机速度转换成脉冲频率反馈到单片机中,构成转速闭环控制系统,达到转速无静差调节的目的。
在系统中采128×64LCD显示器作为显示部件,通过4×4键盘设置P、I、D、V四个参数和正反转控制,启动后通过显示部件了解电机当前的转速和运行时间。
因此该系统在硬件方面包括:电源模块、电机驱动模块、控制模块、速度检测模块、人机交互模块。
软件部分采用C语言进行程序设计,其优点为:可移植性强、算法容易实现、修改及调试方便、易读等。
本次设计系统的主要特点:(1)优化的软件算法,智能化的自动控制,误差补偿;(2)使用光电传感器将电机转速转换为脉冲频率,比较精确的反映出电机的转速,从而与设定值进行比较产生偏差,实现比例、积分、微分的控制,达到转速无静差调节的目的;(3)使用光电耦合器将主电路和控制电路利用光隔开,使系统更加安全可靠;(4)128×64LCD显示模块提供一个人机对话界面,并实时显示电机运行速度和运行时间;(5)利用Proteus软件进行系统整体仿真,从而进一步验证电路和程序的正确性,避免不必要的损失;(6)采用数字PID算法,利用软件实现控制,具有更改灵活,节约硬件等优点;(7)系统性能指标:超调量≤8%;调节时间≤4s;转速误差≤±1r/min。
1PID算法及PWM控制技术简介1.1PID算法控制算法是微机化控制系统的一个重要组成部分,整个系统的控制功能主要由控制算法来实现。
pid实际应用PID(Proportional-Integral-Derivative,比例积分微分)控制器是一种经典的自动控制系统,也是目前工业控制中应用最广泛的一种控制器。
它通过不断地测量被控对象的实际输出值与期望输出值的差距,并依照一定的比例、积分、微分系数计算出控制信号,对被控对象进行调节,最终使其输出达到期望值并保持稳定。
PID控制器的实际应用非常广泛,涵盖了各个领域的自动控制系统。
下面就以几个实际的例子来说明PID控制器的应用。
1. 温度控制系统温度控制系统是PID控制器的经典应用。
制造业中的许多工艺都需要对温度进行控制,例如冶金、化工、生物制药、食品加工等行业。
PID 控制器可以根据传感器提供的温度数值计算出控制信号,通过调节加热器或制冷器的功率,实现对温度的精确控制。
2. 电机转速控制电机的转速直接影响着机械设备的性能和工作效率,因此需要对电机转速进行准确控制。
PID控制器可以通过对电机转速的反馈信号不断调整电机的输出功率,使得电机转速稳定在期望值或者在受到扰动时能够快速恢复到期望转速。
3. 液位控制系统液位控制系统在化工、石油、食品饮料等行业中应用较为广泛。
PID 控制器可以通过对液位的反馈信号进行测量和处理,精确地调节阀门开度和出口流量,从而实现液位的准确控制。
4. 飞行控制在无人机、飞机、火箭等航空器的飞行控制中,PID控制器是必不可少的关键组件之一。
通过对陀螺仪、加速度计等测量装置的反馈信号不断计算控制信号,实现对飞行器姿态、高度、速度等方面的精确控制。
总之,PID控制器是自动控制领域中非常重要的一种控制器,其实际应用广泛涵盖了各个领域。
在未来,随着人类技术的不断进步和应用场景的不断拓展,PID控制器的应用也将变得越来越广泛和深入。
用PID调节优化电机驱动系统的效率和精度PID调节是一种常用的控制策略,可用于优化电机驱动系统的效率和精度。
本文将介绍PID调节的原理和应用,并探讨其在电机驱动系统中的具体应用案例。
一、PID调节的原理PID调节是一种基于反馈控制的方法,通过不断调整输出信号,使系统的实际输出与期望输出之间达到最优的差距。
PID控制器由比例(P)、积分(I)和微分(D)三个部分组成。
1. 比例(Proportional)部分:根据误差的大小决定输出信号的变化幅度。
比例控制主要用于快速响应系统变化,并减小稳态误差。
2. 积分(Integral)部分:根据误差的累积值决定输出信号的变化幅度。
积分控制主要用于消除系统的静态误差。
3. 微分(Derivative)部分:通过计算误差变化率来调整输出信号的变化速度。
微分控制主要用于抑制系统的震荡和提高系统的稳定性。
通过合理地调节PID控制器的参数,可以使系统达到期望的效果,并提高系统的响应速度、稳定性和精度。
二、PID调节在电机驱动系统中的应用电机驱动系统是一种常见的控制系统,PID调节在其中被广泛应用。
下面将以直流电机驱动系统为例,介绍PID调节在电机驱动中的应用。
1. 速度控制直流电机的转速控制是电机驱动系统的重要任务之一。
PID调节可用于实时调整电机的驱动信号,使电机达到期望的转速。
控制器根据电机实际转速与期望转速之间的差异,不断调整输出信号,实现电机转速的精确控制。
2. 位置控制除了速度控制,PID调节还可用于电机的位置控制。
通过控制电机的驱动信号,使电机在给定的位置上停止或定位到指定位置。
控制器根据电机实际位置与期望位置之间的差异,调整输出信号,实现电机位置的精确控制。
3. 力矩控制在某些应用中,需要通过控制电机的力矩来实现特定的任务。
PID 调节可用于调整电机的驱动信号,使电机输出期望的力矩。
控制器根据电机实际输出力矩与期望输出力矩之间的差异,调整输出信号,实现电机力矩的精确控制。
电机控制系统PID调节器设计与实现一、引言随着电机在工业、农业、交通等领域的广泛应用,如何实现电机的精确控制成为了一项重要挑战。
PID调节器作为一种常用的控制算法,被广泛应用于电机控制系统中。
本文将介绍电机控制系统中PID调节器的设计与实现。
二、PID调节器原理及控制策略PID调节器是一种常用的闭环控制算法,它包含比例控制、积分控制和微分控制三个部分。
比例控制是根据误差信号的大小进行控制,积分控制是处理误差信号的累计值,微分控制是根据误差信号的变化率进行控制。
PID调节器结合了三个控制策略,可以实现对系统的快速响应、精确控制等优秀特性。
三、PID调节器的实现方法PID调节器的实现方法取决于电机控制系统的具体应用场景与控制需求。
一般来说,PID调节器可以分为模拟PID和数字PID 两种实现方法。
1、模拟PID调节器模拟PID调节器是基于传统的模拟电路进行实现的,它需要使用模拟运算放大器等元器件实现PID调节器的比例、积分和微分计算。
模拟PID调节器的优点是响应速度快、控制精度高,但缺点是难以实现复杂的控制算法。
因此,模拟PID调节器通常仅适用于简单的电机控制系统。
2、数字PID调节器数字PID调节器是基于数字信号处理器(DSP)等器件进行实现的,它可以通过编程实现PID调节器的比例、积分和微分运算。
数字PID调节器的优点是可以实现复杂的控制算法、易于开发和调试。
数字PID调节器通常适用于电机控制系统的高级控制或者涉及多轴控制的应用场景。
四、电机控制系统PID调节器设计实例本文以直流电机控制系统为例,介绍PID调节器的设计方法。
1、控制系统模型建立假设直流电机的控制系统如图1所示,它由电气子系统和机械子系统组成。
电气子系统包含直流电机、电源、电阻和感性电路。
机械子系统包含电机机械负载、转动惯量和摩擦阻力等。
图1 直流电机控制系统示意图则直流电机控制系统的传递函数为:G(s) = K / (Ls + R) * 1 / (Js2 + bs)其中,K是电机的电磁功率常数,L是电机的电感,R是电机的电阻,J是电机的转动惯量,b是电机的摩擦系数。
实验十七 直流电机控制实验一、 实验目的1. 学习数字控制器的模拟化设计方法;2. 学习数字PID 控制器的设计方法;3. 学习PWM 控制理论;4. 学习数字PID 控制器在DSP 上的实现方法。
二、实验设备 计算机,CCS 2.0版软件,实验箱、DSP 仿真器、导线。
三、基础理论 PID 控制器(按闭环系统误差的比例、积分和微分进行控制的调节器)自30年代末图1 模拟PID 控制期出现以来,在工业控制领域得到了很大的发展和广泛的应用。
它的结构简单,参数易于调整,在长期应用中已积累了丰富的经验。
特别是在工业过程控制中,由于被控制对象的精确的数学模型难以建立,系统的参数经常发生变化,运用控制理论分析综合不仅要耗费很大代价,而且难以得到预期的控制效果。
在应用计算机实现控制的系统中,PID 很容易通过编制计算机语言实现。
由于软件系统的灵活性,PID 算法可以得到修正和完善,从而使数字PID 具有很大的灵活性和适用性。
实现PID 控制的计算机控制系统如图1所示,其中数字PID 控制器是由软件编程在计算机内部实现的。
1、PID 控制规律的离散化PID 控制器是一种线性调节器,这种调节器是将系统的给定值r 与实际输出值y 构成的控制偏差y r c -=的比例(P )、积分(I )、微分(D ),通过线性组合构成控制量,所以简称PID 控制器。
连续控制系统中的模拟PID 控制规律为:])()(1)([)(0dtt de T dt t e T t e K t u D t I p ++=⎰ (式1)式中)(t u 是控制器的输出,)(t e 是系统给定量与输出量的偏差,P K 是比例系数,I T 是积分时间常数,D T 是微分时间常数。
其相应传递函数为:)11()(s T sT K s G D I p ++= (式2) 比例调节器、积分调节器和微分调节器的作用:(1)比例调节器:比例调节器对偏差是即时反应的,偏差一旦出现,调节器立即产生控制作用,使输出量朝着减小偏差的方向变化,控制作用的强弱取决于比例系数P K 。
PID控制应该算是非常古老而且应用非常广泛的控制算法了,小到热水壶温度控制,大到控制无人机的飞行姿态和飞行速度等等。
在电机控制中,PID算法用得尤为常见。
一、位置式PID1.计算公式在电机控制中,我们给电机输出的是一个PWM占空比的数值。
话不多说,直接上位置式PID基本公式:控制流程图如下:上图中的目标位置一般我们可以通过按键或者开关等方式编程实现改变目标值,测量位置就是通过stm32 去采集编码器的数据。
目标位置和测量位置之间作差就是目前系统的偏差。
送入PID 控制器进行计算输出,然后再经过电机驱动的功率放大控制电机的转动去减小偏差,最终达到目标位置的过程。
2.C语言实现如何把我们以上的理论分析和控制原理图使用C 语言写出来呢,这是一个有趣且实用的过程。
位置式PID 具体通过C 语言实现的代码如下:int Position_PID (int Encoder,int Target){static float Bias,Pwm,Integral_bias,Last_Bias;Bias=Target- Encoder; //计算偏差Integral_bias+=Bias; //求出偏差的积分//PID基本公式Pwm=Position_KP*Bias+Position_KI*Integral_bias+Position_KD*(Bias-Last_Bias);Last_Bias=Bias; //保存上一次偏差return Pwm; //输出}入口参数为编码器的位置测量值和位置控制的目标值,返回值为电机控制PWM(现在再看一下上面的控制框图是不是更加容易明白了)。
第一行是相关内部变量的定义。
第二行是求出位置偏差,由测量值减去目标值。
第三行通过累加求出偏差的积分。
第四行使用位置式PID 控制器求出电机PWM。
第五行保存上一次偏差,便于下次调用。
最后一行是返回。
二、增量式PID1.计算公式速度闭环控制就是根据单位时间获取的脉冲数(这里使用了M 法测速)测量电机的速度信息,并与目标值进行比较,得到控制偏差,然后通过对偏差的比例、积分、微分进行控制,使偏差趋向于零的过程。
本文只是技术交流,仅仅是鄙人对一些知识的看法和认识,由于鄙人学疏才浅,必然会在本文中出现定义理解不深刻,原理叙述有误等错误,敬请各位高人理解,如有错误之处,请大家指出,我将积极学习改进。
其实很早就应该写这么一个东西,由于学习和工作太忙,一直没有时间去写,春节放假,偶尔有了时间,决心一定要写好,本文只是针对初学者,对于那些老鸟和大神们,基本上没有看的必要,所以再您看这篇文章之前,还要对我多多的理解和宽容,写不好,我改进学习,写的好,希望对您有帮助。
(一)PID 的背景和一些原理上理解PID 控制技术,是最简单的闭环控制技术之一,一般都是利用单反馈或者多反馈来实现对控制对象的调节,实现被控对象的可控性和可预知性的控制。
使得设备运行的更加的可靠,合理且平稳。
PID 的全称为比例积分微分控制,P 即为比例,I 即为积分,D 即为微分。
PID 往往都是应用于惰性系统,所谓惰性系统就是变化较慢且无法精确控制和调节的对象,其中最最重要的特点就是变化速度慢,调节速度慢,控制周期较长,最经典的控制对象就为温度的温控。
下面就举一个简单的例子进行说明:比如我们要对一个水箱里面的水进行加热,我们的目标加热温度为100℃,首先我们不用闭环对水温进行加热,也就是说我们只是靠人为观察温度计的温度值来对加热器进行人工的干预。
当温度加热到100℃以后,我们就停止加热,这个时候,虽然水温已经到达100 且加热器已经不再通电加热,但是由于加热器的预热和水本身传递温度的惰性,导致水温会继续上升,经过一段时间后,水温会继续升高,并且超过100℃,那么该系统就无法达到我们所预期的要求。
这个时候您谁想,停止加热后本身会继续散热继续升温,那等到温度到90摄氏度左右以后,我们停止加热,然后利用水的惰性和加热器的散热,让水温继续升温,正好达到100℃,这样不就解决问题了吗?这么想是对的,但是水温要达到90 几度的时候我们停止加热呢?还有就是从停止加热到100℃的时间是多少?经过一段时间后,温度没有达到100℃,而是小于100 摄氏度以后温度就达到了顶峰,这样怎么办?上述所有的办法,可能能够解决水温到达100℃的要求,但是其中很多环节很多结果都是无法预测和无法控制的,即便经历了很麻烦的人为干预同时经过了一个较长的时间达到了我们对水温加热到100℃的要求,也要经历一个相当复杂和相当漫长的时间才能达到,并且整个过程一直要有人为的干预,实在是属于劳民伤财。
下面是一个基于单片机的PID电机调速控制系统的硬件电路设计示例:
电路中使用了一个STM32F103C8T6微控制器,该MCU内置了PWM输出、ADC输入、定时器计数等功能,非常适合用于电机调速控制。
电机驱动采用了L298N模块,可以
控制两个直流电机的转速和方向。
另外,根据需要,可以加入光电编码器或霍尔传感
器等来获取电机的转速反馈信号。
电路中还使用了一个LCD1602液晶屏来显示电机转速、目标速度、PWM输出等信息,方便用户进行调试和监控。
此外,还可以使用按键开关来控制电机的启停和目标速度
的调节。
在硬件电路设计完成后,需要编写单片机程序来实现PID控制算法、PWM输出、
ADC采样等功能。
通常可以使用Keil、IAR等集成开发环境来编写和调试程序,也可
以使用Arduino IDE等编程环境进行开发。
这只是一个简单的PID电机调速控制系统的硬件电路设计示例,具体的实现方式和细
节可能会因应用场景和需求的不同而有所不同。
UM0289User manualeMotion: a motion control kit based on ST10F276IntroductionThis user manual describes the features of the eMotion Kit, and explains how use the kit toperform generic speed control of DC and BLDC motors.Figure 1.eMotion kitKey features■GUI software (Windows XP OS-compatible)■Control board MDK-ST10 (ST10F276 core, 16-bit DSP @ 64 MHz)■Shielded interface board (for encoder feedback)■powerSPIN boards (L6205 / L6235 eval)■Configurable PID closed speed loop for up three motors DC or BLDC■RS232 communicationNovember 2006 Rev 11/29Contents UM0289Contents1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.1Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1MDK-ST10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2PowerSPIN boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2.1L6205 Eval board (DC Motor) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2.2L6235 Eval board (BLDC Motor) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.3Feedback board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93PC software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.1eMotion GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.1.1EVAL 6235 window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.1.2EVAL 6205 window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.1.3Log window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164ST10 firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.1Communication protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.2Control algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215Using eMotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.1Evaluate eMotion kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.1.1Installing eMotion GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.1.2Board configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.1.3Control operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266.1Hardware issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 7Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Appendix A Bibliography. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282/29UM0289Overview3/291 Overview1.1 Getting startedeMotion is a motion control kit able to manage up to 3 motors (DC or BLDC) simultaneously,it can be used as starting point for the evaluation of control algorithms, motors and drivers.The complete kit is composed of:●Windows GUI (XP-compatible): a Multi-Windows software for managing, through a serial connection, the control of up three motors.●MDK-ST10 board: control board based on microcontroller ST10F276 and three connectors compatible with a powerSPIN board (eval 62xx)●Interface board: a board with two shielded connectors, to be stacked into the sockets of MDK-ST10 to allow motor feedback of encoder signals.●powerSPIN boards: the eMotion kit can manage up to three motor driver boards based on L6205 (DMOS dual full bridge motor driver) and L6235 (DMOS fully integrated three-phase motor driver) chips, for DC and BLDC motors respectively.●Firmware for open/closed loop operation: a complete source library is developed to manage the control of DC and BLDC motors in open loop mode (PWM and driver settings) and closed loop mode (speed regulation with encoder feedback) using 62xx eval boards.●Protocol communication: a complete frame-based protocol is developed to allow the exchange of data with GUI via standard RS232 channel.Figure 2.eMotion kit block diagramIt is possible via the GUI to interact with the ST10F276 control board (MDK-ST10) and generate open loop signals for up three DC or BLDC motors. The PWM frequency (17-30 kHz) and duty cycle (0-100%) can be managed together with driver signals such as enable/disable, brake/unbrake (BLDC) and forward/reverse (DC).The closed loop operation can be performed in terms of motor speed with encoder feedback.A complete PID (Proportional, Integrative, And Derivative) control algorithm is implemented. The user can configure:●the value of PID terms (from 0.01 to 100)●the speed (from 1 to 3000 rpm)●the control loop time (from 1 to 52 ms)●the number of encoder pulses per revolution (1 to 65536)PC + GUIBoard PowerControl board MDK ST10Feedback board (shielded)PowerSPIN boardsEncoder signalsEncoder signalsPower signals PWM/DriverBLDC or DC motorsDriver PowerRS232Serial ProtocolOverview UM02894/29Encoder feedback signals are directly managed by the ST10F276 through its dedicated peripherals.In order to guarantee an optimum quality of encoder waveforms, a special adapter is included to shield the signals and to avoid interference (refer to Section2.3 on page 9 for further information).UM0289Hardware 2 Hardware2.1 MDK-ST10(Refer to the MDK-ST10 User manual (UM0288) for more detailed information)The core of the eMotion Kit is the control board which is based on the ST10F276microcontroller, in which all the driver board management routines are implemented.Board key features:●ST10F276 core (16-bit with DSP @ 64 MHz, 832 KB Flash,68 KB RAM)●RS232●RS485● 2 CAN●I2C (3.3V and 5V)●MC Connector● 3 powerSPIN connectors●VN808 board / GP connector●All pin outs availableThe board design allows the user to develop a high-end motion control system based on this16-bit microcontroller. The features of this powerful device allow the integration of complexroutines to create advanced motion control algorithms.Referring on Figure2, the eMotion kit uses the connectors PowerSpin_1, 2, 3 as indicatedon the silkscreen of the board with the text "PractiSpin 1", "PractiSpin 2", "PractiSpin 3".To allow the compatibility with powerSPIN evaluation boards, for each board connector isinserted a jumper (VCC PRACTI X, located close to the connector) that, if closed, providesa 5V power supply to the respective board.Communication with a PC and GUI system is achieved via an RS232 channel through astandard DB9 female connector and using a standard RS232 cable.5/29HardwareUM02896/29Figure 3.MDK-ST10 boardNote:Refer also to Section 5.1.2: Board configuration on page 23The default configuration of the board (once programmed) is:●EA jumper: 1 (in order to obtain the fetch of the code from internal flash of microcontroller)●SW3 switches: all OFF ●SW5 switches:–Switch 2 (CSEL 0): ON –Switch 7 (CLK 1): ON –Other switches: OFF●Selector J206: "PRACTI" position (in order to connect micro lines to powerSPIN connectors)These configurations impose a 60 MHz core clock frequency and leave port 6 ofmicrocontroller free for I/0s (needed because P6.0=CS0 is used to manage powerSPIN boards)To better understand how powerSPIN boards are managed by control board, Table 1 provides a description of the powerSPIN connectors:MC_CONNECTORPOWERSPIN_2ST10F276VN808 / GPPOWERSPIN_3RS232RS485I 2C CAN2CAN1POWERSPIN_1UM0289Hardware7/29Table 1.PractiSPIN connectors description2.2 PowerSPIN boardseMotion kit can manage up to three boards based on monolithic driver of L62xx family. Thisfirst release of system works with DC and BLDC drivers so with boards L6205 and L6235 but also with similar boards for the same motors.2.2.1 L6205 Eval board (DC Motor)(refer to application note AN1762 and the L620x datasheet for more details)PIN No.PractiSPIN 1PractiSPIN 2PractiSPIN 3Functionality15V via Jumper J207 (VCC PRACTI 1)5V via Jumper J208 (VCC PRACTI 2)5V via Jumper J209 (VCC PRACTI 3)-2P2_10P2_11P2_12Interrupt 3P5_5P5_6P5_7ADC 4P0L.0P0L.1P0L.2GPIO 5, 6NC NC NC -7P1L.0P1L.1P1L.2ADC 8P0L.3P0L.4P0L.5GPIO 9NC NC NC -10P0L.6P0L.7P6.3GPIO 11, 13NC NC NC -14P6.0P6.1P6.2GPIO 15, 16, 17, 18, 19NC NC NC -20P2.0P2.1P2.2GPIO / Capcom 21NC NC NC -22P8.0P8.1P8.2PWM / GPIO 23GND GND GND -24, 25NC NC NC -26P7.4P7.5P7.6GPIO / Capcom 27NC NC NC -28P7.0P7.1P7.2PWM / GPIO 29, 30NC NC NC -31P2.13P2.14P2.15GPIO / Capcom 32P2.3P2.4P2.5GPIO / Capcom 33P1H.4P1H.5P1H.6GPIO / Capcom 34NCNCNC-Hardware UM02898/29eMotion kit can manage the evaluation board based on DMOS full bridge ICs(L6205,L6206,L6207).Figure 4.Eval 6205N boardRefer toSection5.1.2: Board configuration on page23 for a description of the board configuration using eMotion.2.2.2 L6235 Eval board (BLDC Motor)(refer to application note AN1625 and the L6235 datasheet for more details)eMotion kit can manage the evaluation board based on L6235 three phase brushless DCmotor.Figure 5.Eval 6235 boardRefer to Section5.1.2: Board configuration on page23 for a description of the boardconfiguration using eMotion.UM0289Hardware9/292.3 Feedback boardIn order to interface the control system with encoder signals coming from motors, a specialboard, with two 20 pins connectors in the top side, is used (Feedback board).This is a stackable board and has to be inserted using the four 36-pin connectors around the microcontroller in the MDK-ST10 board. The insertion orientation is indicated with a dot in a corner of the board (corresponding to pin 1 of the ST10 MCU)The two connectors (Conn1 J3, Conn2 J4), used to allow the encoder feedback, are shielded with the pair of pins connected to GND.The dimensions of this board are about 6.5 x 6.5 cm. The following tables show the pin assignments for each connector.Table 2.Conn1 Feedback boardTable 3.Conn2 Feedback boardConn.1MDK-ST10 PinFunctionality1P3.7T2IN (encoder_1 A)2GND -3P5.15T2EUD (encoder_1 B)4GND -5P3.6T3IN (encoder_2 A)6GND -7P3.4T3EUD (encoder_2 B)8GND -9P3.5T4IN (encoder_3 A)10GND -11P5.14T4EUD (encoder_3 B)12GND -13P2.6CC16 (capture / GPIO)14GND -15P1L.3GPIO / ADC In 16GND -17P1L.4GPIO / ADC In 18GND -19+5V -20GND-Conn.2MDK-ST10 PinFunctionality1P1L.5GPIO/ ADC In 2GND -3P2.7CC7 (capture / GPIO)Hardware UM028910/29Figure 6.Feedback board schematic4GND-5P1L.6GPIO / ADC In6GND-7P1L.7GPIO / ADC In8GND-9P1H.0GPIO10GND-11P1H.7CC27 (capture / GPIO) 12GND-13P1H.1GPIO14GND-15P1H.2GPIO16GND-17P1H.3GPIO18GND-19+5V-20GND-Conn.2MDK-ST10 Pin FunctionalityUM0289Hardware Figure 7.Feedback board - TOPIn order to report the feedback of motors, a 20-pin flat cable could be used. The firstconnector can be used for an incremental encoder as the timer pins are used forincremental interface mode. The second connector can be used for absolute encoderfeedback where the GPIO and capture pins are used.Note:The system allows the feedback of encoder signals (A and B channels) for each motor, Signals must be squared and with the right logic level (0 and 5V). When necessary, refer tothe datasheet of the encoder used. If needed, pull-up the encoder signals (not provided withencoder kit).11/29PC software UM028912/293 PC softwareThe parameters of eMotion system can be configured through a Windows-based GUI(eMotion GUI), that interacts with the control board via an RS232 straight cable.The following paragraphs provide a description of all the software features.3.1 eMotion GUIRefer to Section 5.1.1: Installing eMotion GUI on page 23 for the installation procedure.After start-up of the eMotion GUI, a series of menu functions are available to the user:File:Connect: Open the "Serial Port Selection" window, from which it is possible to select the serial port to open the communication between the PC and the MDK-ST10 board Disconnect: Close the connection between the PC and the MDK-ST10 board.New: Open a new 6205 or 6235 window (for a DC or BLDC motor respectively)Log Window: Open the Log Window. In this window it is possible to see the communication data as a hexadecimal value sent to the MDK-ST10 board Exit: Exit the programView:Toolbar: Display or hide the toolbarStatus Bar: Display or hide the status bar in the bottom-right corner of the main windowHelpHelp T opics: Open the Help Topics About: Displays eMotion Project credits3.1.1 EVA L 6235 windowThe 6235 window allows the user to drive a BLDC motor through the EVAL6235 board. Afterstarting eMotion, click on the 6235 window icon or choose New - 6235 window from the File menu. A new 6235 window opens.UM0289PC software13/29Figure 8.6235 windowThe Connector Selection panel shows the connector of the MDK-ST10 with which theEVAL6235 can be connected (some connector selections could be disabled if the connector is used by other windows). The left part of this window allows the user to control a BLDC motor in open loop mode. The right part of the window allows the user to perform a PID speed closed loop control with encoder feedback.The Motor Control Command panel is always enabled, while the Control Parameters and Control Loop Time panels are disabled when the Closed Loop check button is not checked. In each case the Get button is always enabled.Motor Control Command panel:●Enable: Enables the 6235 driver. This command switches ON all Power MOSFETs of the driver (pin EN high).●Disable: Disables the 6235 driver. This command switches OFF all Power MOSFETs of the driver (pin EN low).●Unbrake: Sets the pin BRAKE high of the 6235 and enables the normal mode (six step control strategy).●Brake: Sets the pin BRAKE low of the 6235. This command switches ON all High Side Power MOSFETs, implementing the Brake Function.●Duty Cycle Set: This slider allows the user to set the duty cycle of the PWM generated by the ST10 as input for the FWD/REV pin of the 6235 driver. Values between 0 and 50% cause the rotation of the motor in one direction, while values between 50% and 100% cause the rotation of the motor in the other direction. A 50% value corresponds to no motor rotation.Note:The real direction (clockwise or counterclockwise) depends on the connection between the 6235 and the motor.●PWM set: This slider allows the user to change the frequency of the PWM generated by the ST10. The allowed values go from a minimum of 17 kHz to a maximum of 30 kHz. (with 1 kHz steps)Note:At system startup the default values are: disable, brake, PWM duty cycle 50%, PWM frequency 17 kHz.PC software UM028914/29Enable/Disable Control Parameters panel:●Closed Loop: This check control enables/disables the text boxes and push buttons of the Control Parameters and Control Loop Time panels.Control Parameters panel:This panel allows the user to perform a PID speed closed loop control with encoderfeedback. The user must fill the following text boxes and then press the Set button in order to set the control parameters:●Enc. Pulses/r: The number of pulses per revolution of motor encoder.●Speed: Speed of the motor expressed in RPM. Allowed values go from 0 to 3000 rpm (steps 1 rpm).●P: Proportional gain of the PID control. Allowed values go from 0 to 100, in steps of 0.01.●I: Integral gain of the PID control. Allowed values go from 0 to 100, in steps of 0.01.●D: Derivative gain of the PID control. Allowed values go from 0 to 100, in steps of 0.01.●Set: Set the control parameters.Note:If values out of range are inserted in one or more text boxes, a pop-up window will appear indicating that at least one value is out of range.●Start: Start the PID speed closed loop control. The rotation of the motor remains the same of the motor before starting the control.●Stop: Stop the PID speed closed loop control. The motor will rotate with a speed accordingly to the duty cycle calculated in the last control routine before stopping.●Get: This command returns the status of the control parameters and of the control loop time actually memorized in the MDK-ST10 board.Control loop time:This text box allow the user to insert the value of control loop time (in case of closed loop operation); the range of this parameter is from 1 to 52 ms (with 200 us steps)Note:For control loop time is intended the frequency of adjustment of PWM duty cycle (according to PID action) in order to reach the speed reference.3.1.2 EVA L6205 windowThe 6205 window is designed to allow the user to drive a DC motor through EVAL6205.After starting eMotion click on the 6205 window icon or choose New - 6205 window from the File menu. A new 6205 window is now opened.Note:The functions of this window are the same of 6235 window, except for the motor control panel.UM0289PC software15/29Figure 9.6205 windowThe Connector Selection panel shows the connector of the MDK-ST10 with which theEVAL6205 can be connected (some connector selections could be disabled if the connector is used by other windows). The left part of this window allows the user to control a DC motor in open loop mode. The right part of the window allows the user to perform a PID speed closed loop control with encoder feedback.The Motor Control Command panel is always enabled, while the Control Parameters and Control Loop Time panels are disabled when the Closed Loop check button is not checked. In each case the Get push button is always enabled.Motor Control Command panel:●Enable: Enables the 6205 driver. This command switches ON all Power MOSFETs of the driver (pin EN high).●Disable: Disables the 6205 driver. This command switches OFF all Power MOSFETs of the driver (pin EN low).●Forward: This command set low the pin IN1 of the EVAL6205 (pin IN1A of 6205 driver). ●Reverse: This command set high the pin IN1 of the EVAL6205 (pin IN1A of 6205 driver).●Duty Cycle Set: This slider allows the user to set the duty cycle of the PWM generated by the ST10 as input for the IN2 of the EVAL6205 (pin IN2A of the 6205 driver).The direction of rotation of the motor depends on the Forward/Reverse radio buttons. If Forward (Reverse) radio button is checked a value of PWM of 0% (100%) stops the motor while a value of PWM of 100% (0%) runs the motor at maximum velocity.Note:The real direction (clockwise or counterclockwise) depends on the connection between the 6205 and the motor.●PWM set: This slider allows the user to change the frequency of the PWM generated by the ST10. The allowed values go from a minimum of 17 kHz to a maximum of 30 kHz (steps 1 kHz).Note:At systems startup the default value are: disable, forward, PWM duty cycle 50%, PWM frequency 17 kHz.Enable/Disable Control Parameters panel:Refer to Section 3.1.1: EVAL 6235 window on page 12.PC software UM028916/29Control Parameters panel:Refer to Section 3.1.1: EVAL 6235 window on page 12.Control loop time:Refer to Section 3.1.1: EVAL 6235 window on page 12.3.1.3Log windowUsing the log window is possible to view the frames sent and received by the GUI (to checkthe state of communication with the board).A text string is shown explaining the command and also the hexadecimal value of the command (refer to Section 4.1: Communication protocol on page 17).Figure 10.Log windowUM0289ST10 firmware17/294 ST10 firmwareThe firmware to manage the eMotion system is organized in two separate modules:●Communication module : able to exchange data with the PC-GUI using a structuredprotocol.●Control module : able to perform the open and closed loop operation on three motors and communicates with the first module.Note:All the firmware is developed, in standard C language, using tasking toolchain v 8.5 from Altium.4.1 Communication protocolThe serial protocol used for communicate with PC-GUI is a frame based protocol, with abaud rate of 115200, 8-bit data length, no parity check, 1 bit stop.The frame has a variable length, with a CRC field. A mechanism of acknowledgement for each command is implemented.Figure 11.Frame protocolFigure 11 shows the general frame format on which the communication is based, the CRC is a field of 1 byte length computed with this formula:16_Total_Length = (16_bit) (FRAME_TYPE + LENGTH + DAT A)CRC = (8_bit) (High_Byte(16_Total_Length) + Low_Byte(16_Total_Length))Table 4 shows the general description of the frames.Table 4.Frame descriptionFrame name Description Frame Type LengthDirectionTypeConnect Openconnection 0x000PC-MDK ST10Command Enable_Motor Enable motor drive0x011PC-MDK ST10Command Disable_Motor Disable motor drive 0x021PC-MDK ST10Command Brake_Motor Enable brake motor drive 0x031PC-MDK ST10Command Unbrake_MotorDisable brake motor drive0x041PC-MDK ST10CommandForward_MotorSet forward motor direction(6205 motor drive)0x051PC-MDK ST10CommandFrame TypeLength PayloadCRC1 byte1 bytevariable length1 byteST10 firmware UM028918/29The length field indicated the number of bytes in the payload.In each frame (with length greater than 0) the first byte of the payload indicates the association connector-powerspin board (except "Send_Latest_Error") (see Table5): Table 5.Connector-Eval62xxReverse_MotorSet reversemotor direction(6205 motordrive)0x061PC-MDK ST10CommandSet_PWMSet duty cycleof PWM0x072PC-MDK ST10Command+DataSet_Freq_PWMSet frequencyof PWM0x082PC-MDK ST10Command+DataSet_PID_ControlSet the PIDand speedvalues0x0912PC-MDK ST10Command+DataSet_Control_Loop TimeSet the time forexecuting theclosed controlloop0x0A2PC-MDK ST10Command+DataGet_ParametersGet the controlparameters.0x0B1PC-MDK ST10CommandStart_ControlStart controlloop0x0C1PC-MDK ST10CommandStop_ControlStop controlloop0x0D1PC-MDK ST10CommandGet_Latest_ErrorGet Latesterror occurred0x0E0PC-MDK ST10CommandSend_ParametersT ransmissionof theparametersvalues0x4015MDK ST10-PC DataSend_Latest_ErrorSend latesterror occurred0x411-50MDK ST10-PC DataACKConfirm thecorrectreception of aframe0x801MDK ST10-PCPC-MDK ST10AcknowledgmentByte Value0x1A First connector with eval 62350x1B First connector with eval 62050x2A Second connector with eval 62350x2B Second connector with eval 6205Frame name Description Frame Type Length Direction TypeUM0289ST10 firmware19/29ACK timeout is fixed at 10 ms, both for the PC and ST10, and the payload of the "ACK" frame is the command code to be acknowledged."Set_PID_Control" (0x09) is the frame used for setting the specific values of each control loop, the contents of this frame is shown in the table below.Table 6.Table 6 - Set_PID_Control payload"Set_Control_Loop time" (0x0A) is a frame used to set the control loop time of each motor control, according to the table below.Table 7.Set_Control loop time payload"Send_Parameters" (0x40) is a particular frame used to send the status of all system parameters to the PC, the contents of this frame is shown in T able 8.0x3A Third connector with eval 62350x3BThird connector with eval 6205Payload byte orderFieldDescription1Motor Connector Association connector-powerSPIN board2Driver Byte for reserved use, indicating the kind of driver (0xCD for a6205,0xEB for a 6235)3-4Encoder 2 Bytes indicating number of pulse for revolution of motor encoder.5-6Speed2 Bytes indicating the reference speed of motor (range 1-3000 rpm)7-8P2 Bytes indicating the proportional gain of the speed control (range 1-1000, with a firmware scaling)9-10I 2 Bytes indicating the integral gain of the speed control (range 1-1000, with a firmware scaling)11-12D2 Bytes indicating the derivative gain of the speed control (range 1-1000, with a firmware scaling)Payload byte orderFieldDescription1Motor Connector 1 Byte indicating which powerSPIN board is connected to a specific connector.2TimeByte indicating the control loop time (number of 200us steps to be added to the basic control loop of 1ms).Byte ValueST10 firmware UM028920/29Table 8.Send_Parameters contents"Send latest error" (0x41) is a particular frame in which the payload is formed by a text string indicating the last error occurred, typical values are shown below.Table 9.Error stringsA series of protocol frames, used for communication, are provided in T able10.Table 10.Frame examplesPayloadbyte orderField Description1Motor Connector1 Byte indicating which powerSPIN board is connected toa specific connector.2-3Encoder2 Bytes indicating the number of pulses for revolution ofmotor encoder.4PWM%Byte indicating the duty cycle value of PWM (range: 0-100)5PWM Freq.Byte indicating the frequency PWM (range: 17-30)6Time control loopByte indicating the control loop time (number of 200ussteps to be added to the basic control loop of 1ms).7Status Byte indicating if the control is enabled (0 or 1)8-9Speed2 Bytes indicating the reference speed of motor (range 1-3000 rpm)10-11P2 Bytes indicating the proportional gain of the speedcontrol (range 1-1000, with a firmware scaling) 12-13I2 Bytes indicating the integral gain of the speed control(range 1-1000, with a firmware scaling)14-15D2 Bytes indicating the derivative gain of the speed control(range 1-1000, with a firmware scaling)String TypesNo errorCRC not validCommand not validCommand not executableMotor errorValue out of rangeFrame Description Value (Hex)Connect00-00-00Enable 6235 driver on powerSPIN connector 101-01-1A-1CBrake 6205 driver on powerSPIN connector 303-01-3B-3FACK for a Forward command80-01-05-86UM0289ST10 firmware21/294.2 Control algorithmCommunication layer after the reception and checking of a complete frame puts themicrocontroller in an execution state in which the right control layer function is involved.The management of open loop signals is executed with functions that directly act in theregister of PWM signals or through the pins for the right generation of connector signals.Closed loop operations, are instead managed through three independent ISR where thereload timing depends on the closed loop time of the specific control.The speed reference is expressed in terms of encoder pulses, counted in the closed looptiming imposed, so each ISR works with the actual values of encoder inputs and with PWMduty cycles to perform a PID action for reach the right value of encoder reference. Figure 12.Algorithm block diagram Figure 12 shows how the two modules interact (through shared memory) to performeMotion operations.The PID algorithm implemented is approximated with the following formula:Set PWM% to 22% for 6235 driver on connector 208-02-2A-16-4A Set 2ms of control loop time for a 6205 driver on connector 20A-02-2B-05-3CSet control for a DC motor with a 1024/revolution encoder, connected to the first connector. Set the speed reference to 100 rpm with control parameters of P=0.04,I=0.02,D=0.0109-0C-1B-CD-04-00-00-64-00-04-00-02-00-01-6D Receive the parameters of connector 3 with a BLDC motor with500/revolution encoder controlled at 200 rpm with P=0.60, I=0.02,D=0.00 and control loop of 1.2 ms. With actual PWM signal 10% / 22 Khz40-0F-3A-01-F4-00-0A-16-02-01-00-C8-00-3C-00-02-00-00-A9Frame DescriptionValue (Hex)CommunicationLayer Shared memory Control LayerSERIAL BUFFER。