昊芯HXS320F28034数字信号处理器项目中电机相位控制与检测调试
本帖最后由 leekom 于 2024-9-11 16:29 编辑<div _blank="" tdoc-data-src="{"mainStory":[{"operationType":"InsertText","param":{"text":"昊芯HXS320F28034数字信号处理器DSP,对电机使用","range":{"gcpBegin":0,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":0,"len":30},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"差","range":{"gcpBegin":30,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":30,"len":1},"property":{"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"速","range":{"gcpBegin":31,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":31,"len":1},"property":{"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"编码器,也称为增量式编码器,其工作原理是将位移转换成周期性的电信号,再将这个电信号转变成计数脉冲,用脉冲的个数表示位移的大小。","range":{"gcpBegin":32,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":32,"len":63},"property":{"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":95,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":95,"len":1},"property":{"lang":{"val":"en-US","eastAsia":"zh-CN"},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":95,"len":1},"property":{"pStyle":{"val":"000001"},"ind":{"firstLine":840,"firstLineChars":400},"numPr":{}},"mode":1,"preventFormatTrackChanges":false},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"其QEP测速的实现方式如下:","range":{"gcpBegin":96,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":96,"len":14},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":110,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":110,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":110,"len":1},"property":{"pStyle":{"val":"000001"},"ind":{"firstLine":840,"firstLineChars":400},"numPr":{}},"mode":1,"preventFormatTrackChanges":false},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"采用GPIO MUX定义引脚:其引脚对应","range":{"gcpBegin":111,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":111,"len":20},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"在码盘的边缘上开有相等角度的缝隙(分为透明和不透明部分),在开缝码盘两边分别安装光源及光敏元件。当码盘随工作轴一起转动时,每转过一个缝隙就产生一次光线的明暗变化","range":{"gcpBegin":131,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":131,"len":80},"property":{"rFonts":{"ascii":"Arial","hAnsi":"Arial","cs":"Arial"},"i":{"val":false},"iCs":{"val":false},"caps":{"val":false},"color":{"val":"333333"},"spacing":{"val":0},"sz":{"val":210},"szCs":{"val":210},"shd":{"val":"STShd_clear","color":"STHexColorAuto_auto","fill":"ffffff"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":",","range":{"gcpBegin":211,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":211,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia","ascii":"Arial","hAnsi":"Arial","cs":"Arial"},"i":{"val":false},"iCs":{"val":false},"caps":{"val":false},"color":{"val":"333333"},"spacing":{"val":0},"sz":{"val":210},"szCs":{"val":210},"shd":{"val":"STShd_clear","color":"STHexColorAuto_auto","fill":"ffffff"},"lang":{"eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"从而","range":{"gcpBegin":212,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":212,"len":2},"property":{"rFonts":{"hint":"STHint_eastAsia","ascii":"Arial","hAnsi":"Arial","cs":"Arial"},"i":{"val":false},"iCs":{"val":false},"caps":{"val":false},"color":{"val":"333333"},"spacing":{"val":0},"sz":{"val":210},"szCs":{"val":210},"shd":{"val":"STShd_clear","color":"STHexColorAuto_auto","fill":"ffffff"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"获取差分编码器正交脉冲QEPA与QEPB、索引QEPI信号;","range":{"gcpBegin":214,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":214,"len":30},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":244,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":244,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":244,"len":1},"property":{"pStyle":{"val":"000001"},"ind":{"firstLine":840,"firstLineChars":400},"numPr":{}},"mode":1,"preventFormatTrackChanges":false},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"通过QDECCTL选择,上升沿、下降沿或双边沿捕获计数方式,得到时钟信号xCLK,","range":{"gcpBegin":245,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":245,"len":46},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"变化的信号经过整形放大,可以得到一定幅值和功率的电脉冲输出信号。脉冲数就等于转过的缝隙数。将该脉冲信号送到计数器中去进行计数,从测得的数码数就能知道码盘转过的角度","range":{"gcpBegin":291,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":291,"len":81},"property":{"rFonts":{"ascii":"Arial","hAnsi":"Arial","cs":"Arial"},"i":{"val":false},"iCs":{"val":false},"caps":{"val":false},"color":{"val":"333333"},"spacing":{"val":0},"sz":{"val":210},"szCs":{"val":210},"shd":{"val":"STShd_clear","color":"STHexColorAuto_auto","fill":"ffffff"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":";","range":{"gcpBegin":372,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":372,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":373,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":373,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":373,"len":1},"property":{"pStyle":{"val":"000001"},"ind":{"firstLine":840,"firstLineChars":400},"numPr":{}},"mode":1,"preventFormatTrackChanges":false},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"经解码QDU逻辑处理,得到方向的高低电平信号iDIR;","range":{"gcpBegin":374,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":374,"len":27},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":401,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":401,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":401,"len":1},"property":{"pStyle":{"val":"000001"},"ind":{"firstLine":840,"firstLineChars":400},"numPr":{}},"mode":1,"preventFormatTrackChanges":false},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"通过QDECCTL选择引脚模式:正交、方向、增或减计数,读取方向QDIR、时钟QCLK信号;","range":{"gcpBegin":402,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":402,"len":52},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":454,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":454,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":454,"len":1},"property":{"pStyle":{"val":"000001"},"ind":{"firstLine":840,"firstLineChars":400},"numPr":{}},"mode":1,"preventFormatTrackChanges":false},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"通过QEPCTL选择,位置计数控制PCCU模式:索引位置事件、最大位置锁存、单位超时锁存;使能QEPCTL,捕获N线光电编码器输出双边沿脉冲,使位置计数器产生计数,从而计算电机转速。","range":{"gcpBegin":455,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":455,"len":103},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"\r","range":{"gcpBegin":558,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":558,"len":1},"property":{"rFonts":{"hint":"STHint_eastAsia"},"lang":{"val":"en-US","eastAsia":"zh-CN"},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyParagraphProp","param":{"range":{"gcpBegin":558,"len":1},"property":{"pStyle":{"val":"000001"},"ind":{"firstLine":840,"firstLineChars":400},"numPr":{}},"mode":1,"preventFormatTrackChanges":false},"propertyType":"ParagraphProperty","builtinStyleName":"Normal"},{"operationType":"InsertText","param":{"text":"\u0013","range":{"gcpBegin":559,"len":0},"preventTextTrackChanges":false},"builtinStyleName":""},{"operationType":"ModifyRunProp","param":{"range":{"gcpBegin":559,"len":1},"property":{"rFonts":{"ascii":"宋体","hAnsi":"宋体","eastAsia":"宋体","cs":"宋体"},"sz":{"val":240},"szCs":{"val":240},"isPlaceholder":true,"author":"p.144115233544640245"},"mode":1,"preventFormatTrackChanges":false},"propertyType":"RunProperty","builtinStyleName":""},{"operationType":"ModifyFieldProp","param":{"range":{"gcpBegin":559,"len":1},"property":{"fldCharType":"STFldCharType_begin","nestingLevel":1},"mode":1},"propertyType":"FieldCharProperty","builtinStyleName":""},{"operationType":"InsertText","param":{"text":"INCLUDEPICTURE \\d \"<a target=">
<div>昊芯HXS320F28034数字信号处理器DSP,对电机使用差分编码器,也称为增量式编码器,其工作原理是将位移转换成周期性的电信号,再将这</div>
<div>个电信号转变成计数脉冲,用脉冲的个数表示位移的大小。</div>
<div>其QEP测速的实现方式如下:<br />
采用GPIO MUX定义引脚:其引脚对应在码盘的边缘上开有相等角度的缝隙(分为透明和不透明部分),在开缝码盘两边分别安装光源及光敏元</div>
<div>件。当码盘随工作轴一起转动时,每转过一个缝隙就产生一次光线的明暗变化,从而获取差分编码器正交脉冲QEPA与QEPB、索引QEPI信号;</div>
<div>通过QDECCTL选择,上升沿、下降沿或双边沿捕获计数方式,得到时钟信号xCLK,变化的信号经过整形放大,可以得到一定幅值和功率的</div>
<div>电脉冲输出信号。脉冲数就等于转过的缝隙数。将该脉冲信号送到计数器中去进行计数,从测得的数码数就能知道码盘转过的角度;</div>
<div>经解码QDU逻辑处理,得到方向的高低电平信号iDIR;<br />
通过QDECCTL选择引脚模式:正交、方向、增或减计数,读取方向QDIR、时钟QCLK信号;<br />
通过QEPCTL选择,位置计数控制PCCU模式:索引位置事件、最大位置锁存、单位超时锁存;使能QEPCTL,捕获N线光电编码器</div>
<div>输出双边沿脉冲,使位置计数器产生计数,从而计算电机转速。</div>
<div></div>
<div>其A\B\C对应差分编码器,通过检测码盘上的缝隙引起的光线明暗变化,将其转换为电脉冲信号,并通过计数器计算脉冲数量来测量位移大小。</div>
<div>同时,通过两套光电转换装置产生的相位差信号来判断旋转方向,常用方法如下:</div>
<div>(1)T法:一个脉冲周期fclk内,捕获脉冲计数,载入16位定时器QCTMR。单位事件发生时,更新载入QCPRDLAT,电机转速n=60*fclk/(4N*QCPRDLAT)。QCTMR上溢时,位置方向QDIR将变化,使捕获单元QEPSTS发生错误标志,故仅适用于低速测量。</div>
<div>(2)M法:规定检测事件Tc内,捕获脉冲计数。单位事件发生时,锁存到32位QPOSILAT和QPOSSLAT,故电机转速n=60*QPOSSLAT/(4N*Tc),适用于高速测量。</div>
<div>由此设计QEP测速实例:EPWM配置1KHz PWM波,模拟1000线编码器旋转,EQEP采用M法与T法测量60rpm与6000rpm下旋转的转速,单位周期为 SysFreq*100,采用上升沿计数,捕获得到脉冲计数,实现转速测量,采用定时器中断实现三种不同功能切换,故硬件连接如下:GPIO0-GPIO20,GPIO1-GPIO21。基于以上分析,在CDK上开发QEP脉冲捕获输出,代码包括:EPWM与EQEP的GPIO引脚配置,EPWM 1KHz两路互差90°的PWM波输出配置,EQEP单位时间锁存计数捕获功能配置,定时器Timer0配置,计数捕获、M法与T法测速程序及其功能切换的定时器中断服务程序,主程序调用执行。</div>
<div>int main(void)</div>
<div>{</div>
<div>/*初始化系统控制*/</div>
<div>InitSysCtrl();</div>
<div>/*初始EPWM GPIO*/</div>
<div>InitEPwm1Gpio();</div>
<div>/*EQEP1引脚配置*/</div>
<div>InitEQep1Gpio();</div>
<div>/*初始化LED配置,用于指示实际转速是否到达给定转速*/</div>
<div>InitLED();</div>
<div>/*关中断*/</div>
<div>InitPieCtrl();</div>
<div>/*清中断*/</div>
<div>IER = 0x0000;</div>
<div>IFR = 0x0000;</div>
<div>/*初始化PIE中断向量表*/</div>
<div>InitPieVectTable();</div>
<div>/*定时器配置*/</div>
<div>Timer0_init();</div>
<div>EALLOW;</div>
<div>/*将timer0_ISR入口地址赋给TINT0,执行M法、T法测速切换中断服务程序*/</div>
<div>PieVectTable.TINT0 = &timer0_ISR;</div>
<div>EDIS;</div>
<div>/*电机转速初始化*/</div>
<div>MotorSpeed_init();</div>
<div>EALLOW;</div>
<div>/*禁用TBCLK同步,允许EPWM初始化配置*/</div>
<div>SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;</div>
<div>EDIS;</div>
<div>/*配置epwm1,用于模拟编码器旋转*/</div>
<div>EPWM1_Config();</div>
<div>EALLOW;</div>
<div>/*使能TBCLK同步,EPWM配置功能起作用*/</div>
<div>SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;</div>
<div>EDIS;</div>
<div>/*EQEP脉冲捕获配置*/</div>
<div>EQEP_pulseCap();</div>
<div>/*使能打开相应的CPU IER中断*/</div>
<div>IER |= M_INT1;</div>
<div>/*使能打开相应的PIE IER中断*/</div>
<div>PieCtrlRegs.PIEIER1.bit.INTx7 = 1;</div>
<div>/*使能打开全局中断*/</div>
<div>EINT;</div>
<div>while(1)</div>
<div>{}</div>
<div>return 0;</div>
<div>}</div>
<div>A\B\C三个相位如下图:</div>
<div></div>
<div>CDK上开发QEP测速程序,其编译结果为:</div>
<div></div>
<div>编译通过后,就可以开始调试了,其中M法测速调试结果如下:</div>
<div></div>
<div>T法测速调试结果如下:</div>
<div></div>
<div>所捕获的光电编码器QEP正交脉冲波形为</div>
<div></div>
<div> </div>
<div> </div>
<!--importdoc--></div>
<div>
<div>
<p><!--importdoc--></p>
</div>
</div>
<p>T法和M法主要的区别是什么</p>
<p>后续更新测量与FPGA监测方法</p>
页:
[1]