Quadrature signal for push button - Page 1
Forum section: electronics / projects

author: psykok
author_rank: Frequent Contributor
timestamp: January 13, 2021, 01:37:44 pm
content: Hi,I looking to solve a small problem since a couple of days and I have not been able to archive what I need.Basically I need to replace an optical rotary coder with a set of two push buttons: button A for CW and B for CCW action.The coder spec:http://www.farnell.com/datasheets/2196116.pdfThe coder is generating a quadrature signal with a 90° phase shift between signal A and B.This phase shift is used to know in which direction you are turning the button.I tried do build something with a set of two D-Type flip flop but the issue is that you need to pulses to get one puls out with this setup.Also tried to generate a second signal with a 90° phase shift using a 4086 but it doesn't work because of the low frequency.So if any of you has an idea , I would be happy to test it.Alex

author: Ian.M
author_rank: Super Contributor
timestamp: January 13, 2021, 02:10:31 pm
content: Implementing a two bit up/down counter with a quadrature decoded output would be a whole mess of logic, and making it work on both transition edges for each button to avoid the problem of only getting one transition per button press would be even worse. Realistically, the best option is probably a small 8 or even 6 pin MCU, programmed to output your desired pulse sequence for each button.

author: Peabody
author_rank: Super Contributor
timestamp: January 13, 2021, 05:22:54 pm
content: Could you clarify how you want the pushbuttons to work? Would a press of A by itself be a CW step? If so, can't you just program things that way? Anyway, a truth table for the buttons would be helpful.You could duplicate the logic of the rotary encoder by requiring both switches to be pressed, or released, to trigger an action, with the direction being determined by which switch goes first.

author: psykok
author_rank: Frequent Contributor
timestamp: January 13, 2021, 06:24:42 pm
content: Hi,The constraint is that I cannot chnager the program of the main unit.Pressing the Button A will generate a CW step and CCW for the button B.Actually button A is for increase and B for decrease.Looks like the only way is to build a setup with a small uC

author: fourfathom
author_rank: Super Contributor
timestamp: January 13, 2021, 06:33:45 pm
content: Quadrature is essentially a 2-bit Gray-code up/down counter. You might look into Gray-code counters, but I can't seem to come up with a simple logic up/down counter design driven by two trigger inputs. A tiny PIC or similar would certainly be the physically simple solution.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: January 13, 2021, 06:39:22 pm
content: Don't forget you also have to add some form of debouncing for mechanical buttons.It can be done without a microcontroller, but these things are so cheap and flexible that even for a simple task as this they are very likely the best option.

author: Peabody
author_rank: Super Contributor
timestamp: January 13, 2021, 09:54:28 pm
content: I agree about using a microcontroller. If the existing software was written for an optical encoder, it's unlikely to include any debouncing, so any button substitute would have to be aggressively debounced. A little 8-pin microcontroller to provide perfect signals to the existing circuit seems to be the way to go.

author: jbeng
author_rank: Regular Contributor
timestamp: January 14, 2021, 12:55:44 pm
content: You could try something like the attached circuit if you don't want to write firmware for a micro...It is a quick & dirty series of Schmitt-trigger one-shots & the output pulse widths for the two channels are determined by the RC time constants of (R2,C1), (R4,C3), (R6,C4) and (R8,C6). The time delays between the pulses ("phase") are determined by (R3,C2) & (R7,C5), so I would make them 1/2 of the time constant of (R2,C1), etc.

author: CJay
author_rank: Super Contributor
timestamp: January 14, 2021, 01:01:18 pm
content: There are chips specially designed for this sort of function, bit niche but they are out there.There was a Hackaday article which mentioned them, I've a feeling it's the one covering a user's repair of an old sampler sometime mid 2020, seem to remember was discussion in the article comments and on the podcast, they cost a couple of quid per chip but *way* less than the effort required to develop code and test it.

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2021, 01:52:15 pm
content: I do not agree with the "logic mess".Decoding 2bit binary to 2bit gray code is what, like one or two XOR gates? Bidirectional counters are also nothing special. Just need to add simple button debounce, for the counter to always hop just one step further.

author: langwadt
author_rank: Super Contributor
timestamp: January 14, 2021, 02:05:33 pm
content: Quote from: Yansi on January 14, 2021, 01:52:15 pmyes all you need is an xor gate, but first you have to find a counter with seperate up and down clock ...

author: MarkF
author_rank: Super Contributor
timestamp: January 14, 2021, 02:16:28 pm
content: Quote from: langwadt on January 14, 2021, 02:05:33 pmSN74192 (decade) or SN74193 (binary).

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2021, 02:18:41 pm
content: Quote from: langwadt on January 14, 2021, 02:05:33 pm74*193 or whatever similar?

author: Ian.M
author_rank: Super Contributor
timestamp: January 14, 2021, 02:44:09 pm
content: ... and debounce its inputs, and also clock on both edges as the O.P. has stated they need one pulse out per input pulse, which is two transitions.

author: fourfathom
author_rank: Super Contributor
timestamp: January 14, 2021, 04:03:40 pm
content: ... and de-glitch the outputs, as putting an XOR binary-to-Gray encoder at the output of a binary counter is no guarantee of glitch-free quadrature signals. (*)I had forgotten about the 74193 with its separate UP and DOWN clocks. That definitely simplifies the problem. If only there were a native Gray counter or a left/right shift register with similar clocking...The 2-bit Gray encoder is just a single XOR:Gray.0 = Bin.0 XOR Bin.1Gray.1 = Bin.1(*) I suppose in practice if the logic is slow enough, the potential transition-time-difference output glitches of the counter will be too short to propagate. I still don't like it.

author: Zero999
author_rank: Super Contributor
timestamp: January 14, 2021, 04:33:16 pm
content: Quote from: jbeng on January 14, 2021, 12:55:44 pmGood idea. It can be simplified a bit.

author: Yansi
author_rank: Super Contributor
timestamp: January 14, 2021, 04:42:48 pm
content: .. then put a 7474 double D-flop on the output. You will then have all the time in between clock pulses to settle the intermediate glitch-states down.Still wouldn't count this as some complex logic mess.And also, depending on what does he need this for, the few glitches may or may not matter at all.

author: fourfathom
author_rank: Super Contributor
timestamp: January 14, 2021, 05:49:51 pm
content: Quote from: Yansi on January 14, 2021, 04:42:48 pmWhich clock pulses? Remember, we've got inputs from two pushbuttons, so we would need to OR these to clock the D-flops.I'm not saying this can't be made to work, and perhaps the "simple" solution will indeed do the job. At this point it's more of a fun puzzle to solve. But even the "simple" solution is starting to get a little hairy. If the OP has a way to code and program a tiny PIC (or similar) that's like a 25-cent 4-pin solution. (or 3-cents, using one of the cheap Chinese controllers).

author: wizard69
author_rank: Super Contributor
timestamp: January 16, 2021, 12:49:01 am
content: More detail might help. Your request is very unusual so I'm not sure an easy off the shelf solution exists. the problem is we can come up with ideas here that might work in one case as we understand it but not another.Consider this CW and CCW implies a motor driven piece off equipment. Depending upon what that equipment might be it could be better to go directly to the stepper controllers where you will find step and direction signals (hopefully). You never know the controller board you are connecting to might have inputs for CW and CCW.If you go the emulated rotary encoder route then you need to decide on a data rate for the sent pulse train. Also how many pulses to output per button push. Again depending upon what you are hooking up to those may be required to be variable.So without a lot more information I hope you see were this could go, basically from dead simple to a rather involved project.Quote from: psykok on January 13, 2021, 06:24:42 pm

author: ledtester
author_rank: Super Contributor
timestamp: January 16, 2021, 01:10:31 am
content: QuoteThis stackexchange question has a couple of circuits. Requires a clock, but perhaps you can generate a pulse signal when you push either of the buttons. Or have a free running clock which is enabled when either button is pressed -- this gives you a key repeat capability.https://electronics.stackexchange.com/questions/427765/generate-a-false-encoder-signal-cw-ccw-1-4-shiftedOne of the answers also mentions using a stepper motor sequencer chip such as an L297.Update:Another stackexchange discussion:https://electronics.stackexchange.com/questions/38046/simulate-encoder-using-buttons(Actually, I don't know why the first answer was marked accepted because it doesn't appear to handle both up and down counting.)