"Custom" C Code with embedded Coder and TI C2000

34 views (last 30 days)
Hello all,
For a small project with the F28379D-ControlCard im using the embedded coder from simulink with the C2000 support package. I have to interface the AD7616 from Analog devices and slowly i'm getting mad with the whole thing...
To get the AD7616 working, i have to fulfill a spezial initialization for the AD, which requires some waiting states. To get this initialization, i create a subsystem in my simulink model with an event listener and an own subsystem contains of a for-itterator, switch case and some GPIO's and SPI. Everything works fine, but i have to met some timing requirements, which can i only achive if i have some small delays in the setup-code. So all i need is that the coder will insert the "DELAY_US(5)" while generatig c-code, and this is the main part of my actual problem. If i insert exactly this line of code manually after generating the CCS-project, everything works fine, but there must be a way the coder will do it by itself.
So my question is if there exists some simulink-block, wich will add my handwritten code in the needed place or which will result in the needed lines of code?
what i´ve tried so far:
  • use c-function-block : results in the error "implicit declaration of DELAY_US(5)". it seem's, that simulink didn't recognize the function, but after generating the project and add the line of code manually, the µC will do the thing. Furthermore all needed directories, including the one directory contining the neccessary files, are present in the generated CCS-Project.
  • use blocks from Simulink-Coder/Custom Code : those blocks can't be used in a subsystem with an event listener. If i remove the listener, the needed line of code appers in the generated sources, but this can't be the solution to remove the event listener in my init-subsystem since this subsystem has only to run once after power-up.
i hope someone has had a similar problem and can help me with this. In the meantime i will try to solve this problem and will post some updates if something changed.
Kind regards,
Robert Zipprich
  1 Comment
Birdman
Birdman on 22 Mar 2021
The only way to manually edit the code generated from Simulink model is to use Custom Code blocks. So you need to find an alternative about using the event listener structure.

Sign in to comment.

Accepted Answer

Roy Mathew
Roy Mathew on 18 Apr 2021
Edited: Roy Mathew on 18 Apr 2021
C Function block needs the function prototype defined either in the Simulation target or for code generation only, in the C Function block itself.
So, you could call the function similar to shown below:
#ifndef MATLAB_MEX_FILE /* Codegen only */
extern void DELAY_US(int);
DELAY_US(5);
#endif
  1 Comment
Robert Zipprich
Robert Zipprich on 19 Apr 2021
Awesome, this code works out of the box. Thanks a lot for your help!

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!