B-G431B-ESC1 Freewheeling

Hello Guy,

I’ve been trying to get the motor into a freewheeling state, using the motor.disable() function.
But when I apply the function, the motor gets in a freewheeling state, but with some very high resistance.
Where does that come from and how can I get rid of it?

I can get the motor to freewheel with:

        pinMode(PHASE_UH, INPUT_FLOATING);
        pinMode(PHASE_UL, INPUT_FLOATING);
        pinMode(PHASE_VH, INPUT_FLOATING);
        pinMode(PHASE_VL, INPUT_FLOATING);
        pinMode(PHASE_WH, INPUT_FLOATING);
        pinMode(PHASE_WL, INPUT_FLOATING);

But I’m not sure why this works.

I think I gave the explanation in my other answer - the driver used cannot be fully disabled, and the motor.disable() function leaves the low side FETs on in this case.

This will shut off all the FETs so that the windings are unconnected. Call motor.disable() first. I would actually have expected that you also need to disable the hardware timer being used, but perhaps setting the pins to input mode simply disables the PWM output of the timer.

Note that you probably want INPUT with pull-down to make sure the driver input is really off. But actually it would probably be better to shut off the PWM (disable the hardware timer) and then use pinMode OUTPUT and LOW to properly switch off the FETs.

Hey,

thanks for the help. Using the method you told me, works.
I was using the “pinMode(PHASE_UH, INPUT_PULLDOWN);
So for disabling :image

and for enabling:image

Don’t worry about the error on “A_PHASE_WL” that’s just in VS, I described my problem here

2 Likes

Hi guys. How do you do it? I added these lines to my code and got an error when compiling😅

Posting the error will certainly help.

There is a possibility that something has changed in the simpleFoc library in the past 12 months and that this workarund needs to be adjusted for the new version.

// Open loop motor control example
#include <SimpleFOC.h>
  BLDCMotor motor = BLDCMotor(15);
  BLDCDriver6PWM driver = BLDCDriver6PWM(14, 25, 12, 26, 13, 27);

float target_velocity = 0;

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.voltage_power_supply = 24;
  driver.voltage_limit = 3;
  driver.init();
  // link the motor and the driver
  motor.linkDriver(&driver);
  motor.voltage_limit = 3;   // [V]
  motor.controller = MotionControlType::velocity_openloop;
  motor.init();
  command.add('T', doTarget, "target velocity");
  command.add('L', doLimit, "voltage limit");
  Serial.begin(115200);
  Serial.println("Motor ready!");
  Serial.println("Set target velocity [rad/s]");
  _delay(1000);
}

void loop() {
  motor.move(target_velocity);
  command.run();
  if (motor.target == 0.0f && motor.enabled==1)
 {
        motor.disable();
        pinMode(PHASE_UH, INPUT);
        pinMode(PHASE_UL, INPUT);
        pinMode(PHASE_VH, INPUT);
        pinMode(PHASE_VL, INPUT);
        pinMode(PHASE_WH, INPUT);
        pinMode(PHASE_WL, INPUT);
      }
if (motor.target != 0.0f && motor.enabled==0)
  {
        pinMode(PHASE_UH, OUTPUT);
        pinMode(PHASE_UL, OUTPUT);
        pinMode(PHASE_VH, OUTPUT);
        pinMode(PHASE_VL, OUTPUT);
        pinMode(PHASE_WH, OUTPUT);
        pinMode(PHASE_WL, OUTPUT);
        motor.enable();
      }
}


Perhaps in the case of esp32 it is necessary to specify other pin names. But I don’t know where I can look :sweat_smile:

I don’t think the phases are defined like that within simpleFoc but are rather coming from SimonFO sketch.

You are calling pinMode Arduino function and the first argument in your case is not defined pinMode() - Arduino Reference

These should correspond to the pins you use to init the driver.

If in pinmode I specify the contact number that I use, then it also causes an error

I did not try if it actually works, but it used to. If I include the code below into my program, it compiles fine with SimpleFOC 2.2.3.

/Chris

  	if (motor.target == 0.0f && motor.enabled==1)
 	{
        motor.disable();
        pinMode(A_PHASE_UH, INPUT);
        pinMode(A_PHASE_UL, INPUT);
        pinMode(A_PHASE_VH, INPUT);
        pinMode(A_PHASE_VL, INPUT);
        pinMode(A_PHASE_WH, INPUT);
        pinMode(A_PHASE_WL, INPUT);
    }
	if (motor.target != 0.0f && motor.enabled==0)
  	{
        pinMode(A_PHASE_UH, OUTPUT);
        pinMode(A_PHASE_UL, OUTPUT);
        pinMode(A_PHASE_VH, OUTPUT);
        pinMode(A_PHASE_VL, OUTPUT);
        pinMode(A_PHASE_WH, OUTPUT);
        pinMode(A_PHASE_WL, OUTPUT);
        motor.enable();
    }

I realized my mistake. Now it compiles. I haven’t checked the performance yet. Thanks.
MfG Iurii

#define PHASE_UH 12
#define PHASE_VH 13
#define PHASE_WH 14
#define PHASE_UL 25
#define PHASE_VL 26
#define PHASE_WL 27

#include <SimpleFOC.h>
BLDCMotor motor = BLDCMotor(15);
BLDCDriver6PWM driver = BLDCDriver6PWM(PHASE_UH, PHASE_VH, PHASE_WH, PHASE_UL, PHASE_VL, PHASE_WL);
float target_velocity = 0;
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.voltage_power_supply = 24;
  driver.voltage_limit = 3;
  driver.init();
  motor.linkDriver(&driver);
  motor.voltage_limit = 3;   // [V]
  motor.controller = MotionControlType::velocity_openloop;
  motor.init();
  command.add('T', doTarget, "target velocity");
  command.add('L', doLimit, "voltage limit");

  Serial.begin(115200);
  Serial.println("Motor ready!");
  Serial.println("Set target velocity [rad/s]");
  _delay(1000);
}

void loop() {
  motor.move(target_velocity);
  command.run();
  if (motor.target == 0.0f && motor.enabled==1)
      {
        motor.disable();
        pinMode(PHASE_UH, INPUT);
        pinMode(PHASE_UL, INPUT);
        pinMode(PHASE_VH, INPUT);
        pinMode(PHASE_VL, INPUT);
        pinMode(PHASE_WH, INPUT);
        pinMode(PHASE_WL, INPUT);
      }
      else
      {
        pinMode(PHASE_UH, OUTPUT);
        pinMode(PHASE_UL, OUTPUT);
        pinMode(PHASE_VH, OUTPUT);
        pinMode(PHASE_VL, OUTPUT);
        pinMode(PHASE_WH, OUTPUT);
        pinMode(PHASE_WL, OUTPUT);
        motor.enable();
      }
}