"Custom" C Code with embedded Coder and TI C2000

조회 수: 9 (최근 30일)
Robert Zipprich
Robert Zipprich 2021년 3월 19일
댓글: Robert Zipprich 2021년 4월 19일
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
Birdman
Birdman 2021년 3월 22일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Roy Mathew
Roy Mathew 2021년 4월 18일
편집: Roy Mathew 2021년 4월 18일
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
Robert Zipprich
Robert Zipprich 2021년 4월 19일
Awesome, this code works out of the box. Thanks a lot for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by