查看: 1486|回复: 0

[评测分享] 【灵动Motor-DK电机控制板】尝试带霍尔的FOC电机控制

[复制链接]
  • TA的每日心情
    奋斗
    昨天 10:30
  • 签到天数: 2095 天

    连续签到: 177 天

    [LV.Master]伴坛终老

    发表于 2023-7-30 23:33:17 | 显示全部楼层 |阅读模式
    分享到:
          由于此次底板的电压输入范围在18V~30V,推荐使用24V配24V电机,手头暂时没有合适的电机配套组件,只有一个12V并支持Hall的尼得科无刷直流电机,而根据从灵动微官方获取的SDK中,如需给板子直接上12V直流电让其工作正常,需要将U1拆除,并撤掉JP2上的跳线帽。但这样做的风险比较大,搞不好U1会因为拆焊而报废。
    供电电路.png
          此次尝试使用官方提供的“MM32SPIN0230_HALL_FOC_2R_V_1.0”Demo工程来验证是否能使用12V正常驱动手头这个直流电机。这个直流电机的大致参数如下:
    电机参数.jpg
          某宝上还提供了详细的接线示意图,对照一番,与此次的“Motor-DK电机控制板”接口分布相一致。
    实物图.jpg
    接线示意图.jpg
        根据电机底板上的PCB丝印,可以将直流电机按照线序,正确连接到板子上。
    连线.jpg
          工程中的源码也是针对Mini型开发板的,因此需要注意LED管脚定义,由于底板是通用的接口,因此其它地方无需变动,编译完成后,直接下载到开发板中,结果电机没有任何反应。这可能还是因为供电不符合18V~30V的要求,看到其它坛友已通过该例程正常驱动24V电流电机了。工程部分源码提供如下:
    1. #include "board.h"
    2. #include "drv_inc.h"
    3. #include "parameter.h"
    4. #include "user_function.h"

    5. void Bsp_Op_Init(void)
    6. {
    7.     GPIO_InitTypeDef GPIO_InitStructure;
    8.     GPIO_StructInit(&GPIO_InitStructure);
    9.     /* GPIO Ports Clock Enable */
    10.     RCC_AHBPeriphClockCmd(OPAMP_GPIO_CLK, ENABLE);

    11.               /*Configure GPIO pin : OPAMP1_Pin */
    12.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AIN;

    13.     GPIO_InitStructure.GPIO_Pin     = OPAMP1_INM_PIN;
    14.     GPIO_Init(OPAMP1_INM_PORT, &GPIO_InitStructure);

    15.     GPIO_InitStructure.GPIO_Pin     = OPAMP1_INP_PIN;
    16.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AIN;

    17.     GPIO_Init(OPAMP1_INP_PORT, &GPIO_InitStructure);
    18.   
    19.           /*Configure GPIO pin : OPAMP2_Pin */
    20.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AIN;

    21.     GPIO_InitStructure.GPIO_Pin     = OPAMP2_INM_PIN;
    22.     GPIO_Init(OPAMP2_INM_PORT, &GPIO_InitStructure);

    23.     GPIO_InitStructure.GPIO_Pin     = OPAMP2_INP_PIN;
    24.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AIN;

    25.     GPIO_Init(OPAMP2_INP_PORT, &GPIO_InitStructure);
    26. }

    27. void Bsp_Adc_Init(void)
    28. {
    29.         GPIO_InitTypeDef GPIO_InitStructure;
    30.     GPIO_StructInit(&GPIO_InitStructure);
    31.        
    32.     /* ADC Clock Enable */
    33.     RCC_AHBPeriphClockCmd(ADC_GPIO_CLK, ENABLE);
    34.     /*Configure ADC pin  */
    35.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AIN;

    36.     GPIO_InitStructure.GPIO_Pin     = VR_PIN;
    37.     GPIO_Init(VR_PORT, &GPIO_InitStructure);

    38.     GPIO_InitStructure.GPIO_Pin     = VBUS_PIN;
    39.     GPIO_Init(VBUS_PORT, &GPIO_InitStructure);

    40.     GPIO_InitStructure.GPIO_Pin     = IR_V_PIN;
    41.     GPIO_Init(IR_V_PORT, &GPIO_InitStructure);

    42.     GPIO_InitStructure.GPIO_Pin     = IR_U_PIN;
    43.     GPIO_Init(IR_U_PORT, &GPIO_InitStructure);
    44. }

    45. void Bsp_Comp_Init(void)
    46. {
    47.     GPIO_InitTypeDef GPIO_InitStructure;
    48.     GPIO_StructInit(&GPIO_InitStructure);
    49.        
    50.     /* COMP Clock Enable */
    51.     RCC_AHBPeriphClockCmd((COMP_GPIO_CLK), ENABLE);

    52.     GPIO_InitStructure.GPIO_Pin = COMP_INP_PIN;
    53.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    54.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_High;
    55.     GPIO_Init(COMP_INP_PORT, &GPIO_InitStructure);
    56. }

    57. void Bsp_Led_Init(void)
    58. {
    59.     GPIO_InitTypeDef GPIO_InitStructure;
    60.        
    61.     GPIO_StructInit(&GPIO_InitStructure);
    62.        
    63.           /* LED Clock Enable */
    64.     RCC_AHBPeriphClockCmd(LED_RCC_CLOCKGPIO, ENABLE);
    65.        
    66.     /*Configure GPIO pin : LED_Pin */
    67.     GPIO_InitStructure.GPIO_Pin     =  LED1_PIN;
    68.     GPIO_InitStructure.GPIO_Speed   = GPIO_Speed_High;
    69.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_Out_PP;
    70.     GPIO_Init(LED1_PORT, &GPIO_InitStructure);
    71. }

    72. void Bsp_Hall_Init(void)
    73. {
    74.     GPIO_InitTypeDef GPIO_InitStructure;
    75.        
    76.     GPIO_StructInit(&GPIO_InitStructure);
    77.        
    78.         /* HALL Clock Enable */
    79.     RCC_AHBPeriphClockCmd(HALL_RCC_CLOCKGPIO, ENABLE);
    80.        
    81.     /*Configure GPIO pin : HALL_Pin */
    82.     GPIO_InitStructure.GPIO_Pin     =  HALL_U_PIN;
    83.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_IPU;
    84.     GPIO_Init(HALL_U_PORT, &GPIO_InitStructure);
    85.        
    86.         GPIO_InitStructure.GPIO_Pin     =  HALL_V_PIN;
    87.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_IPU;
    88.     GPIO_Init(HALL_V_PORT, &GPIO_InitStructure);
    89.        
    90.         GPIO_InitStructure.GPIO_Pin     =  HALL_W_PIN;
    91.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_IPU;
    92.     GPIO_Init(HALL_W_PORT, &GPIO_InitStructure);
    93.        
    94.         GPIO_PinAFConfig(HALL_U_PORT, HALL_U_PIN_SOURCE, HALL_U_PIN_AF);         //TIM2_CH1
    95.         GPIO_PinAFConfig(HALL_V_PORT, HALL_V_PIN_SOURCE, HALL_V_PIN_AF);         //TIM2_CH2
    96.         GPIO_PinAFConfig(HALL_W_PORT, HALL_W_PIN_SOURCE, HALL_W_PIN_AF);         //TIM2_CH3
    97. }

    98. void Bsp_Pwm_Init(void)
    99. {
    100.     GPIO_InitTypeDef GPIO_InitStructure;
    101.     GPIO_StructInit(&GPIO_InitStructure);
    102.     /* PWM Clock Enable */
    103.     RCC_AHBPeriphClockCmd(BLDC1_GPIO_CLK, ENABLE);
    104.     /*Configure GPIO pin : PWM_Pin */
    105.     GPIO_InitStructure.GPIO_Pin     = BLDC1_UH_PIN;
    106.     GPIO_InitStructure.GPIO_Speed   = GPIO_Speed_High;
    107.     GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AF_PP;
    108.     GPIO_Init(BLDC1_UH_PORT, &GPIO_InitStructure);

    109.     GPIO_InitStructure.GPIO_Pin = BLDC1_VH_PIN;
    110.     GPIO_Init(BLDC1_VH_PORT, &GPIO_InitStructure);

    111.     GPIO_InitStructure.GPIO_Pin = BLDC1_WH_PIN;
    112.     GPIO_Init(BLDC1_WH_PORT, &GPIO_InitStructure);

    113.     GPIO_InitStructure.GPIO_Pin = BLDC1_UL_PIN;
    114. #if PWM_L_USE_IO
    115.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    116. #endif
    117.     GPIO_Init(BLDC1_UL_PORT, &GPIO_InitStructure);

    118.     GPIO_InitStructure.GPIO_Pin = BLDC1_VL_PIN;
    119.     GPIO_Init(BLDC1_VL_PORT, &GPIO_InitStructure);

    120.     GPIO_InitStructure.GPIO_Pin = BLDC1_WL_PIN;
    121.     GPIO_Init(BLDC1_WL_PORT, &GPIO_InitStructure);
    122.     /*selects the pin to used as Alternate function of PWM*/
    123.     GPIO_PinAFConfig(BLDC1_UH_PORT, BLDC1_UH_PIN_SRC, BLDC1_UH_PIN_AF);
    124.     GPIO_PinAFConfig(BLDC1_VH_PORT, BLDC1_VH_PIN_SRC, BLDC1_VH_PIN_AF);
    125.     GPIO_PinAFConfig(BLDC1_WH_PORT, BLDC1_WH_PIN_SRC, BLDC1_WH_PIN_AF);

    126. #if PWM_L_USE_TIM
    127.     GPIO_PinAFConfig(BLDC1_UL_PORT, BLDC1_UL_PIN_SRC, BLDC1_UL_PIN_AF);
    128.     GPIO_PinAFConfig(BLDC1_VL_PORT, BLDC1_VL_PIN_SRC, BLDC1_VL_PIN_AF);
    129.     GPIO_PinAFConfig(BLDC1_WL_PORT, BLDC1_WL_PIN_SRC, BLDC1_WL_PIN_AF);
    130. #endif
    131. #if PWM_L_USE_IO
    132.     GPIO_ResetBits(BLDC_UL_PORT, BLDC_UL_PIN);
    133.     GPIO_ResetBits(BLDC_VL_PORT, BLDC_VL_PIN);
    134.     GPIO_ResetBits(BLDC_WL_PORT, BLDC_WL_PIN);
    135. #endif
    136. }

    137. void Bsp_Gpio_Init(void)
    138. {
    139.     Bsp_Op_Init();
    140.     Bsp_Led_Init();
    141.         Bsp_Hall_Init();
    142.     Bsp_Adc_Init();
    143.     Bsp_Comp_Init();
    144.     Bsp_Pwm_Init();
    145. }

    146. void Board_ADC_Init(void)
    147. {
    148.     /*ADC  RANK Array*/
    149.     ADC_Channel_TypeDef sUserAdc1Channel[4];

    150.     /* Configure the ADC RANK Sequence*/
    151.     sUserAdc1Channel[0].u8Rank = IR_U_RANK;
    152.     sUserAdc1Channel[0].sAdcChannel = IR_U_CHANNEL;
    153.     sUserAdc1Channel[0].pNext = &sUserAdc1Channel[1];
    154.        
    155.     sUserAdc1Channel[1].u8Rank = IR_V_RANK;
    156.     sUserAdc1Channel[1].sAdcChannel = IR_V_CHANNEL;
    157.     sUserAdc1Channel[1].pNext = &sUserAdc1Channel[2];
    158.        
    159.     sUserAdc1Channel[2].u8Rank = VBUS_RANK;
    160.     sUserAdc1Channel[2].sAdcChannel = VBUS_CHANNEL;
    161.     sUserAdc1Channel[2].pNext = &sUserAdc1Channel[3];
    162.        
    163.     sUserAdc1Channel[3].u8Rank = VR_RANK;
    164.     sUserAdc1Channel[3].sAdcChannel = VR_CHANNEL;
    165.     sUserAdc1Channel[3].pNext = NULL;
    166.        
    167.         /* Select the ADC external trigger source of the ADC is T1_CC5*/
    168.     Drv_Adc_Basic_Init(ADC1, ADC_ExtTrig_T1_CC4);
    169.      /* Select the ADC sample time*/
    170.     Drv_Adc_Channel_Init(ADC1, sUserAdc1Channel, ADC_SampleTime_2_5);

    171.     ADC_Cmd(ADC1, ENABLE);
    172. }

    173. volatile COMP_TypeDef *pComp;

    174. void Board_Comp_Init(void)
    175. {
    176.     COMP_Input_TypeDef sUserCompInput;
    177.           /* Select the inverting input of the comparator */
    178.     sUserCompInput.sCompInvertingInput = COMP_INVERTING;
    179.           /* Select the non inverting input of the comparator*/
    180.     sUserCompInput.sCompNonInvertingInput = COMP_NON_INVERTING;
    181.           /* Select comparator external reference voltage */
    182.     sUserCompInput.u8CompCrvSelect = COMP_CRV_VOLTAGE_SELECT;
    183.           /* Initializes the COMP according to the specified parameters in the COMP_Input_TypeDef */
    184.     Drv_Comp_Init(&sUserCompInput);
    185. }

    186. void Board_Opamp_Init(void)
    187. {
    188.          /* op-amp Clock Enable */
    189.     RCC_APB1PeriphClockCmd(RCC_APB1ENR_OPA1_Msk, ENABLE);
    190.     RCC_APB1PeriphClockCmd(RCC_APB1ENR_OPA2_Msk, ENABLE);
    191.     /*Enable the specified OPAMP peripheral*/
    192.     OPAMP_Cmd(OPAMP1,ENABLE);
    193.     OPAMP_Cmd(OPAMP2,ENABLE);
    194. }

    195. void Peripheral_Init(void)
    196. {
    197.     Board_ADC_Init();
    198.     Board_Comp_Init();
    199.     Board_Opamp_Init();
    200.         Drv_Hall_Init(TIM2_PRIOD, TIM2_PSC_LOAD);
    201.     Drv_Pwm_Init(TIM1, PWMPERIOD, DEAD_TIME);
    202.     Drv_Iwdg_Init();
    203.        
    204.         /*Initialize divider*/
    205.     Drv_Hwdiv_Init();
    206.        
    207.         /** Enable the TIM1 */
    208.     TIM_Cmd(TIM1, ENABLE);
    209. }
    复制代码
    1. #ifndef __BOARD_H
    2. #define __BOARD_H

    3. /** Files includes */
    4. #include <stdio.h>
    5. #include "mm32_device.h"
    6. #include "hal_conf.h"

    7. #define SYSTICK_INTERRUPT           (1)
    8. #define TIM1_UPDATE_INTERRUPT       (2)
    9. #define ADC1_INTERRUPT              (0)

    10. /** ADC interface */
    11. #define IR_U_RANK                   (0)
    12. #define IR_U_CHANNEL                ADC_Channel_5

    13. #define IR_V_RANK                   (1)
    14. #define IR_V_CHANNEL                ADC_Channel_4

    15. #define VBUS_RANK                   (2)
    16. #define VBUS_CHANNEL                ADC_Channel_1

    17. #define VR_RANK                     (3)
    18. #define VR_CHANNEL                  ADC_Channel_0  

    19. #define ADC_GPIO_CLK               (RCC_AHBENR_GPIOA_Msk | RCC_AHBENR_GPIOB_Msk)

    20. #define VR_PORT                     GPIOA
    21. #define VR_PIN                      GPIO_Pin_1

    22. #define VBUS_PORT                   GPIOA
    23. #define VBUS_PIN                    GPIO_Pin_2

    24. #define IR_U_PORT                   GPIOB
    25. #define IR_U_PIN                    GPIO_Pin_0

    26. #define IR_V_PORT                   GPIOA
    27. #define IR_V_PIN                    GPIO_Pin_5

    28. /** COMP interface */
    29. #define COMP_NUMBER                 COMP1
    30. #define COMP_NON_INVERTING          COMP_NonInvertingInput_IO3                                      /** for PA4 */

    31. #define COMP_INVERTING              COMP_InvertingInput_IO3//COMP_InvertingInput_CRV
    32. #define COMP_CRV_VOLTAGE_SELECT     30// means: (30+1)/64

    33. #define COMP_GPIO_CLK               (RCC_AHBENR_GPIOA_Msk)

    34. #define COMP_INP_PORT               GPIOB
    35. #define COMP_INP_PIN                GPIO_Pin_0

    36. /** OPAMP interface */
    37. #define OPAMP_GPIO_CLK              (RCC_AHBENR_GPIOA_Msk | RCC_AHBENR_GPIOB_Msk)
    38. #define OPAMP1_INM_PORT             GPIOA
    39. #define OPAMP1_INM_PIN              GPIO_Pin_7
    40. #define OPAMP1_INP_PORT             GPIOA
    41. #define OPAMP1_INP_PIN              GPIO_Pin_6
    42. #define OPAMP2_INM_PORT             GPIOA
    43. #define OPAMP2_INM_PIN              GPIO_Pin_4
    44. #define OPAMP2_INP_PORT             GPIOA
    45. #define OPAMP2_INP_PIN              GPIO_Pin_3

    46. /** LED interface */
    47. #define LED_RCC_CLOCKGPIO           (RCC_AHBENR_GPIOB_Msk)

    48. #define LED1_PORT                   GPIOB
    49. #define LED1_PIN                    GPIO_Pin_9
    50. #define LED1_PIN_SOURCE             GPIO_PinSource9

    51. #define LED1_ON()                   LED1_PORT->BRR = LED1_PIN
    52. #define LED1_OFF()                  LED1_PORT->BSRR = LED1_PIN
    53. #define LED1_TOGGLE()               LED1_PORT->ODR ^= LED1_PIN

    54. /** HALL interface */
    55. #define HALL_RCC_CLOCKGPIO          (RCC_AHBENR_GPIOA_Msk | RCC_AHBENR_GPIOB_Msk)

    56. #define HALL_U_PORT                      GPIOA
    57. #define HALL_U_PIN                      GPIO_Pin_9

    58. #define HALL_V_PORT                     GPIOA
    59. #define HALL_V_PIN                       GPIO_Pin_8

    60. #define HALL_W_PORT                       GPIOB
    61. #define HALL_W_PIN                        GPIO_Pin_2

    62. #define HALL_U_PIN_SOURCE                GPIO_PinSource9
    63. #define HALL_V_PIN_SOURCE                 GPIO_PinSource8
    64. #define HALL_W_PIN_SOURCE                 GPIO_PinSource2

    65. #define HALL_U_PIN_AF                      GPIO_AF_0
    66. #define HALL_V_PIN_AF                      GPIO_AF_0
    67. #define HALL_W_PIN_AF                      GPIO_AF_0

    68. /** PWM interface */
    69. #define PWM_L_USE_IO   0
    70. #define PWM_L_USE_TIM  1

    71. #define BLDC1_GPIO_CLK               (RCC_AHBENR_GPIOA_Msk | RCC_AHBENR_GPIOB_Msk)

    72. #define BLDC1_UH_PORT                GPIOB
    73. #define BLDC1_UH_PIN                 GPIO_Pin_7
    74. #define BLDC1_VH_PORT                GPIOB
    75. #define BLDC1_VH_PIN                 GPIO_Pin_5
    76. #define BLDC1_WH_PORT                GPIOB
    77. #define BLDC1_WH_PIN                 GPIO_Pin_3

    78. #define BLDC1_UL_PORT                GPIOB
    79. #define BLDC1_UL_PIN                 GPIO_Pin_6
    80. #define BLDC1_VL_PORT                GPIOB
    81. #define BLDC1_VL_PIN                 GPIO_Pin_4
    82. #define BLDC1_WL_PORT                GPIOA
    83. #define BLDC1_WL_PIN                 GPIO_Pin_15

    84. #define BLDC1_UH_PIN_SRC             GPIO_PinSource7
    85. #define BLDC1_VH_PIN_SRC             GPIO_PinSource5
    86. #define BLDC1_WH_PIN_SRC             GPIO_PinSource3
    87. #define BLDC1_UL_PIN_SRC             GPIO_PinSource6
    88. #define BLDC1_VL_PIN_SRC             GPIO_PinSource4
    89. #define BLDC1_WL_PIN_SRC             GPIO_PinSource15

    90. #define BLDC1_UH_PIN_AF              GPIO_AF_5
    91. #define BLDC1_VH_PIN_AF              GPIO_AF_7
    92. #define BLDC1_WH_PIN_AF              GPIO_AF_7
    93. #define BLDC1_UL_PIN_AF              GPIO_AF_1
    94. #define BLDC1_VL_PIN_AF              GPIO_AF_7
    95. #define BLDC1_WL_PIN_AF              GPIO_AF_5

    96. extern void Bsp_Gpio_Init(void);
    97. extern void Peripheral_Init(void);

    98. #endif
    复制代码
        对照原理图上的管脚分布,也没发现什么不妥之处,后期有时间再在某宝上淘一个24V电机和直流可调适配器,试试这块电机驱动板的稳定性,同时学习学习Hall无刷电机驱动知识。
    原理图.png
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-5-3 10:35 , Processed in 0.117894 second(s), 17 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.