Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

C-script vs DLL vs PIL

0 votes
817 views
Hi

I have a reasonably complex C-code written for STM32Fxxx. It's an implementation for a sensorless FOC observer for position and speed

I would like to interface this with the PMSM model example in PLECS and see the performance with respect to the 'truth'.

I have used C-Script a couple of times, but i think this approach would be messy, because

1) I have multiple header files included in the C-Code

2) The code is written to use CMSIS ARM_DSP for matrix operations. (Sure those functions could be rewritten but it'll be time consuming and messy)

I guess if somehow all the header files (including the suitably modified ARM stuff) were copied into the code declarations (It would be one massive 5K line long code declaration) and the initialization routine was copied to the (start function code), things could work, but it's an awful lot of work and if a bug is discovered, corrected it in the C-Script and making equivalent changes in the embedded code is again prone to errors.

So i looked at the DLL option..

I don't use Windows (Only Linux) and the example uses Visual Studio and seems complicated, so i kind of ruled that out.

So i was wondering if the PIL option is best(only option) suited for this problem ?
asked Jul 11, 2020 by srinath (26 points)

1 Answer

0 votes
I had a similar Problem where DLL didn't work because im on Linux, C-scripts were complicated and the plecs documentation unreliable.
I switched to Matlab/Simulink and used plecs Blockset as Matlab is much more flexible with interfaces to other code. Maybe thats something to consider for you aswell.
answered Aug 21, 2020 by Hannes (29 points)
Hi

I got DLL working on Linux with PLECS. It takes a little bit of work, but is the best bet IMO. I have it working for a variety of combinations (Inputs, outputs, parameters, initialization functions, reset routines etc).

You have to link to the .so file if you are using Linux and not a "dll", but be sure to include the file "Dllheader.h" in your build process.

You may find the attached makefile useful.

Got C-Scripts working too. But that was real easy, just follow the example in the documentation and tweak it slowly from there. Remember that simulationTime is a macro that is available to C-Script.
Thanks a lot for this solution and the make file!
Nice work @srinath!
...