Scripted components | Implementation of arrays

Quote from dmilardo on May 22, 2025, 11:56 amIn the old version 1.0.1 R1336, I implemented the A4988 motor driver as a scripted component.
However, the newer versions no longer use JavaScript, but AngelScript. When I create a lookup table and want to retrieve the values individually from the array, Simulide crashes shortly after starting the simulation.
How exactly do i have to implement an array?
In the old version 1.0.1 R1336, I implemented the A4988 motor driver as a scripted component.
However, the newer versions no longer use JavaScript, but AngelScript. When I create a lookup table and want to retrieve the values individually from the array, Simulide crashes shortly after starting the simulation.
How exactly do i have to implement an array?


Quote from dmilardo on May 23, 2025, 4:34 pmWhile I was trying to create a short documentation, I noticed that it works with the latest version SR1, but only sometimes. The same code and test setup doesn't work with version 1.1.0 R2056. In this version, the connection to the VMOT pin is the problem. I'll take another look at the code, since the problem isn't the array call after all.
While I was trying to create a short documentation, I noticed that it works with the latest version SR1, but only sometimes. The same code and test setup doesn't work with version 1.1.0 R2056. In this version, the connection to the VMOT pin is the problem. I'll take another look at the code, since the problem isn't the array call after all.

Quote from dmilardo on May 23, 2025, 7:06 pmHere are my files for the A4988. One .as-file has the Vmot pin, the other doesn't. The original code is the file "A4988_core_with_Vmot.as." In one case, the Vmot pin was the problem, hence these two versions. Since I previously considered the array call to be an error, I implemented a function with simple if-else statement "findValue" to replace the lookup table. Right now, it works without the array call, and only sporadically without it. I can't figure out what exactly causes Simulide to crash sometimes and allow the simulation to run through in the other case. This happens regardless of whether Simulide itself is restarted.
Array calls and the function "findValue":
In "Other files.zip" are:
- all changed files for the implementation of the scripted component
- a testbuild "A4988_testbuild.sim1"
- the folder of A4988 with the integrated circuit (SENSE-, Vmot- and GND-Pins) file for the ICs folder: "A4988 driver"
In "scripted A4988.zip" are:
- .mcu-file
- both mentioned scripted .as-files
- .package-file of A4988
Here are my files for the A4988. One .as-file has the Vmot pin, the other doesn't. The original code is the file "A4988_core_with_Vmot.as." In one case, the Vmot pin was the problem, hence these two versions. Since I previously considered the array call to be an error, I implemented a function with simple if-else statement "findValue" to replace the lookup table. Right now, it works without the array call, and only sporadically without it. I can't figure out what exactly causes Simulide to crash sometimes and allow the simulation to run through in the other case. This happens regardless of whether Simulide itself is restarted.
Array calls and the function "findValue":
In "Other files.zip" are:
- all changed files for the implementation of the scripted component
- a testbuild "A4988_testbuild.sim1"
- the folder of A4988 with the integrated circuit (SENSE-, Vmot- and GND-Pins) file for the ICs folder: "A4988 driver"
In "scripted A4988.zip" are:
- .mcu-file
- both mentioned scripted .as-files
- .package-file of A4988

Quote from dmilardo on May 23, 2025, 7:20 pmWith the "findValue"-function and 100Hz in STEP-block it looks like that:
Sixteenth Step with MS1, MS2, MS3 == 1, 1, 1 :
If the frequency is set too high, the curves will not be displayed correctly when calling the array or using the findValue function.
With the "findValue"-function and 100Hz in STEP-block it looks like that:
Sixteenth Step with MS1, MS2, MS3 == 1, 1, 1 :
If the frequency is set too high, the curves will not be displayed correctly when calling the array or using the findValue function.

Quote from arcachofo on May 23, 2025, 8:48 pmThanks for all the files.
I think the problem could be related with the nested array, a solution could be to use 4 arrays and do something like this:
OUT1A_Pin.setVoltage( VDD_Value*arr1A[pos_y] ); OUT1B_Pin.setVoltage( VDD_Value*arr1B[pos_y] ); OUT2A_Pin.setVoltage( VDD_Value*arr2A[pos_y] ); OUT2B_Pin.setVoltage( VDD_Value*arr2B[pos_y] );
I could also suggest to use current controlled sources for the sense inputs.
Using the Amp meter will update at low frequency (20 Hz by default):
Thanks for all the files.
I think the problem could be related with the nested array, a solution could be to use 4 arrays and do something like this:
OUT1A_Pin.setVoltage( VDD_Value*arr1A[pos_y] );
OUT1B_Pin.setVoltage( VDD_Value*arr1B[pos_y] );
OUT2A_Pin.setVoltage( VDD_Value*arr2A[pos_y] );
OUT2B_Pin.setVoltage( VDD_Value*arr2B[pos_y] );
I could also suggest to use current controlled sources for the sense inputs.
Using the Amp meter will update at low frequency (20 Hz by default):

Quote from dmilardo on May 24, 2025, 11:14 pmThanks for the quick response.
I tried it, but it still crashes occasionally. However, once the simulation is running, I can stop and restart it immediately as needed. But if I delete the current component and replace it with a new one, it crashes again.
Is there a way to get a detailed crash report so I can see which initialization step of the component is causing the problem?
Thanks for the quick response.
I tried it, but it still crashes occasionally. However, once the simulation is running, I can stop and restart it immediately as needed. But if I delete the current component and replace it with a new one, it crashes again.
Is there a way to get a detailed crash report so I can see which initialization step of the component is causing the problem?

Quote from arcachofo on May 25, 2025, 1:08 pmSeems that there is a problem with modulo operation % using negative numbers.
To investigate the issue I did quite a few changes, attached my last implementation that seems to work.
Note that also did some changes to .mcu file.
Seems that there is a problem with modulo operation % using negative numbers.
To investigate the issue I did quite a few changes, attached my last implementation that seems to work.
Note that also did some changes to .mcu file.

Quote from dmilardo on May 25, 2025, 3:35 pmI've copied your files and the circuit, but Simulide still crashes when I turn off the voltage at ENABLE, which allows the values to be read from the array. I'll discuss it with my professor again. Perhaps my PC is also causing the problem.
I've copied your files and the circuit, but Simulide still crashes when I turn off the voltage at ENABLE, which allows the values to be read from the array. I'll discuss it with my professor again. Perhaps my PC is also causing the problem.
