Problem on PWM generation

I’m using a B_g431_ESC board and i’m looking to do a drone motor firmware with simpleFOC. I have try to start with the example of this page Velocity Open-Loop | Arduino-FOC by adaption the 6 pins of the drivers.
I try my first version with a motor and my board burn (shunt resistor disappear). I take a brand new board, load the firmware and measure the phase voltage and as you can see on the picture, phase U and V (orange and blue) are always on together and phase W in green stay grounded. I have limit the voltage to 0.3V but it doesn’t change anything. Do you have something that can help me ? Thanks :wink:

Hmm, the only things that stand out are that 0.048 ohms with 190kv implies a very large motor, and you never set motor.voltage_sensor_align, and the default 3V (in src/common/defaults.h) is too high for such a low resistance motor.

It is normal for the oscilloscope to show the full power supply voltage. That’s how PWM works. The percentage of on-time versus off-time controls the effective output voltage. Your two working phases are at 50% duty, so effectively 12V output. That is also normal. The sine waves to drive the motor go up and down from there. But because one phase is never turning on, it’s stuck at -12V from center.

But I can’t think of what the problem might be. The A_PHASE_Wx defines come from the STM32 boards package, so the fact that they exist means you must have the correct board definition selected. And the fact that two outputs are working means the timer is configured and running. So why one channel not working?

Post your code, it’s probably something simple.

#include <Arduino.h>
#include <SimpleFOC.h>

// BLDC motor & driver instance
//Set up the motor and driver, motor is 7 pp, .12 phase resistor, and 1400KV 
BLDCMotor motor = BLDCMotor(21, .048, 190);
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);

// instantiate the commander
Commander command = Commander(Serial2);
void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
void doLimitCurrent(char* cmd) { command.scalar(&motor.current_limit, cmd); }

void setup() {

  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 24;
  driver.dead_zone = 0.02;
  driver.init();
  // link the motor and the driver
  motor.linkDriver(&driver);

  // limiting motor current (provided resistance)
  motor.current_limit = 0.5;   // [Amps
  motor.voltage_limit = 0.3;
  
  // open loop control config
  motor.controller = MotionControlType::velocity_openloop;

  // init motor hardware
  motor.init();
  motor.initFOC();

  // add target command T
  command.add('T', doTarget, "target velocity");
  command.add('C', doLimitCurrent, "current limit");

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

void loop() {
  motor.loopFOC();
  // open loop velocity movement
  // using motor.current_limit and motor.velocity_limit
  motor.move();

  // user communication
  command.run();
}

Thanks,

I have now use a new board, put a voltage_sensor_align value much lower but the problem is the same

I have the revision C of the board if it can help you

Are you using platformio?

Yes i’m using platformio and it’s my .ini file :

[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
lib_archive = false
monitor_speed = 115200
board_build.f_cpu = 170000000L
build_flags =
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
    -DCONFIG_DISABLE_DEBUG
    -D USBCON
    -D HAL_OPAMP_MODULE_ENABLED

lib_deps = 
    https://github.com/simplefoc/Arduino-FOC.git#dev

Remove PIO_FRAMEWORK_ARDUINO_ENABLE_CDC

Perfect !!! Thank you so much