-2
\$\begingroup\$

I'm new at digital electronics. I want to find circuit unit that can convert 40 binary input to 6-bit binary number but I cannot find any circuit that can do it. I think must do using encoder, mux but I stacked. Can anyone help me?

\$\endgroup\$
2
  • \$\begingroup\$ Your question reasonably clear (except that we must assume what function from 40 bits to 6 bits you want, the answers assume priority encoding). But maybe you could tell why you want this, we might be able to suggest a better alternative. \$\endgroup\$ May 11, 2014 at 8:56
  • \$\begingroup\$ Do you need to count # of signals that are high?, is it a thermometer code? is it a one hot code with position meaning value? There many ways to interpret "40 binary inputs". \$\endgroup\$ May 11, 2014 at 15:10

4 Answers 4

0
\$\begingroup\$

Probably one of the cheapest and certainly one of the fastest options would be to use a CPLD such as this Xilinx one. The 64 pin package should just do, but I suggest the 100 pin package to leave some room. As good as 5ns response pin-to-pin, single chip solution and only $2.86 quantity 1. You can decide what output function (count the 1's, count the 0's, priority encoder, inverted-input priority encoder or whatever) at any time and reprogram it.

Unlike most FPGAs, these CPLD parts contain internal non-volatile flash memory, so you don't need an external program storage component.

Unfortunately, the learning curve is a bit steep for the require 7G bytes (or whatever) of (free) software, the HDL (Verilog or VHDL) or schematic method you'd use to describe the functionality, and you need a JTAG-USB programmer (cheap clones are available), but once you learn it, you'll probably find many other applications.

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ I wouldn't recommend any XL series parts for new designs. I just went through this at work, and the entire series is on the way to obsolescence. \$\endgroup\$
    – Matt Young
    May 11, 2014 at 14:48
  • \$\begingroup\$ @MattYoung What's the recommended replacement? I'm looking at the Coolrunner for a new project. \$\endgroup\$ May 11, 2014 at 14:54
  • \$\begingroup\$ You should be fine with the Coolrunner. My Xilinx rep said 2-3 years on the XL series, and 10+ on the Coolrunners. \$\endgroup\$
    – Matt Young
    May 11, 2014 at 18:07
1
\$\begingroup\$

A priority encoder would output a binary number representing the "most significant" active input - that is, if inputs 1,12,and 24 were active, a priority encoder would output 24.

There are 8-bit priority encoder ICs, such as the 74LS148 that can be interconnected to handle more than 8 bits.

\$\endgroup\$
1
\$\begingroup\$

I assume you want to activate one of 40 inputs, such as switches, and get out a binary number identifying which input is active, right?

Assuming that, the "simplest" way is to use priority encoders. The 74HC148 is probably what you want. The TI data sheet http://datasheet.octopart.com/SN74HC148D-Texas-Instruments-datasheet-51926.pdf shows how to extend from 8 bits to 16. You will need to further extend this to 40 bits. This will require 5 74HC148s for the first level of encoding, then 3 74HC30s to provide the 3 LSBs, and another 74HC148 to encode the upper 3 bits. This will, of course, require a total of 9 16-pin ICs.

\$\endgroup\$
1
\$\begingroup\$

Connect the 40 inputs to five 8 bit parallel-to-serial shift registers (8 inputs each). The shift registers can be in series. Read them into a simple microprocessor like the AVR in an Arduino. You can "Bit bang" them in with a digital output to clock the shift registers and a digital input to collect the bits as they come in. Then find the bits that are in the logic state you are looking for with some simple code. Clocking data in probably takes about 40 microseconds on an 8 MHz Arduino Uno for example ($11 or so I think on eBay). On an M series ARM Cortex, more like 4 microseconds. See 74HC165 or 74LV165.

Is the 6 bit output supposed to be an integer representation of a single active input line? You can count clocks till you find and input that is on (or none). I would probably save the data and then check the five bytes then calculate the value. If speed is important, a look-up table for each byte will be faster. I think there is a clever way to find the 6 bit value with logic and shifting that is optimal. Something like this for 8 bits at a time: x is the byte being tested. Numbers in hexadecimal.

if x=0 return (the value you want for none of the inputs asserted. Maybe 0?)
n=0
if x AND F0 == 0 then n=4; shift x left by 4 bits
if x AND 3F == 0 then n=n+2; shift x left by 2 bits
if x AND 7F == 0 then n=n+1
return n

Add 8 to n for the second byte, 16 for the third, 24 for the 4th, and 32 for the 5th.

For 32 bits at a time it goes like this.

FFFF0000 n=16 shift 16
FF000000 n=n+8 shift 8
F0000000 n=n+4 shift 4
3F000000 n=n+2 shift 2
7F000000 n=n+1

This counts from high order bit towards low order bit (called counting the leading zero's). Shifts are from low end to high and assumes 0's are shifted in as data is shifted out. It is just an idea as you can do various things with how you order the data as it is input. No guarantee I got that right, but a starting point.

Note that on an ARM, you can load 4 bytes at once and it has a barrel shifter that will do arbitrary shifts in one cycle. On true ARM (not Thumb) all instructions are conditional, so the if + add + shift is a single instruction. So, the whole thing is 9 or 10 instructions long. If you do not need a pure hardware solution, then try the 5 chips plus an Arduino and some code.

If you need help, an Arduino forum (or whatever processor you use) or IRC channel can be great. Just give the part number, like 75HC165 and a one line description and people will know what you are trying to do and be able to give more detailed suggestions to fit your implementation.

People with more experience might find a cheaper solution with a gate array type chip.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.