# Motor-controller model diverges when defects are added

**URL:** <https://scilab.discourse.group/t/motor-controller-model-diverges-when-defects-are-added/891>\
**Category:** Xcos\
**Created:** [April 3, 2025, 12:25am UTC](https://scilab.discourse.group/t/motor-controller-model-diverges-when-defects-are-added/891 "2025-04-03T00:25:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shon\_Shon](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Shon\_Shon](https://scilab.discourse.group/u/Shon_Shon)\
**Post date:** [April 3, 2025, 12:25am UTC](https://scilab.discourse.group/t/motor-controller-model-diverges-when-defects-are-added/891/1 "2025-04-03T00:25:23Z")

</div>

Hello there, I’m kind of new to scilab so I’ll introduce myself: I’m Shon\_Shon, I’m a college student studying awesome control, robotics and informatics stuff, and I found scilab because of xcos and it’s use for modeling systems.  
I am currently doing a proyect where I model a permanent magnet synchronous motor and a controller with a reduced observer for it based on a guide given to me by a teacher. It works really well when the sensors and modulator are ideal, but as soon as I added second order transfer functions to the sensors and modulator it all went unstable. I need to make the sensor extremely fast for the system to barely converge. Some of my classmates did the project in simulink and theirs didn’t have that problem.  
I added lot’s of graphs to see what is going on, but apparently it just starts like a small vibration in the current that grows more with each cycle until it eats the original signal.  
The reference signal is the integral of a triangle curve that starts at 0, goes up, goes down and returns to 0.

I just don’t know what to do.  
I’ll send the system models with and without delays so you can compare them, and also a functions file you need to execute before simulating.  
If any wizard out there could take a look, say “Elemental, dear Watson” and tell me why it’s diverging I would be extremely grateful.  
[park.sce](https://scilab.discourse.group/uploads/short-url/4m1DZVXUegwv2kKbJTjefb2fydz.sce) (1.3 KB) (functions file)  
[prueba\_integracion\_moduladores\_4\_err.zcos](https://scilab.discourse.group/uploads/short-url/qSddzG6G56g09QDEdIdNpAsWndf.zcos) (45.2 KB) (model that diverges)  
[prueba\_integracion\_moduladores\_2.zcos](https://scilab.discourse.group/uploads/short-url/nOfSqkix7boHPZ9cVhWPEKXB8Pf.zcos) (39.7 KB) (model that doesn’t)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [April 3, 2025, 8:57am UTC](https://scilab.discourse.group/t/motor-controller-model-diverges-when-defects-are-added/891/3 "2025-04-03T08:57:58Z")

</div>

Hello,

Frankly speaking, this is hard to see what could be happening in a complex diagram like this. What I can say, is that there is an instability which prevents to simulate the system with good precision (trying to decrease relative and absolute tolerance of the solver does not help). I think that the problematic subsystem is the second order

`wn_ang^2/s^2+2*wn_ang*s+wn_ang^2`

if you multiply wn\_ang by 2 (`wn_ang = 4000*3*9`) then there is no instability, but the closer to `2000*3*9`, the larger the instability, i.e. see below for `wn_ang = 2100*3*9`:

 ![Screenshot 2025-04-03 at 11.19.12](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/7db525b7837437689e47c521688728fe216d42ff.jpeg)  
 ![Screenshot 2025-04-03 at 11.19.09](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/c2734770483824dc4570b306d9f9ce3a9b557d7a.jpeg)  
 ![Screenshot 2025-04-03 at 11.19.06](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/ba5b8958d99adc23e3dbe08162d179fe3f9a9f82.jpeg)

It’s not a problem of Xcos vs. Simulink here but rather a misconception in your system, I hope my brief analysis above can help you to find where.

S.

---

<div class="post-metadata">

**Author:** ![Shon\_Shon](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Shon\_Shon](https://scilab.discourse.group/u/Shon_Shon)\
**Post date:** [April 5, 2025, 2:41pm UTC](https://scilab.discourse.group/t/motor-controller-model-diverges-when-defects-are-added/891/4 "2025-04-05T14:41:13Z")

</div>

Thanks a lot.  
I briefly considered a resonance of some kind it, but my classmates showing me their models working alright dispelled it for me. Thanks a lot for taking the time to review this.  
I’ll try finetuning the frecuencies to avoid the instabilities.  
If it works I’ll update this thread with another post.  
Thanks again for experimenting with my model to find these things out, I’ll take the time to answer other questions I have the knowledge for too. 🧡
