How to include decimal with fraction to encoder position

myusername

Member
Join Date
Feb 2022
Location
Philippines
Posts
3
Hi, 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 very much!
 
Hello,


I might be naive but, can't you simply multiply your computation result by 100 -> convert it into float -> divide the float by 100 ?
 
I dont know Omron CX programmer, but it looks to me as if you are using integers to represent the position.

1. You could have an implied decimal fraction, i.e. if the integer holds a value of 9565, it actually represents 95.65 mm. Be careful to not exceed the range of what an integer can represent, usually -32768 .. +32767.
2. Use floating point calculations throughout.
3. Instead of running to a position in mm, run to a certain no of encoder pulses. In this way you achieve a precision as high as the encoder can represent. You avoid introducing inaccuracies by the conversion to integer or floating point representation of the position in mm.
 
If I'm following correctly, you are taking the value you computed as a float and then converting to a DINT. You're data type needs to be a float to get the format you're looking for. Sounds like you don't need the conversion to a DINT. Maybe we are missing something in your steps/requirements.
 
Welcome to the forum!

Position encoder values do not usually contain fractional values, e.g. the values for a 10-bit encoder can only be 0, or 1, or 2, ..., or 1023.

How many encoder pulses (values) are there per mm?

If there is indeed only one encoder pulse per mm, then the best that can be done is to round that 95.65 to 96. The FIXL instruction will always truncate (drop; round toward 0) any fractional portion of a floating point value. If 95 is close enough, then FIXL by itself is good enough. If Omron does not have a rounding instruction, then add or subtract 0.5 to a positive or negative, respectively floating point value and then apply FIXL to the result.

xxx.png

N.B. Those example conversions are for illustration only, and otherwise bogus in the context of actual operation, because neither of the displayed values (2,147,483,640.5 and –214,748,340.5) can be represented in the 32-bit floating-point double-word.
 
Last edited:
Hi all, thanks for your help.
So, this is a program for a flow wrap machine. I need to set a certain number (in mm) on my HMI number input, this is my “P”. So this P is in mm and I need to input pulse on my encoder. I did it by dividing my encoder’s PPR to pi*drive diameter*P. But before I did that, I converted my PPR, drive diameter, and P to float.
Now I have a resulting pulse in float and I need to convert it to 32 bit to be read by my encoder. So, I used the FIXL instruction but it doesn’t include the 0.xx. I am thinking of using the “adding 0.5” tip as mentioned by drbitboy, but it seems that this will lengthen my process, I’d like to know if there is a better way to do this? Thank you again for your help.
 
I would assume OP is doing the math correct, something like

  • (HMI mm) * (1 revolution / (PI*diameter, mm)) * PPR pulse/revolution
  • (HMI * PPR / (PI * diameter)) (mm) (revolution/mm) (pulse/revolution)
  • (HMI * PPR / (PI * diameter)) (pulses)
However, encoders typically only measure position in integral pulses, that is, commands to the servo can only position the device to the nearest whole encoder pulse. P{ is correct in doing the math in floating point, but they cannot send a floating point value, with a fractional pulse, to the servo; they can only send an integer value to the servo.

So if OP needs a finer linear (mm) resolution, then they need

  • EITHER an encoder with more pulses per revolution,
  • OR a drive roller with a smaller diameter.
  • OR a change of the gearing between the servo encoder and the drive roller.
 
Hi all, thanks for your help.
So, this is a program for a flow wrap machine. I need to set a certain number (in mm) on my HMI number input, this is my “P”. So this P is in mm and I need to input pulse on my encoder. I did it by dividing my encoder’s PPR to pi*drive diameter*P. But before I did that, I converted my PPR, drive diameter, and P to float.
Now I have a resulting pulse in float and I need to convert it to 32 bit to be read by my encoder. So, I used the FIXL instruction but it doesn’t include the 0.xx. I am thinking of using the “adding 0.5” tip as mentioned by drbitboy, but it seems that this will lengthen my process, I’d like to know if there is a better way to do this? Thank you again for your help.


Here is food for thought.


The math interested me but I fully agree with drbitboy.
 
Last edited:
Now I have a resulting pulse in float and I need to convert it to 32 bit to be read by my encoder.
encoders don't read in fractions. There isn't a 1 to 1 correlation between positions in 0.1mm and counts. Sometimes a position in mm will be between two counts. Face it.
This problem is made worse if the PPR is not very high. I always recommend a 10,000+ ppr encoder assuming the every phase gets counted so the there are really 40,000+ counts per revolution



What do you want to do with the fractional counts anyway?
 
What do you want to do with the fractional counts anyway?


As it is often the case the poster declined to answer important questions asked by drbitboy so I chose to entertain myself with hypotheticals. Imagine an old machine with a prox or even a switch and sprocket or something pulsating that prox.
Say it is better to overwrap than to underwrap so anything above 0.32 would round up otherwise just round down; or the other way around.
 
Last edited:
If I wanted o express fractions of a count I would use 32 bits for the integer and 32 bits for the fraction where if the fraction is 80000000 it is 1/2 of 2^32. DSPs programmers use this.
https://en.wikipedia.org/wiki/Q_(number_format)
When I was programming 80186s I would use 16 bits for the whole number and 16 bits for the fraction. However, I never had a need to express counts as fractions. Usually I had to express millimeters and inches as whole numbers and fractions after converting counts to position units.
 
Hi, thank you everyone for your help. As Kalabdel mentioned, I am thinking of using the fractional counts because I want my result to be as close as possible to the actual measurement, or if it can't be done I figured it would be better to overwrap than to underwrap. Unfortunately I am presently working with an encoder with low PPR and it is uncertain if I can replace it with one having higher PPR to get a finer resolution.
 
Hi, thank you everyone for your help. As Kalabdel mentioned, I am thinking of using the fractional counts because I want my result to be as close as possible to the actual measurement, or if it can't be done I figured it would be better to overwrap than to underwrap. Unfortunately I am presently working with an encoder with low PPR and it is uncertain if I can replace it with one having higher PPR to get a finer resolution.




If there is more than one roller, moving the encoder to a roller with a smaller diameter would increase pulses per mm, which is what you are actually after.
 
Hi, thank you everyone for your help. As Kalabdel mentioned, I am thinking of using the fractional counts because I want my result to be as close as possible to the actual measurement, or if it can't be done I figured it would be better to overwrap than to underwrap.
It won't work. How are you going to estimate a fractional count?
It can be done but you need some very fast timers and the ability to latch the counts on each phase Then you count the time between the counts. I have done this.



Unfortunately I am presently working with an encoder with low PPR and it is uncertain if I can replace it with one having higher PPR to get a finer resolution.
Encoders are cheap relative to the time you will waste trying to work around it.
 
Hi, thank you everyone for your help. As Kalabdel mentioned, I am thinking of using the fractional counts because I want my result to be as close as possible to the actual measurement, or if it can't be done I figured it would be better to overwrap than to underwrap. Unfortunately I am presently working with an encoder with low PPR and it is uncertain if I can replace it with one having higher PPR to get a finer resolution.


You have a team of experts reading every word you write and offering free help and this is all you have to say.

Take advantage of the opportunity and give them something to work with 🔨 .........it is FREE.


What CPU are you using.
How many PPR? Single or two phase?

How many pulses per mm?
How is your encoder mounted.
Any other sensors triggering any part of the process?
 
Last edited:

Similar Topics

Good Morning , I am working on a project with some PowerFlex 525 drives. I am using CompactLogix 1769-L18. I took notice that the tags that...
Replies
23
Views
22,518
I want to post a question on a SLC 500 program. How do I post the program that I see on my screen for others to see and comment on?
Replies
4
Views
3,604
Help! I've created extra files online with Logix500, but when I try to include them in the main (JSR) the PLC faults. Any suggestions?
Replies
1
Views
4,641
In S7/TIA Portal, is there a function to round a real to a specified number of decimal places? e.g. If I have 22.519432 and I want to round it to...
Replies
16
Views
1,903
I am using a Micro 850E PLC (the new one with implicit messaging capability) to drive a Kinetix 5100 servo drive. The error code number on the...
Replies
7
Views
1,717
Back
Top Bottom