Sign in to follow this  
Followers 0
prtbrown

floating point constant

10 posts in this topic

I need to set the midpoint of a PID function via sensor readings. The min and max are 0.7-1.0 hence I want to set the midpoint at 0.85. I want to use the Mov instruction to move a floating point number constant (0.85) into an UINT variable but I don't know how. Could I just set the midpoint at 85 and scale the sensor readings by x10? Edited by prtbrown

Share this post


Link to post
Share on other sites
If you are doing floating point maths and have to use constants you must use the FLT (32 bit) or FLTL (64 bit) to turn a constant into a floating point number.. If you wish to move a floating point number you can use MOV (16 bit floating point number into a 32 bit register) or MOVL (long move - 32 bit floating point number into a 32 bit register). Remember 32 bit floating point uses 2 registers (D) and 64 bit floating point uses 4 registers for each number - easy to forget and try to use adjacent D registers instead of allowing 2 Ds between each number.

Share this post


Link to post
Share on other sites
You can't store a number with decimal places in anything other than REAL (floating point) format. So you can't put 0.85 into a UINT. As you indicated, you can multiply the values by 100 (not 10) so 85 mean 0.85. Or you can convert the values all to floating point like BobB said. The Omron PLCs (you never said which model) should have support for floating point math, comparison, etc. so no reason not to use floating point for the extra accuracy of the decimal places.

Share this post


Link to post
Share on other sites
What did you mean by midpoint for PID function? Variables for PID instruction must be UINT.

Share this post


Link to post
Share on other sites
Another thing to note, he FIX function that converts FP to UNIT does not round the value so 0.85999 will result in 85 not 86.

Share this post


Link to post
Share on other sites
Yes, that is an annoyance. FIX and FIXL truncate the decimal part. I would like to see these functions at least shift the left over into another channel so that they can be accessed.

Share this post


Link to post
Share on other sites
Yep, it's a pain. The easiest fix is to add 5 to the first digit you don't use, in this case it would be +0.005.

Share this post


Link to post
Share on other sites
thanks for the replies. this is my first job working with PLCs (but learning quickly!) I am reusing code from another programmer. Under the PIDAT (191) instruction he has set the Setpoint Value as an operator input value (IDEAT1_PID_SV) which is an UINT. In the screenshot of the HMI the example input value is 7.2. For my present spec, I need to fix the setpoint at a value of 0.85. So my confusion is how do I set 0.85 as a constant in the PIDAT instruction? The CPU is a CS1G-H Edited by prtbrown

Share this post


Link to post
Share on other sites
Multiply by 100

Share this post


Link to post
Share on other sites
There is probably some scaling involved, first you need to find the input range of the PIDAT itself. Look for a MOV that puts a HEX number like #1494 in the Setpoint + 6 address. IE if the setpoint is at address D3101, the range control parameter is in D3106. the second digit (from left) is the input range/resolution. 0 is 8 bits, 8 is 16 bits. 4 is a common value, that gives 12 bits resolution and a range of 0 to 4096. A setpoint of 50% would then be 2048. Geir

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