# Problems with torque-control

**URL:** https://community.simplefoc.com/t/problems-with-torque-control/6904
**Category:** hardware support
**Created:** [March 10, 2025, 3:34pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904 "2025-03-10T15:34:45Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas\_Stingel](https://community.simplefoc.com/user_avatar/community.simplefoc.com/thomas_stingel/32/7915_2.png) [@Thomas\_Stingel](https://community.simplefoc.com/u/Thomas_Stingel)
#### Post date: [March 10, 2025, 3:34pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/1 "2025-03-10T15:34:45Z")

</div>

Hey,

I’m having problems with the torque and voltage control.  
I am building a 2-DOF GImbal to align a camera.  
I am using:

- GM5208-24 motors from iPower
- as5048a encoder
- Nucleo f446re
- SimpleFOC mini v1.0
- labor power supply

Yesterday I assembled my construction for the first time and had already successfully tested the individual motors and sensors in advance.

After the assembly I was able to control and align both motors but both motors showed the following behavior:

They approached the individual target angles but after a certain limit the motors block and simply start to draw more current. While this is happening, the motors do not react to further inputs.

To get to the bottom of the problem, I checked and tested the following things today:

- Wiring
- Sensor values, both in the program and with the sensor test examples
- open-loop Velocity
- open-loop position
- closed loop velocity
- torque control
- Replacing the drivers

While my pitch axis now works in all modes (PINS were inserted incorrectly), I have problems with the yaw axis. Open-loop works fine in terms of speed and position. The closed-loop velocity does not work. I then tested the torque control to rule out controller problems and the motor now runs at 2V for about 27 revolutions and then stops. During the revolutions you can hear that a kind of friction occurs at two points of the rotation which slows down the motor (no mechanical friction, the motor can rotate freely if no voltage source is connected). If the target voltage is set to 0, the motor can be rotated without any noticeable force. If I set a voltage of 12v, then the motor holds its position after stopping but does not turn any further. I have already read most of the forum entries on similar topics and unfortunately have had no success in finding a solution so far. Has anyone had a similar problem?

Otherwise, many thanks to all those who have contributed to this project and made it possible for me to complete my project!

Thats the code i use for torque-control:

/\*\*

- Torque control example using voltage control loop.
- 
- Most of the low-end BLDC driver boards doesn’t have current measurement therefore SimpleFOC offers
- you a way to control motor torque by setting the voltage to the motor instead hte current.
- 
- This makes the BLDC motor effectively a DC motor, and you can use it in a same way.  
\*/  
#include \<SimpleFOC.h\>

// magnetic sensor instance - SPI  
#define AS5048\_CS\_2\_PIN PD2  
SPIClass SPI\_3(PC12, PC11, PC10);

// Sensor-Objekt  
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147\_SPI, AS5048\_CS\_2\_PIN);  
// magnetic sensor instance - I2C  
// MagneticSensorI2C sensor = MagneticSensorI2C(AS5600\_I2C);  
// magnetic sensor instance - analog output  
// MagneticSensorAnalog sensor = MagneticSensorAnalog(A1, 14, 1020);

// BLDC motor & driver instance  
BLDCMotor motor = BLDCMotor(11);  
BLDCDriver3PWM driver = BLDCDriver3PWM(PC6, PC7, PC8, PC9);  
// Stepper motor & driver instance  
//StepperMotor motor = StepperMotor(50);  
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);

// voltage set point variable  
float target\_voltage = 2;  
// instantiate the commander  
Commander command = Commander(Serial);  
void doTarget(char\* cmd) { command.scalar(&target\_voltage, cmd); }

void setup() {

// use monitoring with serial  
Serial.begin(115200);  
// enable more verbose output for debugging  
// comment out if not needed  
SimpleFOCDebug::enable(&Serial);

// initialise magnetic sensor hardware  
SPI\_3.begin();  
sensor.init(&SPI\_3);  
// link the motor to the sensor  
motor.linkSensor(&sensor);

// power supply voltage  
driver.voltage\_power\_supply = 12;  
driver.init();  
motor.linkDriver(&driver);

// aligning voltage  
motor.voltage\_sensor\_align = 5;  
// choose FOC modulation (optional)  
motor.foc\_modulation = FOCModulationType::SpaceVectorPWM;  
// set motion control loop to be used  
motor.controller = MotionControlType::torque;

// comment out if not needed  
motor.useMonitoring(Serial);

Greetings  
Thomas

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 2, 2025, 1:09pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/2 "2025-11-02T13:09:14Z")

</div>

Hi, I have a similar problem, the motor turns for a while in the torque-voltage mode, but after that it just locks up/blocks, the current increases and my ESP32 does not respond to commands, the monitor() also stops sending data to serial. Did you manage to find a solution?

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [November 2, 2025, 8:47pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/3 "2025-11-02T20:47:36Z")

</div>

Hi @arch welcome to SimpleFOC!

it does not sound like your problem is the same as Thomas.

@Thomas_Stingel very sorry you never got an answer to your issue back in March. I hope you have solved it.

Arch, how long is “a while”? Are we talking many minutes or just a short time?

Which ESP32 are you using?

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 3, 2025, 12:59pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/4 "2025-11-03T12:59:24Z")

</div>

Hi @runger, thanks for reply.

It depends on what kind of target I set in the torque-voltage mode (I used pp, resistance and KV). If \<1, then it spins for a long time and gets stuck only if I stop it with my hands. If \>1, then it spins for up to 10 seconds and stops. Also, ESP32 sends an error many time before it is blocked:  
(15513) i2c.master: I2C hardware timeout detected  
E (15513) i2c.master: s\_i2c\_synchronous\_transaction(945): I2C transaction failed

By “lock/stall” I mean:

1. Either the ESP does not send anything to Serial at all and does not respond to commands (only the reboot helps). The current is increasing. The motor stops in place.

2. Either ESP restarts itself with an error:  
Guru Meditation Error: Core 1 panic’ed (StoreProhibited). Exception was unhandled.

I really haven’t been able to figure out what’s going on for a long time(because i am newbie in electronics and simple foc) maybe it’s the EMF, because these stalls occur under load.  
Motor 5010 360KV 0.27 Ohm  
Driver MKS dual foc 3.3 12V  
Encoder I2C MT6701  
In open loop it works pretty good

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [November 3, 2025, 5:53pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/5 "2025-11-03T17:53:09Z")

</div>

From your description it sounds a bit like you’re somehow exceeding the capabilities of your power supply, or perhaps getting spikes into the 3.3V line. For example with your setup you would be setting a target current in torque mode. So when you set it too high the BEMF rises as the motor turns faster. The controller reacts by adjusting the voltage up to counteract the BEMF. Eventually the capacity of the PSU is exceeded and the voltage drops, and the ESP32 experiences a brown-out. Something like that.

Or if you find you can reset the esp by sharply moving the motor or by stopping it suddenly while moving, then perhaps there are spikes coming across from the motor to the MCU…

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 3, 2025, 7:43pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/6 "2025-11-03T19:43:32Z")

</div>

@runger I decided to remove the ESP from the driver (see the photo with my poor setup) and everything started working much better! Maybe my driver doesn’t have reverse protection or something?

 ![image](https://community.simplefoc.com/uploads/default/original/2X/1/19ecf4ee8414052c5ec5997164cb7db6f8b97703.jpeg)

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [November 3, 2025, 7:46pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/7 "2025-11-03T19:46:11Z")

</div>

That’s interesting! It definitely sounds like something electrically dodgy is going on. Is everything the same just with cables, or did you change something about the way it gets powered also?

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 3, 2025, 7:57pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/8 "2025-11-03T19:57:28Z")

</div>

No, I just removed the ESP from the driver (I used it as a shield before) connected the necessary pins with wires and that’s it.

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [November 3, 2025, 8:33pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/9 "2025-11-03T20:33:21Z")

</div>

Maybe the problem was through one of the other pins then, that is now not connected?

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 3, 2025, 8:37pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/10 "2025-11-03T20:37:36Z")

</div>

So, this is probably some kind of magic, now the system is not working, but for a different reason. I’m trying to calibrate the sensor, but why isn’t it initializing or something?

 ![image](https://community.simplefoc.com/uploads/default/original/2X/2/2fbb0c297dc9720573ed6e29cc59b5296ba7286a.png)

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [November 3, 2025, 8:47pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/11 "2025-11-03T20:47:17Z")

</div>

But it was working before? Is the call to initFOC moving the motor?

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 3, 2025, 8:48pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/12 "2025-11-03T20:48:38Z")

</div>

Yep, it worked 30 minutes ago), but apparently something happened

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 3, 2025, 8:51pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/13 "2025-11-03T20:51:39Z")

</div>

The magnetic sensor test itself works, the angle is shown, one revolution is 2Pi.

I noticed an interesting thing, during the encoder test, when I was turning the motor with my hand, the PSU went into OCP protection. I don’t even know what to do about it. But then again, everything was working just now. Going to see with a scope tomorrow.

> [@runger](#):
>
> Is the call to initFOC moving the motor?

No, it doesnt

Update: open loop also doesnt work now, maybe my driver is completely broken. Here’s the video and code of what’s going on

```auto
#include <SimpleFOC.h>

BLDCMotor motor = BLDCMotor(7, 0.27);
BLDCDriver3PWM driver = BLDCDriver3PWM(32,33,25,22);

float target_velocity = 2;

//Serial command setting
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }

void setup() {
  
  driver.voltage_power_supply = 12;
  driver.init();
  motor.linkDriver(&driver);
  motor.voltage_limit = 2; // [V]
  motor.velocity_limit = 40; // [rad/s]
 
  //Open loop control mode setting
  motor.controller = MotionControlType::velocity_openloop;
  //Initialize the hardware
  motor.init();

  command.add('T', doTarget, "target velocity");

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

void loop() {
  motor.move(target_velocity);

  command.run();
}

```

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [November 3, 2025, 9:35pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/14 "2025-11-03T21:35:51Z")

</div>

In that video it looks like only one of the phases is working?

I’d say for open loop you need to drop your voltage limit. With 0.27Ohm resistance 2V will still be quite a few amps. To move the motor without load just some milliamps will be enough. Try with a voltage limit of 0.1V to 0.25V.

With the motor resistance set you can also set a current limit on the motor…

---

<div class="post-metadata">

### Author: ![arch](https://community.simplefoc.com/user_avatar/community.simplefoc.com/arch/32/9392_2.png) [@arch](https://community.simplefoc.com/u/arch)
#### Post date: [November 3, 2025, 10:05pm UTC](https://community.simplefoc.com/t/problems-with-torque-control/6904/15 "2025-11-03T22:05:11Z")

</div>

Indeed, at 0.2 it turns at least, thanks, I thought it was already completely broken. (In fact, it only turns at values from 0.18 to 0.23) My fault, I always used voltage\_limit 1 or 2 before, but it worked well enough at these values.
