4-bit, 4 input (A,B,C,D) Magnitude Comparator Circuit

Thread Starter

SteveMorgan

Joined May 14, 2012
14
Is there a way to design a 4-bit, 4 input (A,B,C,D) Magnitude comparator without resorting to a Mircoprocessor/controller? I note that there are 2 input (A,B) magnitude comparators available such as the DM74LS85, but cannot see a way to design a 4 input version. Any suggestions?
Reason for question is that I'm trying to design a position indicator for a 4 lane slot car setup, so that car coming first with most laps shows a Position 1 indicator for its lane, car with the next most laps gets a position 2 indicator and so on.
Thanks in advance for your input.
 

Thread Starter

SteveMorgan

Joined May 14, 2012
14
Sorry for the delay. That is helpful, thanks. Are you able to offer any advise on how I could extend these so that I can compare 4 separate inputs? Is there any way to daisy chain these at all? I can't see how and cannot find anything on the internet. If not, are you able to offer any suggestions as to the direction I should be heading to achieve my goal?
 

WBahn

Joined Mar 31, 2012
30,058
Why don't you want to use a microcontroller? That would sure seem to be the much simpler solution.

For your intended system, how do you handle ties, for instance, if the number of laps completed by the cars in lanes 1 through 4, respectively, are {5, 7, 5, 4}, what position should each lane show?
 

Papabravo

Joined Feb 24, 2006
21,225
I'm pretty sure you are mistaken. The 74LS85 is a 4-bit Magnitude Comparator. I offer the following datasheet for the 74HC85 and the 74HCT85 which you may still find on distributors shelves. The HCT version has TTL threshold characteristics in case that is important to you.

https://assets.nexperia.com/documents/data-sheet/74HC_HCT85.pdf
Look carefully at page 11 of the datasheet for how to cascade the part to additional bits of two words.
 

Thread Starter

SteveMorgan

Joined May 14, 2012
14
Why don't you want to use a microcontroller? That would sure seem to be the much simpler solution.

For your intended system, how do you handle ties, for instance, if the number of laps completed by the cars in lanes 1 through 4, respectively, are {5, 7, 5, 4}, what position should each lane show?
Yeah I may be forced down the microcontroller route but I was trying to avoid it if i could find a reasonably uncomplicated solution, something that seems relatively simple for the human brain to process seems to take a bit more effort in external logic!
In answer to your question, the car that gets to the line first wold be the one deemed next position between the 2 that have the same laps. Actually thinking about it a bit more, really only need to process the first 3, the 4th could then automatically be deemed last.
 

Thread Starter

SteveMorgan

Joined May 14, 2012
14
Thanks for that. I wasn't sure if that would work since I intended processing 4 separate 4 bit words? As mentioned above though, I probably only need to calculate 3, and the last one would be last position by default. So you think your diagram would work processing 3 separate 4 bit words as opposed to a single 12 bit word as the diagram seems to imply?
 

Thread Starter

SteveMorgan

Joined May 14, 2012
14
64K x 8 bit rom? 4 * 4bits in the address lines, 2 * 4 bits out as the answer?

What should it output if 2 or more of the inputs are the same?
So that sounds like its going down the microcontroller route which is more complicated than I wanted to get if I could resolve using a relatively simple logic circuit. I appreciate though that this may in fact not be possible, I'm just putting it out there in case there is a relatively simple solution to my quest.
In answer to your question though, even though some cars may have the same laps, one would arrive before the other, so incrementing its laps before the other, and so would be deemed next position,
 

michael8

Joined Jan 11, 2015
414
even though some cars may have the same laps, one would arrive before the other, so incrementing
its laps before the other, and so would be deemed next position,


Ah! That implies to me that the 4 bits as a value from the lap counters isn't the full information, it's also necessary
to record the time (which is first etc) when the lap counters increment.

I'd be tempted to back up the problem and just use the lap sensor outputs (1 bit per track) rather than
the lap counter outputs.

Is this a homework problem?

Oh, a search show lap/timing system really are a thing:
https://www.mylaps.com/systems/rc-4-timing-system/
https://www.rccaraction.com/dirtchamp-design-portable-lap-timing-system/

I suspect that there isn't a really simple "just logic" solution, although if I had to have such a
solution I'd look at how incremental encoders are decoded:

https://en.wikipedia.org/wiki/Incremental_encoder_interface#Quadrature_decoder

It's not an exact analogy as you have 4 lap sensor inputs and the cars are not restricted to be just before or
after each other -- they can lap each other which has to be remembered somehow.
 

Thread Starter

SteveMorgan

Joined May 14, 2012
14
even though some cars may have the same laps, one would arrive before the other, so incrementing
its laps before the other, and so would be deemed next position,


Ah! That implies to me that the 4 bits as a value from the lap counters isn't the full information, it's also necessary
to record the time (which is first etc) when the lap counters increment.

I'd be tempted to back up the problem and just use the lap sensor outputs (1 bit per track) rather than
the lap counter outputs.

Is this a homework problem?

Oh, a search show lap/timing system really are a thing:
https://www.mylaps.com/systems/rc-4-timing-system/
https://www.rccaraction.com/dirtchamp-design-portable-lap-timing-system/

I suspect that there isn't a really simple "just logic" solution, although if I had to have such a
solution I'd look at how incremental encoders are decoded:

https://en.wikipedia.org/wiki/Incremental_encoder_interface#Quadrature_decoder

It's not an exact analogy as you have 4 lap sensor inputs and the cars are not restricted to be just before or
after each other -- they can lap each other which has to be remembered somehow.
Thanks for the helpful information. My situation is slightly different though, and it is for a home setup, not commercial, My setup is for slotcars, so there is one position on the track where these are sensed as they go through each lap, and it is at this point where they are measured as to laptimes and, hopefully, their current position number on the track. So wouldn't need telemetry on where they are on the track at any point in time, only when they pass the lap mark/point. It is beginning to look like this request may not be as simple as it appears on the surface!
 

WBahn

Joined Mar 31, 2012
30,058
64K x 8 bit rom? 4 * 4bits in the address lines, 2 * 4 bits out as the answer?

What should it output if 2 or more of the inputs are the same?
Yeah I may be forced down the microcontroller route but I was trying to avoid it if i could find a reasonably uncomplicated solution, something that seems relatively simple for the human brain to process seems to take a bit more effort in external logic!
In answer to your question, the car that gets to the line first wold be the one deemed next position between the 2 that have the same laps. Actually thinking about it a bit more, really only need to process the first 3, the 4th could then automatically be deemed last.
IF your logic ONLY dependent on the current values of the four lane counters, then the simplest solution would be to use a ROM and create a look-up table. You would have to be able to program the ROM, though, and so there's some hardware you would need to obtain. It wouldn't cost too much, but perhaps more than you would like to spend if this is the only time you would get to use it.

However, now you have added additional inputs. If you just tell me that Car 1 has 5 laps and Car 3 has 5 laps, how am I supposed to know that Car 3 got to that point (i.e., went from 4 laps to 5 laps) before Car 1 did? So your system needs to monitor not only the value of those four four-bit values, but also when they change. This is moving things pretty firmly into the microcontroller realm.

I have never worked with things like the Arduino or the Raspberry Pi, but this should be something that is right up their alley and should be pretty simple to do with them.
 

WBahn

Joined Mar 31, 2012
30,058
Thanks for the helpful information. My situation is slightly different though, and it is for a home setup, not commercial, My setup is for slotcars, so there is one position on the track where these are sensed as they go through each lap, and it is at this point where they are measured as to laptimes and, hopefully, their current position number on the track. So wouldn't need telemetry on where they are on the track at any point in time, only when they pass the lap mark/point. It is beginning to look like this request may not be as simple as it appears on the surface!
Do you have access to the signal in each slot that is used to increment the lap counter that you already have?

If so, that gives you four signals instead of sixteen. Then you need eight outputs (two bits per lane) to indicate the position.

The logic for the program in a microcontroller is pretty simple and, if you decide to go that route, we can help you with.
 

Thread Starter

SteveMorgan

Joined May 14, 2012
14
Do you have access to the signal in each slot that is used to increment the lap counter that you already have?

If so, that gives you four signals instead of sixteen. Then you need eight outputs (two bits per lane) to indicate the position.

The logic for the program in a microcontroller is pretty simple and, if you decide to go that route, we can help you with.
The slot car triggers an opto detector that provides a pulse for the counter, no problem accessing that. The only reason I assumed 4 bits would be required for each lane was for the BCD representation of the laps so I could use the magnitude comparators for each lane to establish who was coming first, second, etc- if thats the best approach to the issue, which I'm now getting the impression that its not. Thanks for the offer of the Microcontroller assistance. What processor would you recommend in this instance?
 

WBahn

Joined Mar 31, 2012
30,058
The slot car triggers an opto detector that provides a pulse for the counter, no problem accessing that. The only reason I assumed 4 bits would be required for each lane was for the BCD representation of the laps so I could use the magnitude comparators for each lane to establish who was coming first, second, etc- if thats the best approach to the issue, which I'm now getting the impression that its not. Thanks for the offer of the Microcontroller assistance. What processor would you recommend in this instance?
By bringing in just the four trigger signals, your program can keep track of the laps for each car with internal variables. The only thing that would need to be considered is the possibility of your logic either missing a pulse or double counting it. But that can be handled with a bit of conditioning logic.

As for which MCU to use, I'm guessing that something like an Arduino is a good choice. Like I noted previously, I have never previously used one but there are plenty of people here that have or similar options. I can certainly help with the generic logic design of the program -- it's pretty simple -- and the actual implementation should be pretty straightforward, but any help you need on that would need to come from one of the other members.
 

Thread Starter

SteveMorgan

Joined May 14, 2012
14
By bringing in just the four trigger signals, your program can keep track of the laps for each car with internal variables. The only thing that would need to be considered is the possibility of your logic either missing a pulse or double counting it. But that can be handled with a bit of conditioning logic.

As for which MCU to use, I'm guessing that something like an Arduino is a good choice. Like I noted previously, I have never previously used one but there are plenty of people here that have or similar options. I can certainly help with the generic logic design of the program -- it's pretty simple -- and the actual implementation should be pretty straightforward, but any help you need on that would need to come from one of the other members.
Thanks WBhan
 
Top