Compiles, and motor driver shields work individually--but not together

In summary, the conversation discusses the use of a debugger and the process of commenting and uncommenting parts of code in the Mbed platform. It also mentions the availability of a Hello World program on the Mbed website and how it can be used in the online IDE. The conversation then delves into the initialization parameters and components of the Motor Control Expansion Board, as well as the SPI bus. The issue of the motors not moving when both lines of code are loaded onto the board is also mentioned.
  • #1
adamaero
109
1
TL;DR Summary
I'm using an STM32F767 MCU along with two shields: IHM02A1 dual stepper motor driver.
I don't have a debugger yet, but my company is getting one...

In the mean time, I've been un/commenting out parts of Mbed's code. Their Hello World program is available from this website, and it can be used directly in their online IDE by clicking "Import Program": https://os.mbed.com/components/X-NUCLEO-IHM03A1/
Code:
#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); 
        
}

That's a minimum reproducible example of the full program. If you want to try it out yourself, simply copy/paste it into main.cpp (in the online IDE noted above).

Everything complies, no warnings. Either of the lines below (with their matching pointers and such) works by moving the motors. I.e., motorstwo[x] and motors[x] both work out on their own. But when both lines are loaded unto the board...nothing works, the motors do not move. The steppers don't even have a very soft sound coming from them.

Code:
    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);

Why can't these two lines be uploaded together? How can this be fixed? Thanks.
 
Technology news on Phys.org

1. How do compilers and motor driver shields work individually?

Compilers are software programs that translate human-readable code into machine-readable code. They are used to convert high-level programming languages, such as C++ or Java, into low-level instructions that can be understood by the computer. On the other hand, motor driver shields are hardware components that control the speed and direction of DC motors. They typically have their own microcontroller and can be programmed to receive commands from a microcontroller or a computer.

2. Why do compilers and motor driver shields not work together?

The main reason why compilers and motor driver shields may not work together is that they use different languages and protocols to communicate with the computer. Compilers use programming languages, while motor driver shields use microcontroller languages. Thus, they may not be compatible with each other and cannot communicate effectively.

3. Can compilers and motor driver shields be used together?

Yes, compilers and motor driver shields can be used together with the proper setup. The key is to make sure that the language used by the compiler is compatible with the language used by the motor driver shield. This can be achieved by using a microcontroller that supports both languages, or using an interface between the two components.

4. What is an interface and how does it help compilers and motor driver shields work together?

An interface is a hardware component or software program that acts as a bridge between two different systems. In the case of compilers and motor driver shields, an interface can translate the commands from the compiler into a language that the motor driver shield can understand. This allows the two components to communicate and work together effectively.

5. Are there any other factors that may affect the compatibility of compilers and motor driver shields?

Yes, there are other factors that may affect the compatibility of compilers and motor driver shields. These include the hardware and software specifications of both components, the type of microcontroller used, and any additional features or functionalities that may be required for the system to work. It is important to carefully research and select compatible components when working with compilers and motor driver shields.

Similar threads

  • Mechanical Engineering
Replies
2
Views
7K
Back
Top