Convert Floating point number to Integer and back in SLC 5/03

P

Thread Starter

Purna

I have to develop a program where I have to read the voltage setting from the panel view which will be in floating point format and compare that to the analog feedback. I think I have to convert this floating point value to integer in order to compare it to the analog voltage.

I also have to display the current voltage value of the process on the panel view which has to be in floating point format.

Thanks.
 
S

Steve Myres, PE

Why not convert the analog input to a float using a SCP box, and then do all your control and display in floats?
 
Your analog feedback will be in the range 0-32767, so use the SCP instruction to convert the floating point value from the panelview to a scaled integer. Example if your input is in the range 0 to 10.0 and the floating point value is in F8:0 and your scaled result is in N7:0 then
SCP F8:0 0 10.0 0 32767 N7:0.
Now you can compare N7:0 to the input. You can do the same thing in reverse to convert the input to floating point.
SCP I:10.0 0 32767 0.0 10.0 F8:1.
Be sure to trap and reset the math overflow minor error before the scan ends.
 
S

ScienceOfficer

Purna---

I don't understand your plan. All of the devices you mention except the analog input module can work in floating point, and the analog input should probably be scaled to a floating point value anyway. It's easy to work with floating point in the 5/03--- why limit yourself to integers?

I recommend that you use the SCP (Scale with Parameters) instruction to read the analog input and put a useful result in a floating point register, say F8:0. Let the PanelView display F8:0, just as you need, and also use F8:0 to do your comparisons.

Hope this helps!

Larry Lawver Rexel / Central Florida
 
P
Hi There,
Would it not be easier to Scale the input value of your analogue input.
When you scale it, it becomes a real number. This is much less work.
Scale input :
OUT = [ ((INT(IN) – K1)/(K2–K1)) * (HI_LIM–LO_LIM)] + LO_LIM
K1 = 0.0 and K2 = +27648.0 (unipolar)
Hope this helps.
Regards,
Paul.
 
I am not sure what you are trying to do. I assume you would like to bring in from panelview a floating point 0.000 - 10.000 as your desired voltage and control an analog signal output from 0-10 volts. If so bring in float with 3 decimal places 0.000 to 10.000 then program your plc to multiply this float by 1000 and return the result destination in an integer,were 10 volts would be 10000 integer equivalent. then program your plc to SCP (scale with parameters) input source will be this new integer and in min 0 in max 10000 scaled min 0 scaled max 32767 output will be another integer used to compare to your analog input word. I hope this helps.If this is not what you need post a few more details and I be glad to assist.
 
Take your floating point into an multiply block and multiply it buy 100 or 1000. this will move the decimal point to the right maintaining your numbers resolution. After that take the new integer and do your logic and then divide by the same 100/1000 to display it on your screen.
 
Why not convert your integer to a floating point that way your only doing one conversion. Use a mov function for the conversion.
Good luck
Mike
ISG
 
Top