(Almost) Simulink target for teensy

albertoc

New member
Hi to everybody,

I'm trying to develop a Simulink library for interfacing teensy to Simulink coder hoping to obtain a simple interface for building general purpose real time controllers.
The simplest way for achieving the scope is s-function block, in which the code is written in Arduino-like way. The Simulink model is compiled in c++ and than flashed with the Arduino IDE.

The most cool thing is that it works!!! Of course you need a little bit of manipulation (like attaching the generated main function to a periodic interrupt according to the control timestep).

Screenshot 2023-06-12 205502.png

The implementation of all the functions and libraries is limitless and there is a very little effort in doing this, except one: external interrupt routines.

Do you know and method to implement ISR through Simulink? Some sort of asynchronous task which is executed with higher priority independently from the model execution. I'm not focused on how to deal with asynchronous tasks in Simulink (Arduino target code is crypted).

Of course the library and the methodology will be shared with the community.

Thank you!
 
Hi albertoc,

That sounds and already looks like a cool feature. I'm very interested once you are ready to share, and how this is working within Simulink.

Unfortunately, I'm not an Simulink expert, however I found some stuff reagarding this topic.

The NXP MBDT Toolbox got at least Simulink Blocks for ISR. It can be found here:
https://www.nxp.com/design/development-boards/motor-control-development-solutions/model-based-design-toolbox-mbdt:MBDT

Here https://www.mathworks.com/help/rtw/event-based-scheduling.html?s_tid=CRUX_topnav they are talking about an event based scheduling.
I would a assume that Simulink coder, could generate a separate function, that could hopefully be attached with an attachInterupt() Fucntion.
attachInterrupt(digitalPinToInterrupt(23), mySimulinkInterruptFunction, FALLING);
Thus, you will have the Step-Function and a separate ISR Function generate by the Coder.


Once shared, i would look on my end, if a CanTransmit and CanReceive Block using the FlexCan_T4 libary could be implemented as well.

Regards Bob.
 
Hi Bob08,
thank you for your support.
I've found a workaround for the topic. The most simple thing to do is to set the subsystem as atomic and to package as reusable function. In this way the code is generated for the function and it can be inserted into an interrupt routine.
Screenshot 2023-06-17 154606.png
The workaround is working pretty well but it is not "build and flash" as the standard support package.

For the implementation of FlexCan_T4 library, I can't see any problem, it is sufficient to write the s-function in arduino-like way.
 
Any updates? It seems a very interesting.
In the past I generated C/C++ code with the Simulink Embedded Coder and then included the generated code in my code, but I think yurr methodology may be better.
 
Back
Top