Skip to content

ESP32 Based Motor controller with inverted low side #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
VTCrafter14 opened this issue May 17, 2025 · 1 comment
Open

ESP32 Based Motor controller with inverted low side #470

VTCrafter14 opened this issue May 17, 2025 · 1 comment
Labels
question Further information is requested

Comments

@VTCrafter14
Copy link

Hello i want to control a bldc 3 phase sensored Motor and i have a esp32 with three u3115s mosfet drivers that invert the low side so that the Low Side Mosfet is active if the Lin from the u3115 ic is low and the high side is active if the Hin of the u3115s is High. Maybe is there a way to invert the low side outputs from the esp?
here is my code:
#include <SimpleFOC.h>

// ------------------------
// Pins & Parameters
// ------------------------
const int potiPin = 34; // analog input for potentiometer
float target_velocity = 0;

// Hall sensor pins A, B, C + pole pairs
HallSensor sensor(35, 36, 39, 15);

// 6PWM Driver for High- and Low-side MOSFETs
BLDCDriver6PWM driver(
32, // U-phase High-side input
33, // U-phase Low-side input
25, // V-phase High-side input
26, // V-phase Low-side input
27, // W-phase High-side input
14 // W-phase Low-side input
);

BLDCMotor motor(15);

// ISR routines for Hall signals
void isrA() { sensor.handleA(); }
void isrB() { sensor.handleB(); }
void isrC() { sensor.handleC(); }

void setup() {
Serial.begin(115200);

// Hall-Sensor initialization
sensor.init();
sensor.enableInterrupts(isrA, isrB, isrC);
motor.linkSensor(&sensor);

// Driver initialization
driver.voltage_power_supply = 24;
driver.pwm_frequency = 20000;
driver.init();
motor.linkDriver(&driver);

// Motor FOC settings
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.controller = MotionControlType::velocity;
motor.voltage_limit = 6; // Volt
motor.velocity_limit = 14.9; // rad/s (~6 km/h)
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 10;
motor.PID_velocity.D = 0;
motor.LPF_velocity.Tf = 0.01;

// initialize motor and FOC
motor.init();
motor.initFOC();

Serial.println("=== Poti-Controlled FOC Ready ===");
}

void readPoti() {
int potiValue = analogRead(potiPin); // 0 - 4095
float potiNorm = (potiValue - 2048.0f) / 2048.0f; // Range -1.0 to +1.0
target_velocity = potiNorm * motor.velocity_limit;
Serial.print("Target velocity: ");
Serial.println(target_velocity);
}

void loop() {
motor.loopFOC();
readPoti();
motor.move(target_velocity);
}

@runger1101001 runger1101001 added the question Further information is requested label May 18, 2025
@runger1101001
Copy link
Member

You can do it in 6-PWM mode by setting the build flag -DSIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH=false

Setting build flags depends on your environment. In platformio, you can put them in the platformio.ini

Be careful setting these options and using drivers with inverted polarity - check your PWM outputs and dead-time carefully before connecting power to the driver, or you could have shoot-through and burn your FETs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants