E bike controller for 250w 36V

Hi sir i need your help. I try to develop e bike motor(36V 250W) controller with open loop, using ESP32 and ebike throttle for analog input

#include <SimpleFOC.h>
#include <Arduino.h>
BLDCMotor motor = BLDCMotor(10, 0.3, 80);

BLDCDriver3PWM driver = BLDCDriver3PWM(15, 2, 4);
float target_velocity = 0;
const int potPin = 34;
void setup() {

driver.voltage_power_supply = 36;
driver.init();

motor.linkDriver(&driver);

motor.current_limit = 0.5; // [Amps]
motor.controller = MotionControlType::velocity_openloop;
motor.init();
motor.initFOC();

_delay(1000);
}

void loop() {
motor.loopFOC();
target_velocity = float(map(analogRead(potPin), 0, 4095, 0, 10000)) / 100.0;
motor.move(target_velocity);
}

Sir, please tell me this code is correct or not

No, your code is not correct. Kindly, go through the documents, over there you will find step by step how to use SimpleFOc,

Also, what driver are you using?

Regards,
Moid

1 Like

Sir I’m using irIR2103 based
high_perf_new
drivers

Hi,

The code is not too bad… you should consider reading the analog signal less often, you don’t have to read it at every iteration of the main loop? Maybe 10 to 20 times per second will be enough?

But I think there may be a problem with ESP32 and using the analogRead function alongside current sensing. Try chainging analogRead(potPin) to adcRead(potPin)

1 Like

Thank you for the information. I have one doubt how can I change current limit and velocity using single throttle?

Hey @Dino_X,

I don’t know, I think if you want to control them both separately, then you need to use 2 inputs… encoding them both into the same PWM signal would be complicated, I think, and probably lead to errors/problems.

But limiting the current will at the same time limit the maximum velocity, so perhaps (depending on your application) limiting the current is enough?

1 Like