SImple "C code" == complex simulink model?

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!

Réponses (0)

Cette question est clôturée.

Produits

Question posée :

le 24 Avr 2013

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by