Can't init current sense

I’m having difficulty getting current sense to init on my config

Driver: SimpleFOCShield v2.0.4
MCU: ESP32-S3-DevKit C N8R2
BLDC: [5010 260KV] - 12N14P (7 pole pair)(Rctimer 5010 260KV Multirotor Brushless Motor(4.0mm shaft)) running at 12V (supports 4-6s / 14.8->22.2V)
Sensor: AS5600

Application: I’m building a zoetrope very similar to this

Pre-simplefoc:


I’m running a low-impedance BLDC with a max of 750rpm / 78rad/s with a ~400g load. I never see > 800ma and I have a heatsink+fan on the L6234. So far it works great.

I’m trying to get inline current sensing working but am encountering problems.

  1. “Err too low current, rise voltage!” current sense errors
  2. higher voltage_sensor_align values cause pole pair check to fail

Starting out with:

motor.voltage_sensor_align = 1;

results in:

  1. CS: Err too low current, rise voltage!
  2. MOT: PP check: OK!
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
[  2012][E][esp32-hal-adc.c:172] __analogChannelConfig(): Pin is not configured as analog channel
[  2021][E][esp32-hal-adc.c:172] __analogChannelConfig(): Pin is not configured as analog channel
Current sense init success!
PWM frequency: -12345
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: OK!
MOT: Zero elec. angle: 5.20
MOT: Align current sense.
CS: Err too low current, rise voltage!
MOT: Align error!
MOT: Init FOC failed.

the code says to bump it up. I tested with 1-9V)

motor.voltage_sensor_align = 9;

doesn’t help. It throws the same error. setting:

motor.voltage_sensor_align = 12;

results in:

MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
[  2012][E][esp32-hal-adc.c:172] __analogChannelConfig(): Pin is not configured as analog channel
[  2021][E][esp32-hal-adc.c:172] __analogChannelConfig(): Pin is not configured as analog channel
Current sense init success!
PWM frequency: -12345
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp: 8.06
MOT: Zero elec. angle: 5.18
MOT: Align current sense.
CS: Err too low current, rise voltage!
MOT: Align error!
MOT: Init FOC failed.
  1. the same CS error
  2. MOT: PP check: fail - estimated pp: 8.06

With motor.voltage_sensor_align = 1 I did see this once:

MOT: Align current sense.
CS: Switch A-B
CS: Switch B-(C)NC
MOT: Success: 2
MOT: Ready.

After that, I swapped my current sense pins and never saw it again. I also tried swapping them back to their original assignments but never saw success again.

I’ve also seen the following after swapping around 2 of the phases between the driver and motor (but returned to the other CS error on subsequent runs):

MOT: PP check: OK!
MOT: Zero elec. angle: 5.16
MOT: Align current sense.
CS: Err align B
MOT: Align error!
MOT: Init FOC failed.

I looked at the code but didn’t see any hints.

To be clear I almost always get the CS: Err too low current, rise voltage! error.

Full code here:

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

#define I2C_SDA 4 // SDA on encoder (encoder yellow)
#define I2C_SCL 5 // SCL on encoder (encoder orange)
#define CURRENT_SENSE_B 6  // GPIO6 - ADC1_5 
#define CURRENT_SENSE_A 7  // GPIO7 - ADC1_6
#define PWM_A 15 // 9 on simplefoc shield v2 (red)
#define PWM_B 16  // 5 on simplefoc shield v2 (orange)
#define PWM_C 17 // 6 on simplefoc shield v2 (yellow)
#define ENABLE 18 // 8 on simplefoc shield v2 (green)


BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(PWM_A, PWM_B, PWM_C, ENABLE);
MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);

// Try different constructor variations with explicit float types
// Version 1: Using defines with float literals
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, CURRENT_SENSE_A, CURRENT_SENSE_B);

float target_velocity = 0.0f;

Commander command = Commander(Serial);

void doMotor(char* cmd) { command.motor(&motor, cmd); }
void doTarget(char* cmd) { 
  command.scalar(&target_velocity, cmd); 
  // Serial.print("Target velocity set to: ");
  // Serial.println(target_velocity);
}

void setup() {
  Serial.begin(115200);
  _delay(1000);
  
  Serial.println("Starting...");
  
  // Add debug prints for pin values
  Serial.print("Define values - A: ");
  Serial.print(CURRENT_SENSE_A);
  Serial.print(", B: ");
  Serial.println(CURRENT_SENSE_B);
  
  // Print the actual pin values from current_sense object
  Serial.print("Current sense pins from object: ");
  Serial.print(current_sense.pinA);
  Serial.print(", ");
  Serial.println(current_sense.pinB);

  SimpleFOCDebug::enable(&Serial);

  Wire.begin(I2C_SDA, I2C_SCL);
  Wire.setClock(400000);

  sensor.init(&Wire);

  motor.linkSensor(&sensor);
  
  driver.voltage_power_supply = 12;
  if(!driver.init()){
    Serial.println("Driver init failed!");
    return;
  }

  current_sense.linkDriver(&driver);

  motor.linkDriver(&driver);
  motor.controller = MotionControlType::velocity;
  motor.PID_velocity.P = 0.04f;
  motor.PID_velocity.I = 0.7f;
  motor.PID_velocity.D = 0.0f;
  motor.LPF_velocity.Tf = 0.01f;
  motor.voltage_limit = 12;   // [V]
  motor.velocity_limit = 1000; // [rad/s]
  motor.voltage_sensor_align = 3; // [V]
  motor.velocity_index_search = 3;
  motor.useMonitoring(Serial);
  
  if(!motor.init()){
    Serial.println("Motor init failed!");
    return;
  }

  if (current_sense.init())  Serial.println("Current sense init success!");
  else{
    Serial.println("Current sense init failed!");
    return;
  }

  motor.linkCurrentSense(&current_sense);

  // driver.pwm_frequency = 20000;
  Serial.print("PWM frequency: ");
  Serial.println(driver.pwm_frequency);

  motor.initFOC();

  command.add('T', doTarget, "target velocity");
  command.add('M', doMotor,"my motor");
  
  _delay(1000);
}

void loop() {
  motor.loopFOC();
  //  motor.monitor();
  motor.move(target_velocity);  // use the target velocity here

  command.run();
  
}

// columtarget, voltage.q, velocity, angle

PlatformIO config:

[env:esp32-s3_i2c_simplefoc]
build_src_filter = +<esp32-s3_i2c_simplefoc.cpp> 
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.mcu = esp32s3
board_build.f_cpu = 240000000L
board_build.partitions = default_8MB.csv
board_build.arduino.memory_type = qio_qspi
build_flags = 
    -DARDUINO_USB_MODE=1
    -DARDUINO_USB_CDC_ON_BOOT=1
    -DBOARD_HAS_PSRAM
upload_protocol = esptool
monitor_speed = 115200
lib_deps = 
	askuric/Simple FOC@^2.3.4
	Wire
1 Like

I’m also experiencing the same issue with an ESP32s3