# Force feedback controller control loop problem

**URL:** <https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753>\
**Category:** applications\
**Created:** [February 24, 2022, 1:36pm UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753 "2022-02-24T13:36:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xarin94](https://community.simplefoc.com/user_avatar/community.simplefoc.com/xarin94/32/2536_2.png) [@Xarin94](https://community.simplefoc.com/u/Xarin94)\
**Post date:** [February 24, 2022, 1:36pm UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/1 "2022-02-24T13:36:51Z")

</div>

Hi, I’m trying to build an FFB controller using two large NEMA 23 steppers linked to a controller stick.  
I want to use the two motors axis like spings, tunable on the go, to crate vibrations and different forces on the stick during the usage.  
I’m trying with only one axis now, my setup is a teensy 3.6 board, for position control a AH503 hall effect( i am using only 1-1.5 rad, so only one is in the linear zone) a L296N board.  
My problem is choosing the right control method: I’ve tried with no success angle loop, but it can’t hold my desired angle, torque control also does not provide constant torque, is my driver bad?  
The angle reading at 16 BIT with averaging seems very precise and reliable.  
If needed i can post the code but is a copy and paste of what I’ve found the examples.  
Thanks for the help!

---

<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:** [February 25, 2022, 8:27am UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/2 "2022-02-25T08:27:52Z")

</div>

Hi, and welcome @Xarin94 ,

> [@Xarin94](#):
>
> I’ve tried with no success angle loop, but it can’t hold my desired angle, torque control also does not provide constant torque, is my driver bad?

What do you mean by this? Is the torque low, so that the force is weak, or is the position not holding at the value when you command a constant position? Could you post a video maybe of what is going on?

In general terms: L298N is not a great driver, it can work depending on the situation, but it is a bit inefficient… without knowing a bit more about what is going on I would not blame the driver yet though!

---

<div class="post-metadata">

**Author:** ![Xarin94](https://community.simplefoc.com/user_avatar/community.simplefoc.com/xarin94/32/2536_2.png) [@Xarin94](https://community.simplefoc.com/u/Xarin94)\
**Post date:** [February 26, 2022, 3:53pm UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/3 "2022-02-26T15:53:40Z")

</div>

That means when i use torque mode, i expect the motor with no load to accelerate, ar at least with speed =/0, but nothing happens.  
I can post a screenshot of my motor monitoring and my code.  
In velocity mode and angle mode, the motor makes a normal startup, fails pp check, and don’t spin even in velocity mode.

 ![motor monitoring](https://community.simplefoc.com/uploads/default/original/2X/f/f51283ba408f375752fca3e926024ef2c18773fe.png)  
this is the code, i’m using a teensy 4.1(reading analog between 0-2024 for two rotations of the sensor):

#include \<SimpleFOC.h\>  
MagneticSensorAnalog x = MagneticSensorAnalog(A0, 14, 2048); //zero a 4.60  
StepperMotor motor = StepperMotor( 50 );  
StepperDriver4PWM driver = StepperDriver4PWM(4, 3, 2, 1);

void setup()  
{  
analogReadAveraging(10);  
Serial.begin(115200);  
motor.useMonitoring(Serial);  
motor.monitor\_variables = \_MON\_TARGET | \_MON\_VEL | \_MON\_ANGLE;  
motor.monitor\_downsample = 100; // default 10  
x.init();  
motor.linkSensor(&x);  
driver.voltage\_power\_supply = 20;  
driver.init();  
motor.linkDriver(&driver);  
motor.foc\_modulation = FOCModulationType::SinePWM;  
motor.controller = MotionControlType::angle;

motor.voltage\_limit = 5;  
// initialize motor  
motor.init();  
// align sensor and start FOC  
motor.initFOC();

\_delay(1000);  
}

void loop()  
{  
motor.loopFOC();  
motor.target = 2.34;  
motor.move();  
motor.monitor();  
}

---

<div class="post-metadata">

**Author:** ![Xarin94](https://community.simplefoc.com/user_avatar/community.simplefoc.com/xarin94/32/2536_2.png) [@Xarin94](https://community.simplefoc.com/u/Xarin94)\
**Post date:** [February 26, 2022, 11:09pm UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/4 "2022-02-26T23:09:28Z")

</div>

Found the problem, need better position sensing technique, the hall effect sensor must be tuned for the little range and used the correct value in MagneticSensorAnalog x = MagneticSensorAnalog(A0, 14, 2048);

---

<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:** [February 27, 2022, 10:04am UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/5 "2022-02-27T10:04:25Z")

</div>

Oh, I am glad you found it! Is it working now?

I was going to ask about the Analog sensor and how well it works? It is not often used with SimpleFOC…

---

<div class="post-metadata">

**Author:** ![Xarin94](https://community.simplefoc.com/user_avatar/community.simplefoc.com/xarin94/32/2536_2.png) [@Xarin94](https://community.simplefoc.com/u/Xarin94)\
**Post date:** [March 2, 2022, 8:25pm UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/6 "2022-03-02T20:25:43Z")

</div>

worked a bit better but not well, tried with as5600 but the same result, I suspect is the driver not very suitable,for a stepper motor what driver is good with a teensy for stepper?  
thanks

---

<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:** [March 3, 2022, 4:51pm UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/7 "2022-03-03T16:51:44Z")

</div>

The teensy is a very fast, very good MCU. It depends which one, but they are all pretty fast.

The AS5600 and the analog sensors are among the worst-performing sensors with SimpleFOC. They can work, but they don’t work as well as other models.

So you have a situation where you have a MCU like a Ferrari engine, but are using a driver and sensors like a Toyota Corolla… they don’t fit together, you won’t get the benefits of the fast MCU using these sensors and this driver.

Any FET-based driver will be better than the L298N. It is difficult right now due to components shortage, but keep looking in the SimpleFOC shop, and maybe in the meantime you can search for “SimpleFOC” on AliExpress…

When using the teensy, the loop normally runs very fast (although when using the I2C sensor this will slow it down). Sometimes it can be too fast - this can make the PIDs very hard to tune, and cause other problems, so if your loop is executing at more than 10000 iterations/second then maybe you can slow it down a bit (delayMicroseconds()).  
Also the L298N may be more sensitive to the PWM speed due to its long switching times. Lowering the PWM frequency can help to reduce noise and heat, and also in some cases improve the motor performance.

Do you use SimpleFOCStudio? If you can install it and use it to connect to your motor the outputs it can show can help to find problems…

---

<div class="post-metadata">

**Author:** ![Xarin94](https://community.simplefoc.com/user_avatar/community.simplefoc.com/xarin94/32/2536_2.png) [@Xarin94](https://community.simplefoc.com/u/Xarin94)\
**Post date:** [March 3, 2022, 6:23pm UTC](https://community.simplefoc.com/t/force-feedback-controller-control-loop-problem/1753/8 "2022-03-03T18:23:24Z")

</div>

thanks for the valuable info, I’ll make improvements on my setup and keep it posted.  
Do you have any idea of a suitable single or dual h bridge MOSFET based? I’m finding only ones with a dir input ad a pwm, not true l298 similar
