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

【电机控制】手把手一起玩转电机库SDK  

[复制链接]
努力的人 发布时间:2017-8-28 13:56
相关阅读:
电机培训 - 三个任务主函数及中断程序
电机培训 - 让你可以深入研究的PMSM/BLDC文档

PS:如果大家觉得帖子还可以的话,请到社区之星评选为我投出你宝贵的一票谢谢
点击进入投票
很高兴参加了ST的电机控制培训,先上几张图,我也悄悄地在提问窗口回复了坛友的问题
1.jpg


2.jpg

ST研讨会.jpg
下面开始步入正题吧!我的主函数程序下载 main.rar (3.98 KB, 下载次数: 111)
收藏 10 评论49 发布时间:2017-8-28 13:56

举报

49个回答
努力的人 回答时间:2017-8-31 10:33:33
donatello1996 发表于 2017-8-30 23:35
对了楼主知不知道在FOC那个例程里面监测电机转速和VBUS电压是哪个函数啊? ...

1.jpg
母线电压是ADC采样的
所有的函数都在这里,你自己查 STM32 FOC PMSM FW library developer Help file.chm (1.14 MB, 下载次数: 71)
努力的人 回答时间:2017-8-28 13:57:18
本帖最后由 努力的人 于 2017-8-28 15:19 编辑

二、TASK1 5s转动、5s停止       

    首先上传一下源代码,因为systick的500us的定时与SDK中一些任务的处理速度相关,这里我觉得还是不要修改定时时间比较好,我的代码如下:
说明:在main.c中定义uint16_t mytime; 在stm32f30x_it.c中定义extern uint16_t mytime;5S就是10000*500us,所以就可以转5S停5S了
  1. //TASK1 源码
  2. /////main.c//////////////
  3. uint16_t mytime;
  4.   while(1)
  5.   {
  6.                 if(mytime==0)
  7.                 {
  8.                         MCI_ExecSpeedRamp(oMCI[0],3000/6,1000);
  9.                         MCI_StartMotor(oMCI[0]);
  10.                 }
  11.                 if(mytime==10000)
  12.                 {
  13.                         MCI_StopMotor(oMCI[0]);
  14.                 }

  15.    
  16.   }
  17. //stm32f30x_it.c
  18. extern uint16_t mytime;
  19. void SysTick_Handler(void)
  20. {
  21.   TB_Scheduler();
  22.         mytime++;
  23.         if(mytime == 20000)
  24.         {mytime=0;}
  25. }
复制代码

视频:



努力的人 回答时间:2017-8-28 13:57:36
本帖最后由 努力的人 于 2017-8-28 14:36 编辑

三、TASK2 PID参数的调试
    任务2的代码如下:
  1. //TASK2源码
  2.         static int16_t Speed_Kp,Speed_Ki;
  3.         static CPI oPItuning;
  4.         oPItuning = MCT_GetSpeedLoopPID(oMCT[0]); // ????PID???
  5.         Speed_Kp = PI_GetKP(oPItuning); // ????PID??
  6.         Speed_Ki = PI_GetKI(oPItuning);
  7.         PI_SetKP(oPItuning,Speed_Kp); // ??PID??
  8.         PI_SetKI(oPItuning,Speed_Ki);
复制代码
这里我们首先看一下原始PID参数的速度曲线,从图中我们可以看出转速的超调比较大,已经达到4000多转
原始PID.jpg    原来的PID参数.jpg
接着我们修改程序,将程序设成2倍的PI参数(左图)和0.5倍的PI参数(右图)
2倍PID参数.jpg    0.5倍PID参数.jpg
从图中可以看出,增大倍数的PID参数比减小的好,所以我们接下来将PI参数往大了调,分别作了2.2倍,2.5倍,2.9倍的速度曲线图
2.2倍PID参数.jpg
2.5倍PID参数.jpg
2.9倍PID参数.jpg
我们还想让超调小一点,所以我减小了一点P参数,最终得到这个速度曲线,我们通过上位机可以看到调完的参数,最后将程序中默认的PID参数改成我们自己的。
最终确定的PID参数.jpg   
程序最终PID.jpg
努力的人 回答时间:2017-8-28 13:58:01
本帖最后由 努力的人 于 2017-8-28 15:07 编辑

TASK3
    首先还是上传一下源码
  1. //TASK3 源码
  2.         MCI_ExecSpeedRamp(oMCI[0],3000/6,1000);
  3.         MCI_StartMotor(oMCI[0]);
  4.         MCI_ExecSpeedRamp(oMCI[0],-3000/6,1000);
  5.         CSTM oSTM = MCT_GetStateMachine(oMCT[0]);
  6.         //STM_NextState(oSTM,STOP_IDLE);
  7.         STM_FaultProcessing(oSTM, MC_SPEED_FDBK, STOP_IDLE );
  8.         while(1)
  9.           {
  10.                
  11.                
  12.         Fault_Type = (uint16_t)STM_GetFaultState(oSTM);
  13.         if(Fault_Type == MC_SPEED_FDBK)
  14.         {
  15.                 //MCI_FaultAcknowledged(oMCI[0]);
  16.                 //MCI_ExecSpeedRamp(oMCI[0],MCI_GetLastRampFinalSpeed(oMCI[0]), 1000);
  17.                 //MCI_StartMotor(oMCI[0]);
  18.         }
复制代码
将程序写好后,下载到板子中,我们可以看到致故障的上位机界面
致故障.jpg
然后我们将下面的代码下进板子中
  1. //TASK3 源码
  2.         MCI_ExecSpeedRamp(oMCI[0],3000/6,1000);
  3.         MCI_StartMotor(oMCI[0]);
  4.         MCI_ExecSpeedRamp(oMCI[0],-3000/6,1000);
  5.         CSTM oSTM = MCT_GetStateMachine(oMCT[0]);
  6.         //STM_NextState(oSTM,STOP_IDLE);
  7.         STM_FaultProcessing(oSTM, MC_SPEED_FDBK, STOP_IDLE );
  8.         while(1)
  9.           {
  10.                
  11.                
  12.         Fault_Type = (uint16_t)STM_GetFaultState(oSTM);
  13.         if(Fault_Type == MC_SPEED_FDBK)
  14.         {
  15.                 MCI_FaultAcknowledged(oMCI[0]);
  16.                 MCI_ExecSpeedRamp(oMCI[0],MCI_GetLastRampFinalSpeed(oMCI[0]), 1000);
  17.                 MCI_StartMotor(oMCI[0]);
  18.         }
复制代码
可以发现电机正常反转。
关于故障代码可以参考: 故障代码查询.jpg
关于至状态机故障和清除故障的程序,大家参考StateMachineClass.h
  1. /**
  2.   ******************************************************************************
  3.   * @file    StateMachineClass.h
  4.   * @author  STMicroelectronics - System Lab - MC Team
  5.   * @version 4.3.0
  6.   * @date    22-Sep-2016 15:29
  7.   * @brief   This file contains interface of StateMachine class      
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
  12.   *
  13.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14.   * You may not use this file except in compliance with the License.
  15.   * You may obtain a copy of the License at:
  16.   *
  17.   *        http://www.st.com/software_license_agreement_liberty_v2
  18.   *
  19.   * Unless required by applicable law or agreed to in writing, software
  20.   * distributed under the License is distributed on an "AS IS" BASIS,
  21.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22.   * See the License for the specific language governing permissions and
  23.   * limitations under the License.
  24.   *
  25.   ******************************************************************************
  26.   */

  27. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STATEMACHINECLASS_H
  29. #define __STATEMACHINECLASS_H

  30. /* Includes ------------------------------------------------------------------*/
  31. #include "MC_type.h"

  32. /** @addtogroup STM32_PMSM_MC_Library
  33.   * @{
  34.   */

  35. /** @addtogroup StateMachine
  36.   * @{
  37.   */

  38. /** @defgroup StateMachine_class_exported_constants StateMachine class exported constants
  39.   * @{
  40.   */


  41. /**
  42. * @}
  43. */

  44. /** @defgroup StateMachine_class_exported_types StateMachine class exported types
  45. * @{
  46. */


  47. /**
  48.   * @brief  Public StateMachine class definition
  49.   */
  50. typedef struct CSTM_t *CSTM;

  51. /**
  52. * @}
  53. */

  54. /** @defgroup StateMachine_class_exported_methods StateMachine class exported methods
  55.   * @{
  56.   */

  57. /**
  58.   * @brief  Creates an object of the class StateMachine.
  59.   * @param pStateMachineParams pointer to a StateMachine parameters structure.
  60.   * @retval CSTM new instance of StateMachine object.
  61.   */
  62. CSTM STM_NewObject(void);

  63. /**
  64.   * @brief  Initializes all the object variables, usually it has to be called
  65.   *         once right after object creation.
  66.   * @param this related object of class CSTM.
  67.   * @retval none.
  68.   */
  69. void STM_Init(CSTM this);

  70. /**
  71.   * @brief It submits the request for moving the state machine into the state
  72.   *        specified by bState (FAULT_NOW and FAUL_OVER are not handled by this
  73.   *        method). Accordingly with the current state, the command is really
  74.   *        executed (state machine set to bState) or discarded (no
  75.   *        state changes)
  76.   * @param this related object of class CSTM.
  77.   * @param bState New requested state
  78.   * @retval bool It returns TRUE if the state has been really set equal to
  79.   *              bState, FALSE if the request has been discarded
  80.   */
  81. bool STM_NextState(CSTM this, State_t bState);

  82. /**
  83.   * @brief It clocks both HW and SW faults processing and update the state
  84.   *        machine accordingly with hSetErrors, hResetErrors and present state.
  85.   *        Refer to State_t description for more information about fault states.
  86.   * @param this object of class CSTM
  87.   * @param hSetErrors Bit field reporting faults currently present
  88.   * @param hResetErrors Bit field reporting faults to be cleared
  89.   * @retval State_t New state machine state after fault processing
  90.   */
  91. State_t STM_FaultProcessing(CSTM this, uint16_t hSetErrors, uint16_t
  92.                                                                   hResetErrors);

  93. /**
  94.   * @brief  Returns the current state machine state
  95.   * @param  this object of class CSTM
  96.   * @retval State_t Current state machine state
  97.   */
  98. State_t STM_GetState(CSTM this);

  99. /**
  100.   * @brief It reports to the state machine that the fault state has been
  101.   *        acknowledged by the user. If the state machine is in FAULT_OVER state
  102.   *        then it is moved into STOP_IDLE and the bit field variable containing
  103.   *        information about the faults historically occured is cleared.
  104.   *        The method call is discarded if the state machine is not in FAULT_OVER
  105.   * @param this object of class CSTM
  106.   * @retval bool TRUE if the state machine has been moved to IDLE, FALSE if the
  107.   *        method call had no effects
  108.   */
  109. bool STM_FaultAcknowledged(CSTM this);

  110. /**
  111.   * @brief It returns two 16 bit fields containing information about both faults
  112.   *        currently present and faults historically occurred since the state
  113.   *        machine has been moved into state
  114.   * \n\link Fault_generation_error_codes Returned error codes are listed here \endlink
  115.   * @param this object of class CSTM.
  116.   * @retval uint32_t  Two 16 bit fields: in the most significant half are stored
  117.   *         the information about currently present faults. In the least
  118.   *         significant half are stored the information about the faults
  119.   *         historically occurred since the state machine has been moved into
  120.   *         FAULT_NOW state
  121.   * \n\link Fault_generation_error_codes Returned error codes are listed here \endlink
  122.   */
  123. uint32_t STM_GetFaultState(CSTM this);

  124. /**
  125.   * @}
  126.   */
  127.   
  128. /**
  129.   * @}
  130.   */

  131. /**
  132.   * @}
  133.   */

  134. #endif /* __STATEMACHINECLASS_H */

  135. /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
复制代码

状态机看这个图: 状态机.jpg



努力的人 回答时间:2017-8-28 13:58:15
开放性试验
反派小智 回答时间:2017-8-28 18:03:16
学习了,谢谢分享
epochal 回答时间:2017-8-29 06:51:01
学习!!!
携手未来 回答时间:2017-8-29 09:17:54
看看,学习下。
哈哈先生105 回答时间:2017-8-29 21:38:06
厉害
donatello1996 回答时间:2017-8-30 20:53:20
看了楼主的帖子学到了不少东西
12345下一页

所属标签

STM32团队

意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM® Cortex®-M0、M0+、M3、M4、M33、M7及A7内核并具备丰富外设选择的32位微控制器及微处理器


最新内容

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版