Driver.init() failure; MCPWM appears to be initialized twice (ESP32-C6)

Hi there!

I’ve been running into some issues getting a simple open loop motor spinning example working on my setup where the driver initialization fails. I have an ESP32-C6 dev board (CodeCell C6) connected to a TMC6300 driver board and SparkFun’s brushless gimbal motor (OT-EM3215). The driver board is connected to a 6V 1200mAh, NiMH RC battery.

Setup

Motor Pinout: UH = 1, UL = 2, VH = 3, VL = 21, WH = 22, WL = 23

Software

  • Arduino IDE
  • SimpleFOC 2.4.0
  • SimpleFOCDrivers 1.0.9
  • esp32 3.3.11

Issue

I enabled debug logging over Serial, and it appears that SimpleFOC is able to detect and configure my board’s MCPWM peripheral, only to fail by (apparently) attempting to set it up again:

ESP32-DRV: Configuring 6PWM in group: 0 on timer: 0
ESP32-DRV: Configuring 3 operators.
ESP32-DRV: Configuring 6PWM with hardware dead-time
ESP32-DRV: Configuring 3 comparators.
ESP32-DRV: Configuring 6 generators.
ESP32-DRV: Configuring Center-Aligned 6 pwm.
ESP32-DRV: Configuring dead-time.
ESP32-DRV: Enabling timer: 0
ESP32-DRV: MCPWM configured!
ESP32-DRV: Not enough pins available for 6PWM!

Looking through esp32_driver_mcpwm.cpp, the configuration log lines appear to indicate successful configuration, as otherwise I (should?) see errors per configuration, like these:


  for (int i = 0; i < no_operators; i++) {
    CHECK_ERR(mcpwm_new_comparator(params->oper[i], &comparator_config, &params->comparator[i]),"Could not create comparator: " + String(i));
    CHECK_ERR(mcpwm_comparator_set_compare_value(params->comparator[i], (0)), "Could not set duty on comparator: " + String(i));
  }

I tried to trace this back and see if there would be any reason as to why the init would be attempted twice, but I don’t think I see anything, so I’m a bit at a loss.

Is it possible some power issue is causing it to be attempted twice? Or some flag that is being ignored?

Thanks in advance for any thoughts/suggestions :folded_hands: If there’s anything additional context that would be of use, do let me know.

2 Answers

2

I added some log lines in BLDCDriver6PWM.cpp’s BLDCDrive6PWM::init() to see if at least some kind of params were being returned:

// configure 6pwm
// hardware specific function - depending on driver and mcu

params = _configure6PWM(pwm_frequency, dead_zone, pwmA_h,pwmA_l, pwmB_h,pwmB_l, pwmC_h,pwmC_l);

SIMPLEFOC_DEBUG("beep");

if (params == SIMPLEFOC_DRIVER_INIT_FAILED) {
  SIMPLEFOC_DEBUG("Validation check: params matches SIMPLEFOC_DRIVER_INIT_FAILED!");
} else {
  SIMPLEFOC_DEBUG("Validation check: params returned a valid structure pointer!");
}

initialized = (params!=SIMPLEFOC_DRIVER_INIT_FAILED);

return params!=SIMPLEFOC_DRIVER_INIT_FAILED;

This is an excerpt from the Serial output. Note that it DOES appear to be attempting the process twice for whatever reason:

ESP32-DRV: MCPWM configured!
beep
Validation check: params returned a valid structure pointer!
ESP32-DRV: Configuring 6PWM in group: 0 on timer: 0
ESP32-DRV: Configuring 3 operators.
E (1183) mcpwm: mcpwm_operator_register_to_group(35): no free operators in group (0)
E (1184) mcpwm: mcpwm_new_operator(79): register operator failed
ESP32-DRV: ERROR - Could not create operator 0
beep
Validation check: params matches SIMPLEFOC_DRIVER_INIT_FAILED!

The reason why we no longer see ESP32-DRV: Not enough pins available for 6pwm is because I added a hard-coded case for 6PWM in _findBestGroup:

int _findBestGroup(int no_pins, long pwm_freq, int* group, int* timer){
  // handle 6 pwm
  if (no_pins == 6) {
    *group = 0; 
    *timer = 0; 
    return 1;   
  }
  ...
}

I switched over to a RP2040 Connect for this project, but in the process, I may have discovered the reason why I was running into issues:

driver.init();
if (!driver.init()) {
  Serial.println("Driver init failed!");
}

I think I developed blindness to my own if statement, lol. In this case, the reason why the driver is initialized twice is because we’re literally initializing it twice, once on its own, and once in the if. I disconnected the ESP32-C6, but chances are if i removed the first init and just had the init in the if, the issue would have been solved (can’t confirm entirely until I try it, though).