Weird Motor behaviour of hitting a wall

Hi All,

Let me go into the hardware first,

Microcontroller
STM32F446

Driver
Using the SimpleFOCShield V1.3.3

Motor
GM5208-12

The plan was to get 3 sets of motors running. So I use the SPI connector to get 3 sets of AS5048A. While the readings were weird at the start, I managed to solve that problem by changing some of the SPI modes settings.

Problem,

I tried using the find pole number example, however I got quite a bit of unrealistic numbers. The estimate is usually > 60. And expectedly, that example did not manage to turn the motors at all. When I try to use the open loop velocity example, the motor would turn at first, hit a ā€˜wallā€™, stops. then snap back to a ā€˜startingā€™ point, moves to the wall, and the action repeats. This happens for all velocities and pole numbers (1-8 & 11) that I tried.

As the application is suppose to drive at least 3 motors, Iā€™m using the bluepill setup example of connecting to the driver. Which, if Iā€™m correct, is to use the PWM pins of the stm32 to the PWM A, B & C connectors of the shield.

Has anyone had this problem and solve it?

Hi @Neuro,

Welcome to the forum!

I am not an expert and I do not know if this is going to solve your problem, but looking at the web, you are using the following motor, right?

Looking at the configuration: 12N14P, it looks like your motor should have 7 pole pairs.

But it looks like you already tried 7 pole pairs! But I will still suggest to check it agian with 7 pole pairs. Otherwise take an extra look at:

  • The wiring
  • This example code
  • I had a problem once that my motor was stuck in open loop mode because I called motor.loopFOC();

Greetings,

Wittecactus

@Wittecactus,

Thanks for replying.

Yes, the motor is correct.

the example code, weirdly, compiles with the following error,

OpenLoopMotorControl:15:36: error: ā€˜class Commanderā€™ has no member named ā€˜variableā€™
15 | void doTarget(char* cmd) { command.variable(&target_velocity, cmd); }
| ^~~~~~~~
exit status 1
ā€˜class Commanderā€™ has no member named ā€˜variableā€™

Iā€™m confused with this compiler error.

On the wiring, I noticed that there is quite a number of weird behaviours,

I tried changing the pwm pins and found a few combinations that does not move the motors are all. Then I read somewhere that the TIM1 should be used and used PA8, PA9, PA10, PA11, which just replicate the problem.

Iā€™m planning to using an arduino uno to see if the MCU is the issue here.

Hey @Neuro,

Welcome!

Iā€™ve got a few questions.
Did you solder the pin configuration on the bottom side of the board?
If youā€™re using the nucleo-64 stm32f466 then you can stack it on the arduino headers ,there should be no issues there :slight_smile:

The code in the example is failing because it was the dev branch code. Iā€™ll update the conversation. Basically just replace the function call variable with scalar. The name of the function has changed.

You can use any timer with owl outputs for stm32f466 MCUs.
If you have the nucleo-64 then you can use arduino pin numbers also no need for PAx, PBx, PCx

Hi Antun,

  1. Solder - I believe so. I have 3 atm. The current one that iā€™m using, I have set 9,10,11,8. This was influenced by the blue pill example. Also, due to the magnetic sensors using SPI and trying to set up 3 sensors, Iā€™m did not solder any other connections as they are not needed atm.

As Iā€™m planning to set up 3 motors, Iā€™m trying to avoid using the stacking method. In any case, as part of my debugging efforts, Iā€™m gg to solder the common 9,5,6,8 setting and use it with a spare arduino uno and see if the motor would spin correctly in a open loop.

Thanks for clarifying the compiler issue.

Will take note on the timer with owl outputs, thou not quite sure what that meant. Iā€™ll see if i can find out more on this.

I am using the nucleo-64, however, it is easier to use the PAx, PBx and PCx with the pinout diagram by ST.

Iā€™ll update again on the results with the arduino uno.

Thanks everyone for the advice!

Sorry about the confusion, my autocorrect is playing games with me. :smiley:

I meant pwm outputs not owl :smiley:

In stm32duino pins 13,12 and 11 are used for SPI initially.
If youā€™re using the spi sensor then youā€™ll not be able to use this driver pinout at the same time. But it should not be a problem for open-loops (because no sensor is used)

Did you connect the common ground?

Also which version of the shield do you have, what is the date on the bottom side?
Is it 11/2020 or 12/2020?

Hi Antun,

tbh, the SPI isnā€™t really an issue for pin space, I can use the SPI2 or 3 for that matter.

Yes, I believe I did connect the common ground.

I can confirm that all the shields are 12/2020

Updates,

Using the arduino uno, GM5208-12 and the SimpleFOC Shield 1.3.3, the motor moves as command when i change velocity using the example that Wittecactus suggested.

The difference bwt this and my problematic setup,

  • STM32F446re instead of Uno
  • Connects with jumper wires instead of stacking
  • Using the open loop velocity program from the examples in the arduino library instead of the one found on the website.

Iā€™m planning to do the following to eliminate issues one by one,

  1. try with stacking the working shield with the STM32 to determine if it is a MCU issue.
  2. try the working shield with the STM32 using jumper cables to determine if it is a jumper cable problem.

Thanks guys for the help!

** I can confirm that the STM32F446re is the problem. Using the working stack and code does not cause the motor to move correctly when used with the STM32F446re. It works fine with the Uno.I change some of the arduino settings and it works with the STM32F446 board now. Talk about weirdā€¦

1 Like

Hi All,

just to update on the situation after testing for a whole day.

Arduino uno with shield.
Works very well, with the AS5048a encoder and GM5208-12. In some instances the motor could move without supplying power to the driver, abit it moves poorly.

STM32F446re.
I can confirm that this MCU cause problems.
I have 2 pieces of the stm32 and both exhibit different behaviours.

Using the same driver and code as the Arduino uno uses the following happened,

First shield, can now move the motor in open loop. However, it is unable to read any SPI.

Second shield, can read multiple magnetic sensor readings correctly, however it is unable to move the motors.

For the testing, the following pins were used.

9,5,6,8 -> Pwma Pwmb Pwmc enable.

10 -> CS pin.

Looking for anyone with experience with STM32s. Is there some setting I need to set seperately for the STM32? Seeing that the arduino can move the Motor with the driver been supplied with power, Iā€™m suspecting the STM has lesser current in its pwm waves.

It should be no problem for the STM32 MCU to drive the L6234 driver on the SimpleFOC shield. Maybe @Antun_Skuric can confirm this, but the chip is 3.3V compatible, and the digital inputs only need 30ĀµA current.
Maybe the problem is with the MCUā€™s power supply? Are the GNDs of the SimpleFOC board and the MCU connected? Are your jumper cables good (loose cables are a problem, esp. for SPI)?

Hi,

Jumper cables are not the issue here as the shields are stacked to both types of MCU.

Also if one stm32 can read it, doesnā€™t makes sense if the other cannot even detect noise. (It display a single value that doesnā€™t change)

Iā€™m trying a buck converter for the stm32 as a E5V source. Letā€™s see what happens.

Thanks.

What is the board variant you have selected in arduino menu?
Is it the Generic_F446Rx board?. Also are you using new core or older (maple) core? You can tell by which board manager url you configured in Arduino preferences. The default behaviour e.g pinmap selection, depends on the board variant.

Focusing on stm32 spi. Which pins are you using for mosi, miso, Sclk, CS? I want the pin name.
SPI1 wants to use
MOSI - PA7
MISO - PA6
SCLK - PA5
CS - PA4

Other pins can sometimes be used but you need to check/set the peripheral pins

Hi @Owen_Williams ,

Nucleo-64
STM32F446RE

The SPI pins is as described in the pinout. PA5, PA6, PA7.
The 3 sensors uses different CS. PB8 PC9 PB9.
This works on 1 board now. The other board just refuse to work and keep displaying 6.28.

Iā€™m more pleplexed by the PWMs. The current setting uses 9,5,6,8. i.e. PC7, PB4, PB10, PA9.
One board can move the motor in this setting, the other board canā€™t.

i.e.
board 1) -> can move motor, cannot use SPI.
board 2) -> cannot move motor can use SPI.

Codes are the same. Driver is the same. Wiring is the same. Arduino Uno uses the same driver and works perfectly.

Weird behaviour,
The board take cannot move, I tried the following pins, PA8, PA9, PA10, PA11 (because the timers are the same, 1/1, 1/2, 1/3/, 1/4 from the pinout diagram). The motor oscillate between 2 points. However, this is also the only time where the motor can move without power supply to the driver. Previously only the Uno can move the motor without power supply to the driver.

Codes for motor motion uses the example given above, with the only differences below.
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(PA8, PA9, PA10, PA11);
or
BLDCDriver3PWM driver = BLDCDriver3PWM(PC7, PB4, PB10, PA9);

Sensor codes,

#include <SPI.h>

//simplefoc
#include <SimpleFOC.h>

MagneticSensorSPI sensor1 = MagneticSensorSPI(PB9, 14, 0x3FFF);
MagneticSensorSPI sensor2 = MagneticSensorSPI(PB8, 14, 0x3FFF);
MagneticSensorSPI sensor3 = MagneticSensorSPI(PC9, 14, 0x3FFF);
//SPIClass SPI_1(PA7, PA6, PA5);//mosi miso, sclk

void setup() {
// put your setup code here, to run once:
SPI.begin();
//simplefoc sensor init
sensor1.spi_mode = SPI_MODE1; // spi mode - OPTIONAL
sensor1.clock_speed = 500000; // spi clock frequency - OPTIONAL
//sensor1.init(&SPI_1);
sensor1.init();
delay(10);
sensor2.spi_mode = SPI_MODE1; // spi mode - OPTIONAL
sensor2.clock_speed = 500000; // spi clock frequency - OPTIONAL
sensor2.init(&SPI_1);
delay(10);
sensor3.spi_mode = SPI_MODE1; // spi mode - OPTIONAL
sensor3.clock_speed = 500000; // spi clock frequency - OPTIONAL
sensor3.init(&SPI_1);
delay(10);

//serial setup
Serial.begin(115200);
delay(1000);
}

void loop() {
// put your main code here, to run repeatedly:
//sensor1.spi_mode = SPI_MODE0; // spi mode - OPTIONAL
//sensor1.clock_speed = 500000; // spi clock frequency - OPTIONAL
//sensor1.init();
//sensor1.init(&SPI_1);
sensor1.init();

Serial.print(sensor1.getAngle());
Serial.print("\t");

sensor2.init(&SPI_1);
Serial.print(sensor2.getAngle());
Serial.print("\t");

sensor3.init(&SPI_1);

Serial.println(sensor3.getAngle());

delay(10);
}

Hi All,

Another update, Quite sure this does not help much for the problem. hopefully it would help guide another STM32 user, or a record for STM32 usage feedback?

While Iā€™m queuing up to use the oscilloscope (shared resource), I use a multimeter to have a feel of the issue. This is what I found out,

Board 1
Working motor, non working SPI,

BLDCDriver3PWM driver = BLDCDriver3PWM(PC7, PB4, PB10, PA9); //also known as 9,5,6,8

Pin PC7, 9 -> oscillating voltage
Pin PB4, 5 -> oscillating voltage
Pin PB10, 6 -> oscillating voltage
Pin PA9, 8 -> constant volts at 3.28 (or Iā€™m guessing close to 3.3V)

Board 2
Working SPI, non working motor,

BLDCDriver3PWM driver = BLDCDriver3PWM(PC7, PB4, PB10, PA9); //also known as 9,5,6,8

Pin PC7, 9 -> oscillating voltage
Pin PB4, 5 -> oscillating voltage
Pin PB10, 6 -> constant 2.12V
Pin PA9, 8 -> constant volts at 0.06 (which I believe is just a low signal)

Both running the exact same codes.

So either I got two brand new non-working boards, or thereā€™s something else that we do not know about STM32.

Do you fully understand how the solder pads under the SimpleFOC boards work? When I received mine they came with some ā€œsolder pasteā€ across some of the pads and the resistance of them youā€™d expect to be zero but with mine was sometimes a few 100 ohms. I scratched it off and applied proper solder.

PB10,6 feels like it is floating. Where are you measuring it? Just on the board output or on the stm32 pin itself.

Iā€™d put an ohmeter between mcu and the l6234 pins for pb10 and pa9

1 Like

Hi,

Thanks for sharing.

I do understand the logic of testing the resistance of everything you just soldered. Which in this case is bwt 0.06~0.07 ohm.

I am trying to understand the possible reasons why a shield can work with two boards (uno perfectly and a stm32) and not the third means that the shield is at fault and not the board. Especially since the third board gave different signals using the same code and arduino upload method.

Also, of course itā€™s the pins on the stm32. Tested with 3 grd pins i can find on the board.

Hi All,

Just an update. The problem is solved by using Arduino Due instead of STM32. Everything works well now. Thanks.

Glad you are sorted! :slight_smile:
I find using the SimpleFOC board with non R3 shaped boards (i.e. not shaped like uno) a mental challenge!! You have to keep track of the pin numbers of the imaginary Uno board that is not connected as they are referenced in solder pads!

Spreadsheets help here to keep track of this - itā€™s really easy to make a wiring mistake or not notice some datasheet limitations of certain pins.
Also stm32 has a higher learning curve.