tempname24756

Convert word to float?

6 posts in this topic

Hello. I have a digital signal sending a value to D1. I want to scale it down using this formula '(D1-1000)/100'. I've made my own function blocks using ST and at the moment it looks like this. The initial value is is 1454 and as you can see the subtraction works. It is now that I get some problems though. I want the value stored in D3 to be 4.54 but I don't know how to convert the data type to a float type. I've tried to use the word to real function but that did not work. I've tried to do FLTP(D2, D3);before the divide function but no cigar. I've also tried to change the data type of the D3 label directly but that gave me an error, as expected. I don't know what else to try so I'm turning my attention to here. Thank you. EDIT: U2/G11 = D1 Edited by tempname24756

Share this post


Link to post
Share on other sites
A couple of questions. What PLC are you using, and what programming software version.

Share this post


Link to post
Share on other sites
Sorry, I should have included this information. I use gx works 2 with mitsubishi's Q02H cpu paired up with a Q64AD i/o module.

Share this post


Link to post
Share on other sites
Update; so I solved the issue and I feel so dumb right now. Everything could be done in 3 steps of ladder code and it took 10 seconds to write it out, haha. This is how I solved it.

Share this post


Link to post
Share on other sites

I'm looking for the same.
How did you do?

 

Maybe not exactly the same but want Word to Float.
Ex: 102 = 1.02

Edited by Jonas80

Share this post


Link to post
Share on other sites

@Jonas80 Pardon the crudity of the logic but the following changes your requested word 102 into float 1.02

Changing from INT to FLT requires the instruction FLT. Remember that integers only need one register while FLT require two. So when MOVing an int value of 102 into D0 the FLT instruction stores 102.00 into D2 and D3.

Also because we are now dividing a FLT number the modifier on the math instruction (divide) needs an E in front and the reference floating number is now prefaced with an E (float) not a K (integer).

Our result of 1.020 is now stored in D4 and D5.

Hope this helps.

CALC.thumb.png.03c754d7720e1648688f6da86

2 people like this

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