How to create encoder from two Optical sensors?

I want to make an encoder from two VCNT2020 sensors: https://www.digikey.com/product-detail/en/vishay-semiconductor-opto-division/VCNT2020/VCNT2020CT-ND/7560298

I have a sprocket with two offset holes. Each lane of holes has one of these sensors. I know how to count it up using one sensor, but not sure how to merge both filtered waveforms into one? I have output A and output B for both sensors together.

How can I go about using something like ATTINY85-20SUR (feel free to suggest a better/cheaper IC) to combine both readings and add them up on a counter and then send that to an Arduino MEGA 2560 as a single square waveform?

It seems like you have a quadrature encoder.

A good library for encoders is the Encoder library.

The tiny85 could count pulses and sense direction of rotation. Why do you want to combine the pulses?

A Mega has plenty of pins and several are hardware interrupts (use to read encoder if pulses are fast), so why offload the work to a tiny85?

shai:
I have a sprocket with two offset holes. Each lane of holes has one of these sensors. I know how to count it up using one sensor, but not sure how to merge both filtered waveforms into one? I have output A and output B for both sensors together.

Your idea may be correct, but the implementation is wrong. The two rows seem to have different numbers of holes, from which no single speed signal can be determined. Correct implementation senses the same lane with two sensors, so that both signals overlap to some degree, but raise and fall independently. Then with a movement in one direction channel A raises before channel B signal, and reversed for reversed direction..

How can I go about using something like ATTINY85-20SUR (feel free to suggest a better/cheaper IC) to combine both readings and add them up on a counter and then send that to an Arduino MEGA 2560 as a single square waveform?

Either you stay with one signal and forget about rotation direction, or you use both channels for the determination of both speed and direction.

Speed

DrDiettrich:
Your idea may be correct, but the implementation is wrong. The two rows seem to have different numbers of holes, from which no single speed signal can be determined. Correct implementation senses the same lane with two sensors, so that both signals overlap to some degree, but raise and fall independently. Then with a movement in one direction channel A raises before channel B signal, and reversed for reversed direction..Either you stay with one signal and forget about rotation direction, or you use both channels for the determination of both speed and direction.

Speed/direction at the moment isn't important. Sorry I guess I should've specified that! Main goal here so far is to count how many holes have passed over the sensors. Reason for "two lanes" of holes is to make the angle of rotation smaller. This is a sprocket for an SMT feeder, so I am using the sensors to count how far the tape of components has moved.

The count of the holes in the outer lane seems to match the sprockets. Then you sense the holes in that lane for progress detection.

shai:
Reason for "two lanes" of holes is to make the angle of rotation smaller.

If they have a different number of holes then that - as explained above - will not work.

The solution is to use one set of holes, and two or more sensors mounted in a "quadrature" offset. Two sensors can then detect half the movement, three sensors a third and so on.

Paul__B:
If they have a different number of holes then that - as explained above - will not work.

The solution is to use one set of holes, and two or more sensors mounted in a "quadrature" offset. Two sensors can then detect half the movement, three sensors a third and so on.

Why wouldn't it work? x holes = pitch on feeder tape. Sure I can also put them on one lane of holes. In any case, the original topic was to ask for help on how to read two waveforms at same time and count them up so that when sensors reach x count, motor stops sprocket. Any tips on an IC that can merge two optical sensor inputs and spit out a single square waveform?

OR gate.

jremington:
OR gate.

Sorry, I don't understand? Can you please elaborate?

Google "or gate" for enlightenment.

But you don't need any circuit to merge two digital inputs. The Arduino can do that.

jremington:
Google "or gate" for enlightenment.

But you don't need any circuit to merge two digital inputs. The Arduino can do that.

Yes Arduino can do that, however I would have half as less pins then if I connect Arduino pins directly to the sensors. That's why I wanted a middle IC or something to merge it or tally it up.

It will take more than one pin to read an IC that "tallies it up". An OR gate will merge two data streams.

What is so hard to understand in that the rigth solution counts the pulses of one signal only?

Based on that picture, the inner holes are centered on the outer holes so by combining them your getting better resolution if the optical sensors are aligned to each other.

Very likely trying to combine the outputs into “1” output would simply yield a constant HIGH.

A properly setup monostable multivibrator could be used to only generate a quick pulse per”hole” so by having one on each sensor you would be able to count pulses on one pin.

You could also use a atty chip, when each input goes high, send a single pulse.

Nowadays it’s likely cheaper to use the atty chips for a single project.

The second lane does not really provide higher resolution. The same effect, of a higher pulse rate, can be achieved by another sensor on the first lane, or by counting both edges of one signal.

Two square waves can be combined into one by an XOR gate (7486) or function.

DrDiettrich:
The second lane does not really provide higher resolution.

The “second lane” literally doubles the counts per tooth.
Outer lane is 2 counts per tooth, the inner lane is additional two counts per tooth.

Very effective method to achieve 4 counts per tooth without having to use very small holes in one full lane and likely helps maintain structural integrity in the spool.

Sorry, the exactly same effect can be achieved by another sensor on the first lane, with a (usually inevitable) phase shift. Improved resolution with every further added sensor. A second lane only increases the chance for breaks, errors, jitter etc.

DrDiettrich:
The second lane does not really provide higher resolution.

It adds a set of holes midway between the holes in the outer ring. The inner ring holes are closer together, just as many.

Of course if you count ON and OFF of the outer ring sensor, you get just as many states.
You could put more sensors around either ring all offset by a fraction of hole to hole centers; 1/2, 1/4, 1/8, etc, but I think you would need smaller holes to get more than twice the resolution. That is what angling the line of the sensors to a radial of the wheel is doing, going for the 1/4 offset.

If the wheel had radial slits, a line of sensors at slight angle to radial could do the job of a vernier.

Smaller holes are not required, squares were better for sharp signal edges, like have the typical stroboscope-like dials for commercial encoders.

But everybody can create its own encoder pattern...

DrDiettrich:
Sorry, the exactly same effect can be achieved by another sensor on the first lane, with a (usually inevitable) phase shift. Improved resolution with every further added sensor. A second lane only increases the chance for breaks, errors, jitter etc.

Which is of course, what I explained in #5. :roll_eyes: