Author Topic: Find highest value of 4 inputs without microcontroller?  (Read 6786 times)

0 Members and 1 Guest are viewing this topic.

Offline petersanchTopic starter

  • Regular Contributor
  • *
  • Posts: 62
  • Country: 00
Find highest value of 4 inputs without microcontroller?
« on: November 15, 2018, 05:31:51 am »
Hi All,
I have 4 analog inputs and wish to find which one out of the 4 has the highest voltage. A TTL output is preferred. Feels as if there should be an IC that does this. Are there clever ways of doing this without a micro or A2D?

Cheers!
« Last Edit: November 15, 2018, 05:35:51 am by petersanch »
 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 711
  • Country: us
Re: Find highest value of 4 inputs without microcontroller?
« Reply #1 on: November 15, 2018, 06:10:21 am »
Six comparators followed by some digital logic?

(One comparator for every signal pair:  AB, AC, AD, BC, BD, CD.  Then work out the boolean logic for your desired output, whether 1-of-4 or two-bit binary encoding.)
 

Online helius

  • Super Contributor
  • ***
  • Posts: 3639
  • Country: us
Re: Find highest value of 4 inputs without microcontroller?
« Reply #2 on: November 15, 2018, 06:13:27 am »
So with 4 inputs, there are 6 relevant comparisons: A vs B, C vs D, A vs C, B vs D, A vs D, B vs C.
out(A) = (A>B)∧(A>D)∧(A>C)
out(B) = (A<B)∧(B>D)∧(B>C)
out(C) = (C>D)∧(B<C)∧(A<C)
out(D) = (C<D)∧(B<D)∧(A<D)
You can factor the comparisons into sums of terms, too.

How about two LM339 quad comparators, with the outputs ran into a 74HCT132 quad 4-input NAND?
 

Offline unitedatoms

  • Frequent Contributor
  • **
  • !
  • Posts: 324
  • Country: us
Re: Find highest value of 4 inputs without microcontroller?
« Reply #3 on: November 15, 2018, 10:45:10 pm »
For positive only voltages, connect each input to anodes of leds of 4 optocouplers. Tie all led cathodes to single grounded resistor load. The ttl outputs of optos will provide 4 bit code. Where possible most expected values are 0001, 0010,  0100 and 1000. Other values must be decided upon too, use code into any combinatorial manner, for example 2 x 16 inputs demuxes with hardwired inputs if 2 bit output is required.
Interested in all design related projects no matter how simple, or complicated, slow going or fast, failures or successes
 

Offline bson

  • Supporter
  • ****
  • Posts: 2269
  • Country: us
Re: Find highest value of 4 inputs without microcontroller?
« Reply #4 on: November 16, 2018, 02:10:13 am »
I second the optocoupler idea.  The LEDs may differ ever so slightly in forward voltage, so that will be your main source of inaccuracy.



Ra//Rb biases the LEDs, and if you want to bias at -Vf = -2.5V then Vss < GND - Vf < -2.5V.   If you don't care about biasing just remove Ra and replace Vss with ground.

 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9008
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Find highest value of 4 inputs without microcontroller?
« Reply #5 on: November 16, 2018, 02:43:44 am »
Instead of LEDs, use NPN transistors to make a 4 input version of a long tailed pair.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline JVR

  • Regular Contributor
  • *
  • Posts: 201
  • Country: be
Re: Find highest value of 4 inputs without microcontroller?
« Reply #6 on: November 16, 2018, 10:27:49 am »
I second the optocoupler idea.  The LEDs may differ ever so slightly in forward voltage, so that will be your main source of inaccuracy.



Ra//Rb biases the LEDs, and if you want to bias at -Vf = -2.5V then Vss < GND - Vf < -2.5V.   If you don't care about biasing just remove Ra and replace Vss with ground.

I might be missing this, due to my mind being filled with an extraordinary lust for beer, but how is this better than using comparators? This induces large offsets, and even more uncertainty due to the low gain of an optocoupler.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2269
  • Country: us
Re: Find highest value of 4 inputs without microcontroller?
« Reply #7 on: November 17, 2018, 01:45:34 am »
I might be missing this, due to my mind being filled with an extraordinary lust for beer, but how is this better than using comparators?
Post an actual circuit and we'll see.
 

Offline german77

  • Regular Contributor
  • *
  • Posts: 72
  • Country: mx
Re: Find highest value of 4 inputs without microcontroller?
« Reply #8 on: November 17, 2018, 02:45:53 am »
I will go with comparators any time. But I like doing things the hard way  ;D. This idea is similar to the optocoupler idea but with transistors. From the emulation I can expect a minimum of 0.15V difference to say for sure which one is the maximum.
 

Offline fsr

  • Regular Contributor
  • *
  • Posts: 169
  • Country: ar
Re: Find highest value of 4 inputs without microcontroller?
« Reply #9 on: November 17, 2018, 03:32:10 am »
The optocoupler idea is quite clever!
But without a uC, how will you read the result, and how will you actually select the analog line, etc?
From a cost perspective there could be some cheap, low pin-count uCs with several ADCs out there.
But it all depends on how will you use the result and the signals.
 

Offline german77

  • Regular Contributor
  • *
  • Posts: 72
  • Country: mx
Re: Find highest value of 4 inputs without microcontroller?
« Reply #10 on: November 17, 2018, 04:02:33 am »
The optocoupler idea is quite clever!
But without a uC, how will you read the result, and how will you actually select the analog line, etc?
From a cost perspective there could be some cheap, low pin-count uCs with several ADCs out there.
But it all depends on how will you use the result and the signals.
The optocoupler may sound clever but it's actually horrible considering that you need 1.2V or something like that, of difference to know for sure which one is the highest. I'm sure he does use a uC to read the result but he doesn't want to waste ADC pins or resources to do this task.
 

Offline Wolfgang

  • Super Contributor
  • ***
  • Posts: 1775
  • Country: de
  • Its great if it finally works !
    • Electronic Projects for Fun
Re: Find highest value of 4 inputs without microcontroller?
« Reply #11 on: November 17, 2018, 09:40:12 am »
I will go with comparators any time. But I like doing things the hard way  ;D. This idea is similar to the optocoupler idea but with transistors. From the emulation I can expect a minimum of 0.15V difference to say for sure which one is the maximum.

You could make this idea more accurate by using transistor array ICs, one for NPN and one for PNP. Within an array, Vbe does not differ much.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14174
  • Country: de
Re: Find highest value of 4 inputs without microcontroller?
« Reply #12 on: November 17, 2018, 10:06:00 am »
For the transistor circuit it would help a lot if the emitter side resistor to the negative supply would be replaced with a constant current source of some type. This would make the level where the circuit starts to see a difference more independent of the absolute voltage level.

Adjusting the current to the right level (around 1 mA for the shown circuit) can also reduce the turn over range, from a case where no output might be marked to the case where 2 about equal outputs would be marked.
 

Online DC1MC

  • Super Contributor
  • ***
  • Posts: 1882
  • Country: de
Re: Find highest value of 4 inputs without microcontroller?
« Reply #13 on: November 17, 2018, 10:43:52 am »
You can draw some inspiration from the patent here:
https://patents.google.com/patent/US6191623B1/en


 DC1MC
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Find highest value of 4 inputs without microcontroller?
« Reply #14 on: November 17, 2018, 11:11:26 am »
The requirement sounds quite simple at first, but there is more to it than meets the eye

The four LED circuit is so clever. :)

It does have a lack of precision though and there is a danger of exceeding the LED reverse voltage. Of course, that depends on the voltage of the input signals.

Attached is a precision version of the four LED circuit. In addition to the the highest voltage LED illuminating while the others are off, the three off outputs will be at logic 0. But the highest output will be at whatever the highest voltage input is.

I haven't worked out a simple way to produce a solid logic 1  :-\
« Last Edit: November 17, 2018, 11:15:13 am by spec »
 
The following users thanked this post: schmitt trigger

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Find highest value of 4 inputs without microcontroller?
« Reply #15 on: November 18, 2018, 12:04:02 am »
Below is the best I can do at the moment.

All channel outputs are at 0V, except for the highest voltage channel output which will be at 5V, so suitable for driving all 5V logic families.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21658
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Find highest value of 4 inputs without microcontroller?
« Reply #16 on: November 18, 2018, 12:42:17 am »
Should be able to do it in slightly fewer, due to this being a sorting problem (of sorts) and sorting problems being guaranteed N log N worst case complexity.

Not that this helps much at small N, and indeed, if N = 4, then 4 lg(4) = 4*2 = 8, so the 6-comparator solution given earlier can't be too far from there.

I suspect it's possible to save some comparators, in exchange for more logic (e.g., doing pairwise comparisons on ordered sets; using analog muxes to compare pairs in sequence, latch the state and resolve the sampled result; etc.), but this probably won't save many transistors or much space.

The analog method is to use a max(a, b, c, d) circuit and monitor the current through each diode; only one will be active at a time (outside of a transition range, which we can make arbitrarily narrow with op-amps).

To improve on spec's proposal: instead of a pull-down resistor, first just use a current sink instead of a pull-down resistor.  This keeps the offset, transition band, and speed more consistent over the operating range, and lets us work with it more easily, at least for now.

Either:
- In place of the diodes, use transistors to detect when a channel is active.  That is, the pull-down current is communicated through the active transistor's collector, to a load resistor, which probably needs a level shift to get back to a standard logic level (say if the A through D inputs are 0-5V, and the output is 5V CMOS logic level).  So we'd need four NPNs and four PNPs, plus resistors (the PNPs can be the "prebiased" or "digital" kind, saving on components).
- When a channel is "losing", its op-amp is saturated to -V.  In an active rectifier circuit, we often use a diode from -in to out, to reduce integrator windup (i.e., holding the output at (-in) - Vf rather than allowing it to saturate to the full -V, saving slewing time when that signal turns back on).  We can capture this with crude comparators (probably just transistors or diodes), and resolve state with logic if necessary. (This is probably not as nice of a method, so I haven't fleshed it out as well.)

Similar logic applies to this circuit as well, though being just a two-channel min(a, b) implementation for a particular situation (i.e., wrapping around an error amplifier). https://www.seventransistorlabs.com/Images/Limiter2.png By adding a logic output to the diff pair, a comparison output is available; this could be scaled to any number of limit inputs, if such were needed.  This works very nicely for a power supply where you want V/I limiting and indication.  The 4-variable version works just the same, but with more process variables.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14445
  • Country: fr
Re: Find highest value of 4 inputs without microcontroller?
« Reply #17 on: November 18, 2018, 12:48:11 am »
Below is the best I can do at the moment.

That's clever.  :-+

You can probably set your reference voltage a bit higher than 50mV to get more margin, as the highest voltage detection at the opamp's outputs should be a diode drop higher than the input voltage, thus significantly higher than 50mV even if input is very close to 0V, at least for 1N4148 diodes. Using rail-to-rail opamps will also improve the operating range, as well as using schottky diodes.

 

Offline unitedatoms

  • Frequent Contributor
  • **
  • !
  • Posts: 324
  • Country: us
Re: Find highest value of 4 inputs without microcontroller?
« Reply #18 on: November 18, 2018, 01:37:30 am »
@Spec: great!

I'd rather rewire input opamps to be followers and leave it for diodes to decide on outcome of voltage drop across individual diodes. In theory only one diode will win and will have highest voltage drop across itself.

After that works, the output 4 opamps/comparators should only compare cathode vs anode. So the divider can be removed and negative inputs of comparators should be connected only to single resistor.
Interested in all design related projects no matter how simple, or complicated, slow going or fast, failures or successes
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Find highest value of 4 inputs without microcontroller?
« Reply #19 on: November 18, 2018, 05:45:54 am »
Below is the best I can do at the moment.

That's clever.  :-+

You can probably set your reference voltage a bit higher than 50mV to get more margin, as the highest voltage detection at the opamp's outputs should be a diode drop higher than the input voltage, thus significantly higher than 50mV even if input is very close to 0V, at least for 1N4148 diodes. Using rail-to-rail opamps will also improve the operating range, as well as using schottky diodes.

Thank you SW :)

I like your suggestions to enhance the design- well though out.

Of course, a bit of decoupling would help too.
« Last Edit: November 18, 2018, 05:47:43 am by spec »
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Find highest value of 4 inputs without microcontroller?
« Reply #20 on: November 18, 2018, 05:52:57 am »
@Spec: great!

I'd rather rewire input opamps to be followers and leave it for diodes to decide on outcome of voltage drop across individual diodes. In theory only one diode will win and will have highest voltage drop across itself.

After that works, the output 4 opamps/comparators should only compare cathode vs anode. So the divider can be removed and negative inputs of comparators should be connected only to single resistor.

Thank you too uA  :)

Hmm, some interesting thoughts about the architecture. Could you perhaps post an outline schematic of your approach to illustrate.
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Find highest value of 4 inputs without microcontroller?
« Reply #21 on: November 18, 2018, 05:59:03 am »
Should be able to do it in slightly fewer, due to this being a sorting problem (of sorts) and sorting problems being guaranteed N log N worst case complexity.

Not that this helps much at small N, and indeed, if N = 4, then 4 lg(4) = 4*2 = 8, so the 6-comparator solution given earlier can't be too far from there.

I suspect it's possible to save some comparators, in exchange for more logic (e.g., doing pairwise comparisons on ordered sets; using analog muxes to compare pairs in sequence, latch the state and resolve the sampled result; etc.), but this probably won't save many transistors or much space.

The analog method is to use a max(a, b, c, d) circuit and monitor the current through each diode; only one will be active at a time (outside of a transition range, which we can make arbitrarily narrow with op-amps).

To improve on spec's proposal: instead of a pull-down resistor, first just use a current sink instead of a pull-down resistor.  This keeps the offset, transition band, and speed more consistent over the operating range, and lets us work with it more easily, at least for now.

Either:
- In place of the diodes, use transistors to detect when a channel is active.  That is, the pull-down current is communicated through the active transistor's collector, to a load resistor, which probably needs a level shift to get back to a standard logic level (say if the A through D inputs are 0-5V, and the output is 5V CMOS logic level).  So we'd need four NPNs and four PNPs, plus resistors (the PNPs can be the "prebiased" or "digital" kind, saving on components).
- When a channel is "losing", its op-amp is saturated to -V.  In an active rectifier circuit, we often use a diode from -in to out, to reduce integrator windup (i.e., holding the output at (-in) - Vf rather than allowing it to saturate to the full -V, saving slewing time when that signal turns back on).  We can capture this with crude comparators (probably just transistors or diodes), and resolve state with logic if necessary. (This is probably not as nice of a method, so I haven't fleshed it out as well.)

Similar logic applies to this circuit as well, though being just a two-channel min(a, b) implementation for a particular situation (i.e., wrapping around an error amplifier). https://www.seventransistorlabs.com/Images/Limiter2.png By adding a logic output to the diff pair, a comparison output is available; this could be scaled to any number of limit inputs, if such were needed.  This works very nicely for a power supply where you want V/I limiting and indication.  The 4-variable version works just the same, but with more process variables.

Tim

A schematic can often replace a thousand words. ::)
 

Online LaserSteve

  • Super Contributor
  • ***
  • Posts: 1281
  • Country: us
Re: Find highest value of 4 inputs without microcontroller?
« Reply #22 on: November 18, 2018, 07:16:15 am »
My friend Jim modeled this attached circuit for me right before he passed on.  My application was RGB to luminance  for ILDA standard signals [0 to 5V] in laser show projectors with only green lasers. Enjoy..
« Last Edit: November 18, 2018, 07:35:15 am by LaserSteve »
"What the devil kind of Engineer are thou, that canst not slay a hedgehog with your naked arse?"
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21658
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Find highest value of 4 inputs without microcontroller?
« Reply #23 on: November 18, 2018, 04:21:05 pm »
A schematic can often replace a thousand words. ::)

Takes as long to write. And doesn't contain any design info!

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Find highest value of 4 inputs without microcontroller?
« Reply #24 on: November 18, 2018, 04:53:22 pm »
A schematic can often replace a thousand words. ::)

Takes as long to write. And doesn't contain any design info!

Tim

Ah I see your clever scheme- use transistors as diodes and difference amplifiers.

The only thing is that  the A#15 circuit uses:  2 x LM234 , 4 x diodes, 3 x resistor

While the A#23 circuit uses: 1 xLM324, 9 transistors, 11 resistors

Don't you use a circuit capture package?

If not, you do know that there are some pretty good free versions available on the web.

I'm an EAGLE fanboy ::)
« Last Edit: November 18, 2018, 04:55:48 pm by spec »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf