Sign in to follow this  
Followers 0
Bryll

Scale an integer value

4 posts in this topic

I uploaded a function to scale an analog value in integer format in the download section. It can be used instead of the standard Siemens "Scale" function, but it will give you the possibility to select the range of the input signal.

Share this post


Link to post
Share on other sites
Hi Bryll, Can the function, developed by you, operate with unlimited integer values like: In= 2536 (for example) In_Min= -32768 In_Max= 32767 Out_Min= 32767 Out_Max = -32768 ?

Share this post


Link to post
Share on other sites
Sorry for late response, but yes it should work. I made the same function for Mitsubishi and I use it in almost every program I write Edited by Bryll

Share this post


Link to post
Share on other sites
Dear Brill, Just want to draw your attention. If to implement the traditional equation Out = Out_Min + [ ( In - In_Min ) * ( Out_Max - Out_Min ) / ( In_Max - In_Min ) ], 'as is' for the scaling purposes, then all residual values are limited in range from -32768 to 32767, otherwise a negative or positive overflow will occur and the result of calculation will be wrong. To prevent the overflow, values of all operands has to be a half-limited... To avoid this effect and to provide that the scaling function would be able to operate with unlimited integers, another arithmetical equation must be used. If you have already took into account this chip, then your code is smooth. Edited by Inntele

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0