Jo Palm

How do i include the fractional part of the position I set for encoder

2 posts in this topic

Hi, I need help with my program. How do I include the fractional part of the position I set for encoder? I have an Omron PLC and using cx programmer. 
I need to command my servo (from HMI number input) to move to a certain position.

Now using a manual computation, my servo is supposed to move 95.65mm, however, using my plc program, the resulting position doesn't include the 0.65. I used the FIXL instruction to convert my result from float to 32 bit and it removed the fractional part of the value.


Thank you!

Share this post

Link to post
Share on other sites

you need to think how the values are stored....

position measured by encoder is an integer since pulses are counted (0,1,2,3...). so there is no decimal point.

to convert that into real world measure (inch, mm degree or whatever) one can process that value and store it a floating point type.

but if you want to go reverse, for example to enter some setpoint. you really need to go backwards.

note that decimal point is actually only used with floating point data type, also known as REAL or FLOAT. INT/DINT etc do not have that,

so your setpoint such as 95.65 need to be converted into something else and integers do not have fractional parts.

a good way to get around this is to use fixed point representation. in floating point, place of decimal point can move or float. in fixed it is fixed. 

one can choose location of the fixed point based on required accuracy. one common solution is to use 3 decimal places.

so when you use an integer such as 145318, value would really mean 145.318. decimal point is assumed to be at filed location - three places from the right.

in your case such conversion would involve multiplication by 1000 before using FIXL. less significant positions would still be lost of course but you retain ones that matter...

1 person likes 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