how to determine if a encoder misses a single step

bara_hence

Member
Join Date
Aug 2007
Location
Ockelbo
Posts
225
I have an encoder that gives its position by 9bits gray code (512 steps) is there an easy way to make a software (in ladder?) to se if the encoder is ok and doesnt miss a position..

I came up with one soloution by my own and that is to use 513memory bits and compare value in with 0-512 and then set or reset each bit and then I can se wich position it has missed if it misses one but this gives a large program and it must be a better way..
 
Does the PLC have any form of indexed or indirect addressing? The value can be used to point into your table. (And the table can be 0 - 511 for 512 counts - you'll never get the number 512)

Except for the 0-511 transition, if you have a difference between readings of more than 1 then you have missed a count.

But make sure that it isn't a case that your PLC scan isn't fast enough to keep up with the transitions.
 
Yes the plc is some step5 plc is at home now so I cant say exactly what model but i can use indirect adressing..

With a table do you mean that i have as I sayd earlier 512 bits 0-511 (thanks for the correction) but instead of compares i use indirect adressing or do you mean anything else??

I dont think the plc is to slow the machine is around 10years and has worked until now.. no changes in original program or so..

Maybe this is better??

: invalue-recentvalue = diff
: cmp diff>0 if true then multiply by -1
: cmp difference>max difference if true move diff-max diff
: cmp invalue = 511 if true move 0 recent value
: move invalue-recentvalue

this way i se if the plc misses some step then the difference will be larger than one.. this needs that i convert gray to dec values but that is already done in the original program..

but maybe its okey to miss some steps of the encoder but if the encoder disc has faults and reads the value zero sometimes it shouldnt or something else its worse??
 
I have not dealt with this problem, so take what I say with a grain of salt.

Will the plc be running fast enough so that there will be at least one scan between each transition of the encoder?

What about excusive ORing the present reading with the previous reading and then checking to see if more than one bit is set as a result of this process. If there is no movement between the present scan and the previous scan, then the result of the exclusive ORing would be a zero. If the encoder only moves by one increment, then only one bit should be set by the exclusive ORing. If the plc has a instruction that can count the number of bits set in a memory location, then this should be fairly straightforward to implement in code.
 
i agree, are you sure plc scan is fast enough for this?
you may want to put it inside interrupt routine (still may not be fast enough).

if it is, i would simply check as follows:

Difference = Current_Value XOR Old_Value
Old_Value = Current_Value
if number_of_bits in Difference >1 then Show_Error
 
For fastest possible processing code has to be efficient (also needed when using interrupt) .
This also means one can avoid conversion to decimal to perform subtractions etc.
One way is to check for single bit change because this is how gray code works
(one position increment or decrement only changes one bit).

To check if there is no change (encoder not moving), simply compare difference with zero.

To see if just one bit is set, see if value of Difference is same as "processed copy"
which originated from Difference but has just one bit set. This should be complete code

 
Difference = Current_Value XOR Old_Value ' identify changed bits
Old_Value = Current_Value ' update Old_Value for next comparison
Copy = (0-Difference) AND Difference ' find one bit that has changed
IF (Difference<>0) AND (Copy <> Difference) THEN Show_Error ' test if only one bit changed

 
Just in case this wasn't clear:

The 'XOR one bit difference' test must be performed on the Gray Code form of the input.

The '1 count max difference' test must be performed on the converted form of the input.
 

Similar Topics

Hello, i am a beginner with a Siemens Logo 8 PLC. I would determine the direction of an object if it passes a whole cycle of 2 input sensors. See...
Replies
2
Views
163
Hi all, Just looking through the CIP_AXIS_DRIVE data type in a Logix controller to look for something that can tell me whether the current...
Replies
2
Views
1,030
I'm currently working on an MES interface PLC which passes around a whole bunch of strings. A lot of these strings are really just to allow for an...
Replies
0
Views
1,099
I don't use AB much these days, and any installs I've done in years past have been setup by myself from scratch, so I've always known what...
Replies
8
Views
2,057
Hello: I wonder if there is a way to find the CPU load of a Logix processor, and if it is not possible to determine this in an absolute way, I...
Replies
6
Views
1,924
Back
Top Bottom