PDA

View Full Version : Interfacing 100 pulses per rev control knobs



Robin Hewitt
05-07-2023, 11:06 AM
Took a while to discover what the output was, now how do I read it? :calm:

It is a quadrature encoder fitted with a 100 step/rev detente that always parks you in the 00 condition.

So when you try to buzz out the output you always get zeros :nightmare:

As you turn it, you either get 01 11 10 00 or 10 11 01 00 depending on the direction.

So how would you read it? Preferably on an interrupt! :beer:

best

Robin

Robin Hewitt
06-07-2023, 06:10 PM
So I asked my elder brother who looks at me like I have gone senile and says, "You connect one line to the interrupt and read the other for direction".

:crushed:

Neale
07-07-2023, 07:10 AM
Not sure that it's quite that easy! If you look at the data patterns there is no simple link between either data line and direction. And if you only interrupt on one data line, you will miss half the transitions.

How about writing your interrupt code to read both data inputs and work out whether to increment or decrement an internal counter based on comparing current with previous state. Then set up "interrupt on change of state" on both input lines linked to same interrupt routine. The principle of quadrature inputs means that only one data line changes at a time so you should be able to handle one interrupt before the next arrives. How fast can a user turn the encoder knob?

I need to do something similar for a device that currently uses a pot delivering an analogue input to an ADC input on an Arduino but my main processing loop is so fast (compared with rate at which data changes could happen) that I am planning to just use polling of the data lines. I need to do this because the pot is a bit noisy and my soldering iron temperature keeps jumping about...

Robin Hewitt
08-07-2023, 01:50 AM
I didn't think it was that easy either, but it does explain why you get four transitions between each detente but only one counts :smug:

What does your pot control?

Robin

JohnHaine
08-07-2023, 06:59 AM
Which processor? Arduino? Is there a library you could use?

JohnHaine
08-07-2023, 07:53 AM
https://www.pjrc.com/teensy/td_libs_Encoder.html

https://www.arduino.cc/reference/en/libraries/encoder/

There is!

Neale
08-07-2023, 09:55 AM
That looks like the way to go. First rule of programming - find someone who has done it already and pinch their code! As the prophet says, pinch one man's work and it's plagiarism, pinch work from lots of people and it's research... Having those libraries available might get me going on my project again.

About 20 years back, I rescued a Weller soldering iron from a scrap bin at work. It had a sticky label saying "display broken" but it turned out to be more than just that. It was quite a fancy temperature-controlled iron with an analogue temperature control, not the more common Weller magnetic bit style with a fixed temperature based on the particular bit you fitted. However, on inspection I reckoned there was a fault on the PCB which was a ceramic board with principal components under beads of something like epoxy. Not much chance of a repair so I ripped it all out and built a new Arduino-based controller using the original pot as an analogue input for temperature setting and an op-amp-based level converter reading the resistance of the temperature sensor somewhere in the iron. There was a triac switching the element (24V) with zero-crossing switching to avoid any transients - although why this worries me is still a mystery as I can't imagine why you would be soldering any sensitive electronics while live. Twiddle the pot and the display shows desired temperature and after a few seconds it goes back to reading actual bit temperature. However, now the pot seems rather noisy and the desired temperature keeps jumping about so the idea is to replace it with a cheap rotary encoder. I have the encoder but still haven't got round to fitting it and updating the code.

Robin Hewitt
08-07-2023, 11:00 AM
Which processor? Arduino? Is there a library you could use?

I am using a pre-cambrian processor, hopefully without the explosion, the amazing Hitachi HD64180 :pride:

Robin

Voicecoil
08-07-2023, 01:26 PM
I seem to remember that there's a hardware solution using a couple of exclusive OR gates and a counter.....

JohnHaine
09-07-2023, 11:30 AM
I seem to remember that there's a hardware solution using a couple of exclusive OR gates and a counter.....

Yes there is, and maybe a D-type flip-flop too to sense direction. (XOR gates just double the pulse rate.) But you then still need to accumulate the pulses with an up/down counter and convert the counter to analogue to emulate the pot.

If there's a C compiler for the processor I guess it should be possible to modify the library code.

Neale
09-07-2023, 11:58 AM
In my case, I have spare input ports on my Arduino so no need to emulate a pot - I'm using the pot connected to the Arduino's ADC anyway to give an internal 0-255 to represent desired temperature - so using the processor means a SMOP(*) only needed.

For the Hitachi processor, though, not so sure. Had a quick look at data sheet last night (my, that thing's old!) and it looks as if it has the potential for a couple of interrupt lines but not sure if they would trigger on level change in either direction or just one. I would try to do as much as possible in the CPU and avoid external circuitry, though.

(*) Simple Matter Of Programming

Robin Hewitt
10-07-2023, 10:36 AM
I would try to do as much as possible in the CPU and avoid external circuitry, though.

Awww! But I like external circuitry :numbness:

Doddy
14-07-2023, 09:09 PM
Not sure that it's quite that easy! If you look at the data patterns there is no simple link between either data line and direction. And if you only interrupt on one data line, you will miss half the transitions..

You configure the interrupt on either leading or trailing edge - so the interrupt occurs on a transition on one phase - the other phase is steady state at this point. The interrupt is essentially the "clock" to increment or decrement the counter. The state of the second phase, either 0 or 1 determines whether to increment or decrement.