Could it be that you're really working with a pulse-type encoder?
Could it be that your limits are monitored by proximity switches?
Could it be that your backstop moves very slowly? Or, quickly?
Where are your sensors located relative to each other?
How are your sensors oriented?
With respect to your encoder information... I really doubt that it is in BCD form. I suspect it is a pulse-type encoder. In that case your PLC simply counts pulses. If the encoder is moving "Forward" the PLC counts "UP". If reverse, the PLC counts "DOWN". You have to maintain the Current "COUNT" to know where the back-stop is at any given time. Of course, as you indicated, there has to be a reference-point.
As far as "changing to mm", you need to know how many pulses represent 1-mm. Better yet, you need to know how many pulses represent 1-meter. You need to know how many pulses occur over the largest distance you can manage. At the same time, you want to have the largest number of pulses you can manage as well.
The maximum number of pulses can be attained by mounting the encoder on that axis which rotates the most. Typically, that is on the motor itself. However, in some gearing situations, the maximum number of rotations might occur on some other axis. Or, just for the sake of developing a large number of counts, you might use gearing just to drive the encoder.
The point is to make it so that each pulse represents the smallest amount of travel that is reasonably possible.
Some extreme examples:
VERY BAD CASE:
If you can get 10-pulses while the back-stop moves 100-mm, then you have...
10-Pulses / 100-mm = 1/10-pulse / 1-mm THIS IS VERY BAD!
You CAN NOT DETECT a 1-mm MOVE! You would have to move 10-mm just to get 1-pulse!
BETTER, BUT STILL A BAD CASE:
If you can get 100-pulses while the back-stop moves 100-mm, then you have...
100-Pulses / 100-mm = 1-pulse = 1-mm THIS IS STILL BAD!
The back-stop move could have an error of up to +.999999...-mm in Forward or up to -.999999...-mm in Reverse.
The back-stop could move as far as 1.9999...-mm (damned near 2-mm) on a single pulse.
BETTER CASE:
If you can get 1000-pulses while the back-stop moves 100-mm, then you have...
1000-Pulses / 100-mm = 10-pulses = 1-mm --->>> 1-pulse = 1/10-mm THIS IS BETTER!
The back-stop move could have an error of .099999...-mm.
MUCH BETTER CASE:
If you can get 10,000-pulses while the back-stop moves 100-mm, then you have...
10,000-Pulses / 100-mm = 100-pulses = 1-mm --->>> 1-pulse = 1/100-mm THIS IS MUCH BETTER!
The back-stop move could have an error of .009999...-mm.
EXCELLENT CASE:
If you can get 1,000,000-pulses while the back-stop moves 100-mm, then you have...
1,000,000-Pulses / 100-mm = 10,000-pulses = 1-mm --->>> 1-pulse = 1/10,000-mm THIS IS EXCELLENT!
The back-stop move could have an error of .000099...-mm.
Now, some of these numbers seem to be a little unmanageable for a typical 16-bit word (Max Value = 65,535). You handle this by tracking REVs.
If your encoder delivers 4000-Counts per Rev, then you'll run out out "number-space" at 65,535-Counts / 4000-Counts per Rev = 16.38375 Revs. So..., you count Revs as well as Counts to indicate the current position. Every 4000-Counts = 1 Rev. You then need to know how many Revs and Counts = 1-mm. Multiply accordingly.
Important Point to KNOW!
Now, at this point, it is very important to recognize that any subsequent moves should be based on the original reference point. That is, DO NOT make subsequent moves relative to the current position. Doing so incorporporates the error associated with the previous move.
If all of the previous subsequent-moves have been made relative to their particular "positions", then the latest current position has all of those errors associated with those previous moves incorporated into the current position.
For example, if you move to position-X, you will get there within the possible error. If you then use the previously-intended position as the origin for the next move, the next move is made relative to that error-prone position.
So, if you make each move relative to the previous "known-position", each subsequent move incorporates the error associated with that previous position as well as the error associated with all previous relative moves.
After a while, your position is off by more than 1- or 2-mm, and possibly worse, as time goes on.
So, the point is, make your moves absolute relative to the reference-point!!!
Damn! I didn't expect to go on so long. But then, this is a really critical aspect of motion control, and it needs to be understood by all that use it.
Andy,
One of THE MOST IMPORTANT things about process control is to learn how to "Ask the right questions". MANY times, if you finally figure out the right question to ask, the answer mysteriously appears before you get a chance to post the question!!!! That is, with a little bit of forethought, you can answer your question yourself!