首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译和SPI电机驱动器屏蔽单独工作--但不能一起工作。

编译和SPI电机驱动器屏蔽单独工作--但不能一起工作。
EN

Stack Overflow用户
提问于 2019-08-09 17:45:21
回答 1查看 545关注 0票数 1

我使用的STM32F767单片机连同两个屏蔽: IHM02A1双步进电机驱动器。我还没有调试器,但我的公司有一个.

同时,我一直没有/注释出Mbed的部分代码。他们的Hello程序可以从这个网站获得,可以通过点击"Import“:https://os.mbed.com/components/X-NUCLEO-IHM02A1/直接在他们的在线IDE中使用

代码语言:javascript
复制
#include "mbed.h"
#include "DevSPI.h"
#include "XNucleoIHM02A1.h"

#define MPR_1 4 /* Number of movements per revolution. */

#define STEPS_1 (200 * 128)   /* 1 revolution given a 200 steps motor configured at 1/128 microstep mode. */
#define STEPS_2 (STEPS_1 * 2)

/* Delay in milliseconds. */
#define DELAY_1 1000
#define DELAY_2 2000
#define DELAY_3 3000

/* Motor Control Expansion Board. */
XNucleoIHM02A1 *x_nucleo_ihm02a1;
XNucleoIHM02A1 *x_nucleo_ihm02a1two;

/* Initialization parameters of the motors connected to the expansion board. */
L6470_init_t init[L6470DAISYCHAINSIZE] = {
    /* First Motor. */
    {
        24.0,                          /* Motor supply voltage in V. */
        200,                           /* Min number of steps per revolution for the motor. */
        1.7,                           /* Max motor phase voltage in A. */
        3.06,                          /* Max motor phase voltage in V. */
        300.0,                         /* Motor initial speed [step/s]. */
        500.0,                         /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
        500.0,                         /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
        992.0,                         /* Motor maximum speed [step/s]. */
        0.0,                           /* Motor minimum speed [step/s]. */
        602.7,                         /* Motor full-step speed threshold [step/s]. */
        3.06,                          /* Holding kval [V]. */
        3.06,                          /* Constant speed kval [V]. */
        3.06,                          /* Acceleration starting kval [V]. */
        3.06,                          /* Deceleration starting kval [V]. */
        61.52,                         /* Intersect speed for bemf compensation curve slope changing [step/s]. */
        392.1569e-6,                   /* Start slope [s/step]. */
        643.1372e-6,                   /* Acceleration final slope [s/step]. */
        643.1372e-6,                   /* Deceleration final slope [s/step]. */
        0,                             /* Thermal compensation factor (range [0, 15]). */
        3.06 * 1000 * 1.10,            /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
        3.06 * 1000 * 1.00,            /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
        StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
        0xFF,                          /* Alarm conditions enable. */
        0x2E88                         /* Ic configuration. */
    },

    /* Second Motor. */
    {
        24.0,                           /* Motor supply voltage in V. */
        200,                           /* Min number of steps per revolution for the motor. */
        1.7,                           /* Max motor phase voltage in A. */
        3.06,                          /* Max motor phase voltage in V. */
        300.0,                         /* Motor initial speed [step/s]. */
        500.0,                         /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
        500.0,                         /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
        992.0,                         /* Motor maximum speed [step/s]. */
        0.0,                           /* Motor minimum speed [step/s]. */
        602.7,                         /* Motor full-step speed threshold [step/s]. */
        3.06,                          /* Holding kval [V]. */
        3.06,                          /* Constant speed kval [V]. */
        3.06,                          /* Acceleration starting kval [V]. */
        3.06,                          /* Deceleration starting kval [V]. */
        61.52,                         /* Intersect speed for bemf compensation curve slope changing [step/s]. */
        392.1569e-6,                   /* Start slope [s/step]. */
        643.1372e-6,                   /* Acceleration final slope [s/step]. */
        643.1372e-6,                   /* Deceleration final slope [s/step]. */
        0,                             /* Thermal compensation factor (range [0, 15]). */
        3.06 * 1000 * 1.10,            /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
        3.06 * 1000 * 1.00,            /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
        StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
        0xFF,                          /* Alarm conditions enable. */
        0x2E88                         /* Ic configuration. */
    }
};

int main()
{
    /* Initializing SPI bus. */
#ifdef TARGET_STM32F429
    DevSPI dev_spi(D11, D12, D13);

#else
    DevSPI dev_spi(D11, D12, D13);
#endif

    /* Initializing Motor Control Expansion Board. */
    x_nucleo_ihm02a1 =    new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, D2, &dev_spi);
    x_nucleo_ihm02a1two = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);  

    /* Building a list of motor control components. */
    L6470 **motors = x_nucleo_ihm02a1->get_components();
    L6470 **motorstwo = x_nucleo_ihm02a1two->get_components();

    /* Setting the home position. */
    //motorstwo[1]->set_home();
//    wait_ms(DELAY_1);
    int position = motorstwo[1]->get_position();
    wait_ms(DELAY_1);

//      motors[1]->move(StepperMotor::FWD, STEPS_2);
//      motors[0]->move(StepperMotor::FWD, STEPS_2);    
//    wait_ms(DELAY_2);
      motorstwo[1]->move(StepperMotor::FWD, STEPS_2);
      motorstwo[0]->move(StepperMotor::FWD, STEPS_2);

    position = motorstwo[1]->get_position();
    wait_ms(DELAY_1); 

}

这是整个程序的最低可重现性示例。如果您想自己尝试,只需将其复制/粘贴到main.cpp (在上面提到的在线IDE中)。

一切都符合,没有警告。下面的任何一条线(有匹配的指针等等)都是通过移动马达来工作的。也就是说,摩托车和摩托车都是靠自己的力量来完成的。但是当两条线都装到board...nothing工作时,马达就不动了。步行者甚至没有一个非常柔和的声音从他们。

代码语言:javascript
复制
x_nucleo_ihm02a1 =    new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, D2, &dev_spi);
x_nucleo_ihm02a1two = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);

为什么这两行不能上传到一起呢?怎么解决这个问题呢?

编辑

该类包含两个用于"XNucleoIHM02A1“的函数。有七个周长的那个是到dissect...the的第二个最后一个论点的声音被改变(ssel:)

查看Nucleo原理图,您会注意到L6470_1_SDO (串行数据输出)连接到L6470__SDI (Serial )。这是雏菊链的配置。还请注意桥接SB7如何引导到板上的D2引脚。

查看部分数据表,当/CS较低时,它将开始读取数据,并将一直将数据移出直到/CS高。

通过堆叠第二个板子,这个配置结果--它是上面的雏菊链和单独寻址版本的结合:

硬件文档

短数据表长数据表

EN

回答 1

Stack Overflow用户

发布于 2019-08-14 19:24:25

你说你有两个盾牌?每个盾牌上都有一个IHM02A1驱动程序?请详细说明..。

如果是这样的话,您可以使用相同的SPI总线,但您将需要一个单独的芯片选择线为每个屏蔽。

我不太喜欢Arduino用户,所以我不太熟悉他们的司机。我下载了这个示例项目并快速浏览了一下:

对于IHM02A1类,构造函数如下所示:

代码语言:javascript
复制
XNucleoIHM02A1(L6470_init_t *init_0, L6470_init_t *init_1, uint8_t flag_irq, uint8_t busy_irq, uint8_t standby_reset, uint8_t ssel, SPIClass *spi);

其中参数有以下描述:

代码语言:javascript
复制
/**
 * @brief Constructor.
 * @param init_0        pointer to the initialization structure of the first motor.
 * @param init_1        pointer to the initialization structure of the second motor.
 * @param flag_irq      pin name of the FLAG pin of the component.
 * @param busy_irq      pin name of the BUSY pin of the component.
 * @param standby_reset pin name of the STBY\RST pin of the component.
 * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
 * @param spi           SPI device to be used for communication.
 */

第六个参数是选择引脚。这是你必须为每个盾牌指定选择引脚的地方。

然后,您将需要类XNucleoIHM02A1的两个实例,每个屏蔽一个。这不是每台马达的一个实例。这个班已经为两台电动机做好了准备。

代码语言:javascript
复制
XNucleoIHM02A1 *x_nucleo_ihm02a1_shield1; // Class for shield 1
XNucleoIHM02A1 *x_nucleo_ihm02a1_shield2; // Class for shield 2

x_nucleo_ihm02a1_shield1 = new XNucleoIHM02A1(&init[0], &init[1], FLAG1, BUSY1, STBY_RST1, SS1, &dev_spi);
x_nucleo_ihm02a1_shield2 = new XNucleoIHM02A1(&init[0], &init[1], FLAG2, BUSY2, STBY_RST2, SS2, &dev_spi);

其中SS1和SS2是芯片选择引脚。注:您必须填写这些实际的引脚号码。

您还必须确保正确定义了其余的参数。您很可能需要单独的引脚为旗子,繁忙和STBY/RST为每个屏蔽。因此,我定义了参数FLAG1、FLAG2、BUSY1、BUSY2、STBY_RST1、STBY_RST2。注:您必须填写这些实际的引脚号码。

增编:

如果每个电机需要不同的参数,那么需要四种不同的init结构:

代码语言:javascript
复制
L6470_init_t init_shield1[L6470DAISYCHAINSIZE] = {...};
L6470_init_t init_shield2[L6470DAISYCHAINSIZE] = {...};

x_nucleo_ihm02a1_shield1 = new XNucleoIHM02A1(&init_shield1[0], &init_shield1[1], FLAG1, BUSY1, STBY_RST1, SS1, &dev_spi);
x_nucleo_ihm02a1_shield2 = new XNucleoIHM02A1(&init_shield2[0], &init_shield2[1], FLAG2, BUSY2, STBY_RST2, SS2, &dev_spi);

但是,如果所有的电机都有相同的参数和/或要求,那么您只需要一个init结构。

代码语言:javascript
复制
L6470_init_t init[L6470DAISYCHAINSIZE] = {...};

x_nucleo_ihm02a1_shield1 = new XNucleoIHM02A1(&init[0], &init[1], FLAG1, BUSY1, STBY_RST1, SS1, &dev_spi);
x_nucleo_ihm02a1_shield2 = new XNucleoIHM02A1(&init[0], &init[1], FLAG2, BUSY2, STBY_RST2, SS2, &dev_spi);

您需要为每个屏蔽调用"get_components“:

代码语言:javascript
复制
// For easier reading
#define L6470_S1M1 (0u) // Index of shield1 motor1
#define L6470_S1M2 (1u) // Index of shield1 motor2
#define L6470_S2M1 (0u) // Index of shield2 motor1
#define L6470_S2M2 (1u) // Index of shield2 motor2

L6470 **motors_shield1 = x_nucleo_ihm02a1_shield1->get_components();
L6470 **motors_shield2 = x_nucleo_ihm02a1_shield2->get_components();

然后,您以下列方式操作电机:

代码语言:javascript
复制
motors_shield1[L6470_S1M1]->set_home(); // Home motor1 on shield1
motors_shield1[L6470_S1M2]->set_home(); // Home motor2 on shield1
motors_shield2[L6470_S2M1]->set_home(); // Home motor1 on shield2
motors_shield2[L6470_S2M2]->set_home(); // Home motor2 on shield2
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57434935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档