Program compiles, but second stepper motor driver shield does not move motors

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
I'm not quite sure if this is a programming question or better suited for this forum.
I'm using an STM32F767 MCU along with two shields: IHM02A1 dual stepper motor driver.

Here are steps I did for the IHM02A1s:
1. On both shields, unsolder SB34 and solder SB12.
2. Change this in main.cpp:​
dev_spi = new SPIClass(D11, D12, D13);
3. On the second (top) shield, unsolder SB23 and solder SB7. "So, when using more than one expansion board, the user must short a different solder bridge among SB7, SB8, SB9 and SB23, for each X-NUCLEO-IHM02A1."​
st.com/content/ccc/resource/technical/document/user_manual/group0/9c/49/e6/da/a3/75/48/b9/DM00237629/files/DM00237629.pdf/jcr:content/translations/en.DM00237629.pdf#page=11

4. Change:​
x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[2], &init[3], A4, A5, D4, D2, &dev_spi);

upload_2019-8-6_15-11-15.png

upload_2019-8-6_15-24-21.png
upload_2019-8-6_15-28-14.png
https://www.mouser.com/ds/2/389/x-nucleo-ihm02a1-954332.pdf#page=5

Mbed's online IDE does not have a debugger. I do not have one right now, but I will eventually...Keil uVision's 32 kB max project limit was :/

In short, the bottom shield works (moves motors). The top shield does not actually cause the motors to move.

The original program is here: os.mbed.com/components/X-NUCLEO-IHM02A1
(If you want, click "Import" on the Hello World example.)

I think this is the minimum reproducible form of it:
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_3 5000
/* Motor Control Expansion Board. */
XNucleoIHM02A1 *x_nucleo_ihm02a1;
/* 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[2], &init[3], A4, D2, D4, A2, &dev_spi);
//
/* Building a list of motor control components. */
L6470 **motors = x_nucleo_ihm02a1->get_components();
/* Setting the home position. */
motors[3]->set_home();
wait_ms(DELAY_1);
int position = motors[3]->get_position();
wait_ms(DELAY_1);
motors[3]->move(StepperMotor::BWD, STEPS_2);
motors[3]->wait_while_active();
wait_ms(DELAY_1);
position = motors[3]->get_position();
wait_ms(DELAY_1);
}
Here's the same version, just a bit easier to read:
https://github.com/adamaero/HelloWorld_IHM02A1mbed/blob/master/test.cpp
I could change the bottom two motors by changing motors[0] or motors[1], respectively.
So I would think getting the second motor on the second shield would be motors[3]...
 

Attachments

Last edited:

ci139

Joined Jul 11, 2016
725
i'm not SPI (aware) , but
? you list only single "init" → new XNucleoIHM02A1() ← call
? are the motors on the same SPI bus
- ? if so how you set their addresses (i'm also poor reading the type of diagrams ? the SB23 0 ?)
- ? if not how you it's done in single "init" call
 

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
i'm not SPI (aware) , but
- ? if so how you set their addresses (i'm also poor reading the type of diagrams ? the SB23 0 ?)
  • DO (data out), SDO (serial data out), MOSI (master out, slave in) all mean the same thing
  • DI (data in), SDI (serial data in), MISO (Master In, slave out) all mean the same
  • /CS (chip select), /SS (slave select), nCS, nSS all mean the same thing
    • Both ‘n’ and ‘/’ mean the signal is active low, not active high

The basic concept of SPI is that the master initiates every communication. Also one bit is sent by both the master and the slave on every clock edge.



Say you want to read two pieces of data from the slave, you can chain commands together.
MOSI [Read command 1] [Read command 2] [don’t care]
MISO [don’t care] [Response 1] [Response 2]
Note the slave can’t respond until it’s received all of command 1. In this example, command 2 provides the clock edges for the slave to respond with.
At the end, the master must clock an additional packet in (the don’t care above) to get the final response out.
Moving up the chain in complexity is independent slaves:



The clock, MOSI and MISO lines are shared. Each slave has a chip select (/SS) and responds when addressed.
Moving up the chain again is daisychained slaves.


If I want to talk to green, I feed one packet in to write the command. Green sends its response to blue, and blue sends its response to purple, and purple to master.
If you want, you can command all three at once, but you’ll need to send a bunch of don’t care data to flush the shift register and make sure Blue doesn’t try and use green’s response as a command.

Looking at the Nucleo schematic, you’ll notice L6470_1_SDO (Serial Data Out) is connected to L6470_0_SDI (Serial Data In). This is a daisy chain configuration. Also note how the bridging SB7 leads to the D2 pin on the board.


Looking at the part datasheet, it will start reading data when /CS is low, and will keep shifting data out until /CS is high.


By stacking a second board, this configuration results—it’s a combination of both the daisy chain and individually addressed version above:


Motor 1 and 2 move, so nCS1 is working.
Probing nSS2dd with the scope—should jump between 5v to 0v—which it does (~4 V)...

All four nCS's are connected in the middle (as shown on the right in red).

 
Last edited:

Ian Rogers

Joined Dec 12, 2012
666
Not sure I follow this.... You have initialised two motor definitions.. so you only have motor[0] and motor[1] with any info in them.
Surely you will need to select the second shield and initialise that in the same fashion? Or are you assuming the init() routine will fill both devices with the same information... The SPI init looks identical in your ifdef preprocessor statements..
 

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
Below gets the second board moving...so now I think I have to...
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_3 5000

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

/* 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);
                                        //                                  
    /* Building a list of motor control components. */
    L6470 **motors = x_nucleo_ihm02a1->get_components();

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


    motors[1]->move(StepperMotor::BWD, STEPS_2);
    motors[1]->wait_while_active();
    wait_ms(DELAY_1);
    position = motors[1]->get_position();
    wait_ms(DELAY_1);    

}
Now I think I just have to instantiate a second pointer....
 
Last edited:

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
Not sure I follow this.... You have initialised two motor definitions.. so you only have motor[0] and motor[1] with any info in them.
Surely you will need to select the second shield and initialise that in the same fashion?
Ya, so I think I will need to do something like this:
Code:
/* Variables -----------------------------------------------------------------*/

/* Motor Control Expansion Board. */
XNucleoIHM02A1*x_nucleo_ihm02a1;
XNucleoIHM02A1*x_nucleo_ihm02a1two;// @@ new
In void setup():
Code:
/* Initializing Motor Control Expansion Board. */
x_nucleo_ihm02a1 =newXNucleoIHM02A1(&L6470_init[0],  &L6470_init[1], A4, A5, D4, A2, dev_spi);
x_nucleo_ihm02a1two =newXNucleoIHM02A1(&L6470_init[2],&L6470_init[3], A4, A5, D4, D2, dev_spi); // @@ newer

motors = x_nucleo_ihm02a1->get_components();
motors = x_nucleo_ihm02a1two->get_components();// @@ new
 

Ian Rogers

Joined Dec 12, 2012
666
You have two shields.. Each with a dual motor connection.

so there has to be two inits with the CS for each

so.
DevSPI dev_spi(D11, D12, D13); is for the one on pin 13
DevSPI dev_spi(D11, D12, D3); is for the one on pin 3

Then..
L6470_init_t init[L6470DAISYCHAINSIZE] = { …. }; needs to be initialised on CS 13 AND!! another has to be initialised on CD 3..

When you use them read the docs that come with the SPI as I think you can send DevSPI dev_spi() with only two parameters..
Then you can control the two CS pins independently..

BUT!!! I don't know enough about this "Daisychainedsize" business! If both shields are on the same CS pin then you'll need to show the datasheet for that shield as you may need 4 motor inits and not two...
 

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
You have two shields.. Each with a dual motor connection.

so there has to be two inits with the CS for each

so.
DevSPI dev_spi(D11, D12, D13); is for the one on pin 13
DevSPI dev_spi(D11, D12, D3); is for the one on pin 3

Then..
L6470_init_t init[L6470DAISYCHAINSIZE] = { …. }; needs to be initialised on CS 13 AND!! another has to be initialised on CD 3..

When you use them read the docs that come with the SPI as I think you can send DevSPI dev_spi() with only two parameters..
Then you can control the two CS pins independently..

BUT!!! I don't know enough about this "Daisychainedsize" business! If both shields are on the same CS pin then you'll need to show the datasheet for that shield as you may need 4 motor inits and not two...
upload_2019-8-7_14-51-20.png

Why would a second clock pin need to be created?

The older model of this driver board (single instead of dual) does not have multiple with three single motors, three shields:
upload_2019-8-7_15-1-7.png


Short datasheet: mouser.com/ds/2/389/x-nucleo-ihm02a1-954332.pdf

Long datasheet: st.com/content/ccc/resource/technical/document/user_manual/group0/9c/49/e6/da/a3/75/48/b9/DM00237629/files/DM00237629.pdf/jcr:content/translations/en.DM00237629.pdf

Website for shield: os.mbed.com/components/X-NUCLEO-IHM02A1
 

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
Since I don't have a debugger yet, I un/commented a bunch of stuff out to "debug".

The issue is or at least starts here:
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);
Otherwise, the second pointer and such work on it's own. When I uncomment either of the lines above, no motors move (while still compiling).
 

ci139

Joined Jul 11, 2016
725
Yes, learning new devices and the coding takes looong nights working, if you get stuck with it , try out clearing out the peculiarities of each single task (though it's more simple for programming alone -- than when mixed with the embedded design)

so you might just consider logging your project of what was attempted and what resulted and how regular the particular response is to be considered !!! (so you wont go into cycle with it - and if the response is likely regular (the opt.-s how you confirmed such) )

there was a most absurd (compiler peculiarity related) "mistake" back at prev. millennium when (no matter the language spec. allowed the IF clause without ELSE) the thing didn't compile right when there were no "emtpy" ELSE included with one particular place in code !!!???
_____
about #12 -- basically i was a programmer - so even though i did comment my code - it appeared it was no good when trying to understand your own written code some 2 years later (because your thought pattern did not contain default associations it did back then (and those associations should have been commented also . . . )) . . .

. . . so (the) same (applies) for the hardware (i guess) --e.g.-- if you intensively modify your configuration you may go to "infinite loop" -- if you don't document what was already found out for some specific hardware(setup)-(control)code combination . . .

 
Last edited:

Ian Rogers

Joined Dec 12, 2012
666
Sorry.... Been on a short break... Back again... How are the shields connected to the MBED device? are they daisy chained ( ie.. one connected via the other one)?
 

Ian Rogers

Joined Dec 12, 2012
666
I don't see anything about daisy chaining... It talks about a hybrid situation but I can't follow it.. Personally I would put them on separate CS pins and treat them as singular pairs..
 

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
I don't see anything about daisy chaining... It talks about a hybrid situation but I can't follow it.. Personally I would put them on separate CS pins and treat them as singular pairs..
So how would that be different from what I already tried? The code above shows different CS pins.
 

Ian Rogers

Joined Dec 12, 2012
666
Look at post #8 It shows 1 SPI initialisation and 3 motor initialisations on the same bus.

If you are not daisychaining them the you will need to init 2 motors on the first shield and init 1 motor on the second shield..
Effectively..
init SPI
select cs1
init 2 motors
unselect cs1
select cs2
init 1 motor
unselect cs2
then....
move motor 1 or two with cs1 and move motor 3 with cs2

All I see from the first bit of code is 2 motors initialised on one shield.. I cannot replicate any of this as I haven't the hardware..
 

Thread Starter

Adam Uraynar

Joined Dec 21, 2015
67
Look at post #8 It shows 1 SPI initialisation and 3 motor initialisations on the same bus.

If you are not daisychaining them the you will need to init 2 motors on the first shield and init 1 motor on the second shield..
Effectively..
init SPI
select cs1
init 2 motors
unselect cs1
select cs2
init 1 motor
unselect cs2
then....
move motor 1 or two with cs1 and move motor 3 with cs2

All I see from the first bit of code is 2 motors initialised on one shield.. I cannot replicate any of this as I haven't the hardware..
This should make it simpler to see:
Code:
#include "mbed.h"
#include "DevSPI.h"
#include "XNucleoIHM02A1.h"

#define L6470_L1M1 (0u) // Index of shield1 motor1
#define L6470_L1M2 (1u) // Index of shield1 motor2

// #define L6470_L2M1 (0u) // Index of shield2 motor1
#define L6470_L2M2 (1u) // Index of shield2 motor2

#define MPR_1 4

#define STEPS_1 (200 * 128)
#define STEPS_2 (STEPS_1 * 2)

#define DELAY_1 1000
#define DELAY_2 2000
#define DELAY_3 5000

L6470 **motors1stLevel; // double pointer, to L6470 (chip) class
L6470 **motors2ndLevel;

XNucleoIHM02A1 *x_nucleo_ihm02a1one; // pointer to function
XNucleoIHM02A1 *x_nucleo_ihm02a1two;

int positionL1M1, positionL1M2, positionL2M1, positionL2M2 = -1;

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. */
    }
};

void startup();
void forward();
// void allTogether();

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_ihm02a1one = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);
    // x_nucleo_ihm02a1two = new XNucleoIHM02A1(&init[0], &init[1], A0, A1, D1, D2, &dev_spi); 
    x_nucleo_ihm02a1two = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, D2, &dev_spi);

  //                                                                                First shield works, motors move.
  //                                                                                Second shield (3rd motor) does nothing...
/**
 ******************************************************************************
  *
 * 
 * 
 * 
 *
 ******************************************************************************
 */
    /* Building a list of motor control components. */
    motors1stLevel = x_nucleo_ihm02a1one->get_components();
    motors2ndLevel = x_nucleo_ihm02a1two->get_components();

    // startup();

    forward();
//    allTogether();
       

} 
    /*----- Functions -----*/ /*----- -----*/ 

void startup()
{
    /*----- Initialization. -----*/
    motors1stLevel[L6470_L1M1]->set_home();
    motors1stLevel[L6470_L1M2]->set_home();
    // motors2ndLevel[L6470_L2M1]->set_home(); 
    motors2ndLevel[L6470_L2M2]->set_home();

    wait_ms(DELAY_1);

    positionL1M1 = motors1stLevel[L6470_L1M1]->get_position();
    positionL1M2 = motors1stLevel[L6470_L1M2]->get_position();
    // positionL2M1 = motors2ndLevel[L6470_L2M1]->get_position();
    positionL2M2 = motors2ndLevel[L6470_L2M2]->get_position();
     
    wait_ms(DELAY_1);   
}

void forward()
{
        motors1stLevel[L6470_L1M1]->move(StepperMotor::FWD, STEPS_1);
        motors1stLevel[L6470_L1M2]->move(StepperMotor::FWD, STEPS_1);
      wait_ms(DELAY_3);
        motors2ndLevel[L6470_L2M2]->move(StepperMotor::FWD, STEPS_1);    // There is no L2M1
        motors2ndLevel[L6470_L2M2]->move(StepperMotor::FWD, STEPS_1);
}
   
void allTogether()// right now. Over me. bum bum, batta bumm...He bad production He got walrus gumboot He got Ono sideboard He one spinal cracker He got feet down below his kneeieeieesss
{
//    for (int m = 0; m < L6470DAISYCHAINSIZE; m++) 
//        motors[m]->prepare_run(StepperMotor::BWD, 400);
//       
//    x_nucleo_ihm02a1->perform_prepared_actions();
//
//    wait_ms(DELAY_3);
}
 

Ian Rogers

Joined Dec 12, 2012
666
C:
[LIST=1]
[*]

[*]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. */
[*]    }
[/LIST]
MOTOR 3 ????
 
Top