Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

SImple "C code" == complex simulink model?

1 view (last 30 days)
Viktor
Viktor on 24 Apr 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi,
There is very simple c code of "some" modulator.
if((PID_sum > CONST)) {
//Period const.
periood = MIN_PERIOOD;
impulls = ((unsigned int32)PID_sum* MIN_PERIOOD)/10000; // /10000
}
else {
//Impulls const.
impulls = MIN_IMPULLS;
periood = (unsigned int32)(MIN_IMPULLS * 10000) / PID_sum;
}
This code must be executed every time period counter ends and new period- and impulse duration will be calculated from code above.
There is my result in simulink:
God! It looks huge right?
I used some const variables that were declared in workspace used to- & from workspace blocks. Could be done without thease workspace transformations.
But it is "author of this thread" stuff... a almost first simulink "thing" he had done. Not good right. Problems with "from workspace" block init values.. fist thing that comes up. not scalable. + fixed time 0.1 which ist well suited to bigget variable time model.
How would you do it? Is it possbile to use somekind of mathalab functions simulink block. Or... can i have use c code? worth it? Or simulink block is the way to go. Just "to do" better solution?
Thank you in advance!

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!