Encoder Rollover

Guest

Guest
G
In our application we are trying to measure length of product traveling on a conveyor. We are using a SLC 5/04 with a with a 1747-HSCE module. Resetting the module for every piece isn't working for us.

What about just letting the encoder continue to count and rollover. Snap shot the accumulated value on the leading and trailing edges do the math.

Where I need help is when the rollover is between the leading and trailing edges.

Thanks
 
If you don't have multiple encoder rollovers in the total length, you can simply compare the leading edge value to the trailing edge value. If the trailing edge value is LOWER, then a rollover has occurred.

Rollover = no, then trailing edge value - leading edge value = length

Rollover = yes, then max. encoder count (rollover value) - leading edge value + trailing edge value = length

But wait until the PLCs.net 'day shift' arrives, as someone will post a MUCH better method than this... :D

beerchug

-Eric
 
What Eric says is a start.

To account for multiple rollovers, you could have a rollover counter.

Every scan store the encoder value. Next scan compare the current read to the last. If it is lower, increment your counter.

Be sure to start the count at zero.

Now Eric's formula is
rollover_count * max_encoder_counts - leading_edge_value + trailing_edge_value

and you don't need the if statement.
 
There is a flaw in my formula. What if your leading edge is higher than the trailing edge but no complete revolution of the encoder? As I re-read the first post, this is the main point. I don't have time right now to look at it. Maybe someone else can jump in.
 
Guest,
This is a tough one without knowing some more things. If the encoder can rollover from Max Count to 0 during a product scan, then it will be difficult to get a length measurement without additional information. Also, can the encoder go around more than once on long packages (will there be products longer than the encoder)? If not, it makes things a little easier

I have seen this done with a package conveyor line, and the trick was to use a photoswitch mounted next to the encoder to tell the PLC when to start counting and when to stop. When the photoswitch starts "seeing" the box, take an encoder reading. When the box trailing edge passes, the switch goes off, and the PLC takes another encoder reading. Then as Rick and Eric said, Length = Trailing Edge - Leading Edge UNLESS the Leading Edge is larger, then you have to say: Length = Maximum Count - Leading Edge + Trailing Edge.

There is an alternative, if you have the photoswitch and an encoder that sends an output pulse for every incremental distance. For example, if one encoder pulse = 1 inch. Then you only need to count the pulses from Leading Edge to Trailing Edge to get the number of inches of length of the product, without bothering to know what the actual encoder VALUE is at any point.
 
me said:
But wait until the PLCs.net 'day shift' arrives, as someone will post a MUCH better method than this... :D

Am I to believe that the method I described is normally how this is done?... :unsure:

It seems to me there should be a more elegant approach to this problem... :confused:

beerchug

-Eric
 
Eric,
Your solution looks good to me. It is short and easy to understand. Once it is inside the black box, who is to know the nasty details? You only have to write it once, and it runs a million times. Besides, if I can understand it, that makes it elegant to me!
 
I'm back, duty called. Thank you for the replies. The encoder can be set up no to roll over more than once per log.

Peter I'm listening.
 
I may be off base here because I know nothing about the application, (you havent said much about the project) Depending on your application there may be some pit falls.

Depending on the speed of your application (machine), and the scan rate of the PLC. Stopping to do math to compensate for a rollover in the middle of a product may result in some slight measurement errors.

If you have a continuas process that's running just one way, at some time you will reach the end of the PLCs ability to count rollovers. (the plc will not be able to count up indefinately), and you numbers will get so huge your scan time may be effected by the amount of code necessary to track it all. At some point you will have to reset the encoder, and rollover counters etc..

Personally I would reset the encoder at the compleation of each measurment, or cut-off cycle. If your doing a cut-off I would presume the conveyer stops for the cut-off cycle. The stop would the the time to reset the encoder. If your encoder will not count through the piece with out rolling over, you should re-evaluate your hardware. Compesating through programming for improper hardware is very diffucult to do, and usually ends up with lower than expected results.

If none of the above applies, a simple rollover counter should do it. Simply add another counter that will increment from a "0" value from your encoder.

We do a lot of counting and measuring etc.. via quad encoders. If you can post more detail I may be able to help you more.

Mike.
 
Now I wonder about the elevators...

It looks like you need a 32 bit encoder counter. It is easy enough to make a 32 bit counter if your PLC supports 32 bit numbers. The key is to calculate the difference in counts during the last scan.

Code:
nDifCounts = nHWCounter - nOldHWCounter     ;; THIS IS KEY!!!!!
nOldHWCounter = nHWCounter;

The only limitation is that the difference between counts CAN NOT exceed half of the total number of counts. In other words, one must make sure that a 16 bit counter never gets more than + or - 32767 counts in one scan. If you do then how do you know which direction you went? ( Actually you can tell with tricky programming )

Now add the SIGN EXTENDED 16 value to the 32 bit software counter. AB PLCs will automatically sign extend 16 bit values to 32 bit values IF the PLC supports 32 bit ints.

Code:
lSWcounter = lSWCounter + nDifCounts

HOWEVER, the SLC is crippled and doesn’t support 32 bit math easily. Therefore I will cheat and use floats. In this case the equation above becomes

Code:
fSWCounter = fSWCounter + nDifCounts

fSWCounter is now a floating point value that will accurately count to + or – 16,277,200 before losing precision. ( We covered this 2 or 3 weeks ago )

NOW, you can use the nDifCounts to create multiple floating point counters.

When you need to reset the counts because you are starting a new board you should just clear the floating point counter. NEVER reset the hardware counter as this may interfere with the multiple floating point counters. ALWAYS use the difference in hardware counts to increment software counters.

Actually, I would modify the equation above my doing some scaling too so I can deal in inches or meters. You may suffer

Code:
fSWCounter  =  fSWCounter + nDifCounts  ;  The PLC will convert the integer to a float

Only the floating point counts ( software counters ) should be reset or modified.

BTW, I use the first letter to indicate the type if the variable

n for 16 bit signed integer
l for 32 bit signed integer
f for floats

About the NEVER. I NEVER reset the counter because the hardware I use doesn’t require that I do. When an input comes in to start an event my hardware LATCHES the current count. That way I can tell where the input occurred relative to the previous hardware count and the current hardware count. The lack of a input latch on PLCs make them unsuitable for many registration tasks.
 

Similar Topics

I have a single turn encoder controlling my motion project. It is controlling the speed of an elastic web. I have a sensor looking at marks on...
Replies
4
Views
1,734
Could someone outline the process involved in handling a rollover count. I use a HSC to keep track of pieces entering a machine, Then I have...
Replies
2
Views
2,386
Any thoughts on how to handle rollover on an Encoder module. I have a module that only counts up to 32767 yet i need to accumulate much much more...
Replies
15
Views
5,846
Sorry in advance for the long post, but this requires a little back story. I work in a facility with a couple hundred VFDs Most are in a web...
Replies
14
Views
195
I have an application using an incremental encoder and then I convert it to degree (0-360) using calculation program. For a while, the calculation...
Replies
8
Views
263
Back
Top Bottom