Open loop velocity : motor not moving

Hi everybody ! Thanks to the forum I managed to control a DRV8302 board with my STM32f334R8 nucleo board, on arduino IDE. The driver standalone code provided by SimpleFOC works great, and now I’m trying the open loop velocity exemple. I achieve to have PWM signals on the gates, and the phases are controlled, I can see it because when I try to move the rotor, it is blocked to certain positions. I can move it by hand but it block to the nearest magnetic position. Moreover the OCTW Led is on. I think it’s not overtemperature because the led goes on as soon as I start, and I’m not sure about overcurrent, I would think that is a configuration problem more than a real problem. Anyone can help me to figure out why the motor isn’t turning and why the led is on?

Hey, which motor are you using and would you mind sharing the code you are trying to run? I think people will be better able to help you with that information…

Hi ! I use a BLDC Roxxy C35-30-45 with the code provided in exemple for open loop velocity control. Exactly this one :

// Open loop motor control example
#include <SimpleFOC.h>

// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number);
BLDCMotor motor = BLDCMotor(14);
// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);

// Stepper motor & driver instance
//StepperMotor motor = StepperMotor(50);
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6,  8);

//target variable
float target_velocity = 0;

// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }

void setup() {

  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 12;
  // limit the maximal dc voltage the driver can set
  // as a protection measure for the low-resistance motors
  // this value is fixed on startup
  driver.voltage_limit = 12;
  // link the motor and the driver

  // limiting motor movements
  // limit the voltage to be set to the motor
  // start very low for high resistance motors
  // current = voltage / resistance, so try to be well under 1Amp
  motor.voltage_limit = 6;   // [V]
  // open loop control config
  motor.controller = MotionControlType::velocity_openloop;

  // init motor hardware

  // add target command T
  command.add('T', doTarget, "target velocity");
  command.add('L', doLimit, "voltage limit");

  Serial.println("Motor ready!");
  Serial.println("Set target velocity [rad/s]");

void loop() {

  // open loop velocity movement
  // using motor.voltage_limit and motor.velocity_limit
  // to turn the motor "backwards", just set a negative target_velocity

  // user communication;

thank you very much!

That code looks ok, although I assume the motor has 7 pole pairs and not 14. But this error won’t matter for open loop mode.

The motor looks like it has quite low phase resistance, but I can’t find any website with decent specifications for this motor. Probably best if you just measure it.

My guess is you are tripping the over-current protection by running it with too high a voltage limit for its phase resistance. Try lowering the PSU voltage and/or setting a lower voltage limit.

Depending on the DRV8302 board you’re using you probably also should not leave the OC_ADJ pin floating - you can pull it up to VDD to set the max value, or use a voltage divider to set it to a desired level.

Please use a PSU with current limiting for your tests, or you may burn something :slight_smile: use the PSU to set a sensible current limit and watch it to make sure you’re not exceeding your chosen limit.

Of course you also can’t ignore the other driver pins like M_PWM to set the mode. You’re trying to use 3-PWM mode, so you need to pull M_PWM high. I don’t see this anywhere in your code, so are you using an external jumper wire to do this?

Thank you very much, once again.
First, for the pole pairs, I totally agree with you that the motor has 7 pole pairs and not 14, I tried both but I sent the wrong one. By the way, I feel like this point is usually blurry and on many applications number of poles is use for pole pairs. anyway, I will put 7 now.
Secondly, about the phase resistance. I measured it and I had something between 3 and 5 Ohms. I am not using a PSU for now, I am using a plug converter (not sure about the word but it sounds good, sorry I’m french :laughing:), that delivers 12V-2Amps. I will try to lower the voltages limits, but I think I already tried a lot of configurations and it didn’t work, but I’ll try better.
As I’m writing, I tried to put the OC_ADJ to 5V, everything works better with that, I even have some rotation some time, but really really ugly.
I will try not to burn anything but I don’t have a PSU available right now. But don’t worry everything around my desk is burnable.
I already used a jumper to set the M_PWM to high.

Moreover, I assumed that I have to use 3 pwms from the same timer. So I used PA0, PA1, PA2, the 3 first channel of timer 2. Since the driver take 3 int as inputs, how should I do if I wanted to use PC1,PC2, and PC3 ? Like if I write 1,2 and 3 it assumes it’s PA1,2,3 , how can i configure it to be PC.

Hey, ok that sounds quite good! 3-5Ohm is fairly high, so this reduces your chance of burning anything… sounds like this is a good motor for testing!

Still at 12V you may be exceeding the 2A that your plug converter (we call them DC adapters or “wall warts” :slight_smile: ) can deliver, which would cause voltage drops and would affect performance. Try setting the motor.voltage_limit to 3V.

The PP number has to be correct for closed loop mode, for open loop it won’t matter (it will just mean that you get 2x the speed you set if you use 14 instead of 7).

When using STM32 MCUs with Arduino it is best to use the STM32 pin references directly. So to use PC1, PC2 and PC3, use exactly those constants “PC1”, “PC2” and “PC3” in your code. This will be much less confusing than trying to use their numeric equivalents.

Thanks ! I did almost everything you said and now I have a motor turning ! First step, little step, but important step ! How could I use directly PC1 etc when the function has int arguments ?
Thanks !

1 Like

It’s because somewhere in some header file “PC1” gets defined as a constant, something like this:

#define PC1 16

So in your code you can then use this symbol PC1 and the compiler (actually the pre-processor) will replace it with the number 16.

(16 is just an example here, probably the real value of PC1 is different)

1 Like