Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
When making the "state machine" you have to use 4x, otherwise it won't work!Thanks for the added info.
BobW's method also increases the count to 4X the claimed "pulses" per revolution. I figure it is like HP, you can always throttle back.
John
No problem, considering that I had called you Mr. Al in my last post.
I'm getting my encoder threads mixed up.
Also note that I made a minor edit to the above code.
Here's a little follow-up. My first Bourns encoder died an early death, and DigiKey replaced it. I had seen pictures of how they are made, but I decided to take a look anyway. Here are some pictures. One shows the parts right after popping the back off. There is a little pot accessible from the back, but covered with the label. Then there is the LED and detector and a very nice slotted disk. The rule is in millimeters. One photo shows some silicon. I have no idea what it does except act as the photodetector. Maybe it acts like a comparator to give sharp state changes.
Regards, John
View attachment 95519 View attachment 95520 View attachment 95521View attachment 95522
If you only need to use the encoder at its base resolution rather than 4X resolution, then you could just use a single interrupt line for one of the encoder outputs and a regular data line for the other encoder output. In that way, the encoder output that is connected to the interrupt input becomes CLOCK, and the other line becomes DATA. Upon interrupt, your ISR need only check the state of the data line, and increment a count variable if DATA=1 and decrement if DATA=0. If you need 2X or 4X resolution, then you could XOR the encoder outputs together. The XOR gate would give a state change when either encoder output changes state. If you can set the Arduino interrupt to trigger on both edges then you could still get 4X resolution. If the interrupt can only trigger on a single edge, then you'd be limited to 2X resolution.Hi,
I did that a few times myself
That's what the "Edit" button is for, when you make a typo you can correct it just as you did your code.
Back to the Encoders...
I got my 2 bit encoders working so well now that i probably will never need anything better. But i did run into one or two problems...
What if you wanted to use two encoders or use an interrupt for something else?
On the Arduino the lower end boards only have two pins for interrupts, and ONE encoders uses BOTH pins. How would we use a second encoder, or use one of the pins for something else.
For example, i wanted to try to sample a timing signal with one of the interrupts but if both are being used by the encoder, i am not sure how to do this yet.
Any ideas?
There are several manuf that offer incremental encoders for servo use that start at 100p/rev that do not have any detent.I wish the vendors would offer a non-mechanical detent.
John
There is a commercial model of a reed switch activated rotary switch but they do not last that long, when used on a daily basis in commercial machines, I have rebuild these for some years now and have tried different types of reed switch.
**broken link removed**
Max.
In any case, there should have been a comprehensive failure analysis done to determine what exactly is going wrong and what is causing it.