How to saturate a variable according to my range in RTW embedded coder

Hi, I 'm generating an Auto code using an RTW embedded coder. I'm facing staturation issue when i tested the code. problem is saturating my variable according to my range of that variable is not taking, it takes as per the datatype of variable.
For ex: input variable name : abc
range : [0..255]
datatype: uint8
output variable name: out
range: [0..254]
datatype: uint8
implementation in model is out = abc + 1
generated code for this add block will be like
tmp = abc + 1 ;
if(tmp >255)
{
out = 255;
}else{
out = tmp;
}
Now out variable range will be limited to 255 but i need it till 254
How to set the staturation with my range for an output variable.
please help me!!!
Thanks and Regards, Nithin

 Accepted Answer

What about using the Saturation block at the output?

1 Comment

Hi Kaustubha,
Our Model design rule doesnt allow us to not add stauration block in model, but in addition block i have checked the saturation to overflow and also for outport of add block (i.e) out specifying the range as [0..254] but still code is generated like what i said earlier..
Is there any other option to be checked in model

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!