Hello Adel;
At teh beginning of your function you are taking the analog input value from the analog channel, converting it to a REAL value, and dividing it by the maximum value that an analog input should have, 27648 (as a REAL). This is all basically OK.
Let's say you have 20 mA on the input, the analog value will be 27648.0. Divided by 27648.0, the result will be 1. Any other value will give the result of the division as smaller than 1, so M0,0 will always be true; M0.1 cannot ever become true.
If what you are trying to do is obtain a percentage, you should multiply the result of the division by 100.0. That way your comparisons will work.
Another point: your function does not take into account what happens when the values of the analog channel are not whithin their appropriate ranges. What happens if the signal is 20.4 mA (and overrange/underrange does happen, due to noise or miscalibration, for example) or the channel sends an error message, (hex)FFFF?
You might want to react differently than when the signals are within normal, expected range.
Hope this helps,
Daniel Chartier
P.S. I encourage you to develop your own functions for you own needs, of course. But have you looked at FC105 "SCALE", in the TI-S7 converting library?
Regards, D.C.