You need to log in to create posts and topics.

Scripted components | Implementation of arrays

Page 1 of 2Next

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?

Maybe better if you share what you did to have a look at it.

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.

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":

array_calls_and_function

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
Uploaded files:

With the "findValue"-function and 100Hz in STEP-block it looks like that:

Sixteenth Step with MS1, MS2, MS3 == 1, 1, 1 :

Sixteenth Step

If the frequency is set too high, the curves will not be displayed correctly when calling the array or using the findValue function. 

 

 

 

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):

dmilardo has reacted to this post.
dmilardo

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?

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.

Uploaded files:

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.

Thanks for the tip with the amp meter. That solved the problem with higher frequencies.

Page 1 of 2Next