你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

FOC中的PARK变换_TI和ST电机控制库的源码实现

[复制链接]
STMCU小助手 发布时间:2021-7-15 14:11
park变换
该变换将平衡两相正交平稳系统中的矢量变换为正交旋转坐标系。


数学公式:
2.png


跟着转子旋转的“d-q”坐标系成功把cos,sin正余弦信号转化线性的了。
theta角度是由位置传感器得到的已知变量。
3.png


TI的实现
也是很简单的两句计算,cos和sin(theta)是外部计算传入参数。对于三角函数,TI有自己的库去计算。
而cos和sin(theta)不止只有在park中使用,其他地方也会使用,在这函数中再计算一次,未免多花时间了。st的库即比较麻烦。
  1. <font face="微软雅黑" size="3">typedef struct {  _iq  Alpha;                  // Input: stationary d-axis stator variable
  2.                                   _iq  Beta;                 // Input: stationary q-axis stator variable
  3.                                   _iq  Angle;                // Input: rotating angle (pu)
  4.                                   _iq  Ds;                        // Output: rotating d-axis stator variable
  5.                                   _iq  Qs;                        // Output: rotating q-axis stator variable
  6.                                   _iq  Sine;
  7.                                   _iq  Cosine;          
  8.                                   } PARK;                   

  9. /*------------------------------------------------------------------------------
  10.         PARK Transformation Macro Definition
  11. ------------------------------------------------------------------------------*/
  12. #define PARK_MACRO(v)                                                                                        \
  13.                                                                                                                                 \
  14.         v.Ds = _IQmpy(v.Alpha,v.Cosine) + _IQmpy(v.Beta,v.Sine);        \
  15.     v.Qs = _IQmpy(v.Beta,v.Cosine) - _IQmpy(v.Alpha,v.Sine);
  16. </font>
复制代码


ST的库:
ST的代码写很“规矩”,一步一步的。有很多限幅检测。
在对theta求角度的查表法也绕了一下。解决浮点计算,统一后,全使用int型的。
  1. <font face="微软雅黑" size="3">typedef struct
  2. {
  3.   int16_t hCos;
  4.   int16_t hSin;
  5. } Trig_Components;

  6. typedef struct
  7. {
  8.   int16_t alpha;
  9.   int16_t beta;
  10. } alphabeta_t;

  11. typedef struct
  12. {
  13.   int16_t q;
  14.   int16_t d;
  15. } qd_t;

  16. __weak qd_t MCM_Park( alphabeta_t Input, int16_t Theta )
  17. {
  18.   qd_t Output;
  19.   int32_t d_tmp_1, d_tmp_2, q_tmp_1, q_tmp_2;
  20.   Trig_Components Local_Vector_Components;
  21.   int32_t wqd_tmp;
  22.   int16_t hqd_tmp;

  23.   // 传入theta 查表计算得到 cos和sin的值
  24.   Local_Vector_Components = MCM_Trig_Functions( Theta );

  25.   // 不保证溢出,先计算一次,然后各种限幅判断,最后再做IQ的赋值
  26.   /*No overflow guaranteed*/
  27.   // 计算 alpha*cos(theta)
  28.   q_tmp_1 = Input.alpha * ( int32_t )Local_Vector_Components.hCos;

  29.   /*No overflow guaranteed*/
  30.   // 计算 beta*sin(theta)
  31.   q_tmp_2 = Input.beta * ( int32_t )Local_Vector_Components.hSin;

  32.   /*Iq component in Q1.15 Format */
  33. #ifdef FULL_MISRA_C_COMPLIANCY
  34.   wqd_tmp = ( q_tmp_1 - q_tmp_2 ) / 32768;
  35. #else
  36.   /* WARNING: the below instruction is not MISRA compliant, user should verify
  37.     that Cortex-M3 assembly instruction ASR (arithmetic shift right) is used by
  38.     the compiler to perform the shift (instead of LSR logical shift right) */
  39.    
  40.   // IQ的计算,计算完了,去各种限幅。 右移15是sin和cos/32768得到真正的值,又回到16位以内
  41.   wqd_tmp = ( q_tmp_1 - q_tmp_2 ) >> 15;
  42. #endif

  43.   /* Check saturation of Iq */
  44.   if ( wqd_tmp > INT16_MAX )
  45.     hqd_tmp = INT16_MAX;
  46.   else if ( wqd_tmp < ( -32768 ) )
  47.     hqd_tmp = ( -32768 );
  48.   else
  49.     hqd_tmp = ( int16_t )( wqd_tmp );

  50.   Output.q = hqd_tmp;

  51.   if ( Output.q == ( int16_t )( -32768 ) )
  52.   {
  53.     Output.q = -32767;
  54.   }

  55.   /*No overflow guaranteed*/
  56.   d_tmp_1 = Input.alpha * ( int32_t )Local_Vector_Components.hSin;

  57.   /*No overflow guaranteed*/
  58.   d_tmp_2 = Input.beta * ( int32_t )Local_Vector_Components.hCos;

  59.   /*Id component in Q1.15 Format */
  60. #ifdef FULL_MISRA_C_COMPLIANCY
  61.   wqd_tmp = ( d_tmp_1 + d_tmp_2 ) / 32768;
  62. #else
  63.   /* WARNING: the below instruction is not MISRA compliant, user should verify
  64.     that Cortex-M3 assembly instruction ASR (arithmetic shift right) is used by
  65.     the compiler to perform the shift (instead of LSR logical shift right) */
  66.   wqd_tmp = ( d_tmp_1 + d_tmp_2 ) >> 15;
  67. #endif

  68.   /* Check saturation of Id */
  69.   if ( wqd_tmp > INT16_MAX )
  70.   {
  71.     hqd_tmp = INT16_MAX;
  72.   }
  73.   else if ( wqd_tmp < ( -32768 ) )
  74.   {
  75.     hqd_tmp = ( -32768 );
  76.   }
  77.   else
  78.   {
  79.     hqd_tmp = ( int16_t )( wqd_tmp );
  80.   }

  81.   Output.d = hqd_tmp;

  82.   if ( Output.d == ( int16_t )( -32768 ) )
  83.   {
  84.     Output.d = -32767;
  85.   }

  86.   return ( Output );
  87. }
  88. </font>
复制代码


1.png
收藏 评论0 发布时间:2021-7-15 14:11

举报

0个回答
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版