7 Feb 2013

Digital Systems Part 3 - Combinational Logic

In the first two parts of this installment, we learned about the different logic gates and how some of these are implemented with transistors. It is now the time to go a bit further i.e. working with these gates to form complex circuits. Electronics circuits made with logic gates are called digital circuits. There are two main type of digital circuits : combinational and sequential.

Combinational circuits

These circuits are easier to understand than sequential circuits. Combinational logic means that the outputs of the circuit are going to be the same for a given set of input values. The sequence of how the inputs have been setted has no effect on the circuit outputs. There are multiple different type of combinational circuits :

  • encoder/decoders
  • multiplexer/demultiplexer
  • comparator
  • adder/substracter/multiplier/divider
...and I do probably miss some types. 

A decoder is a type of circuit that will take a given number of input bits (a code) and will produce a set of signal for each code. The output will have a larger number of bits than the input. The encoder is the inverse, it will take a set of signals and generate fewer code bits. 

The multiplexer can be seen like a train rail that encounter an Y path. The train will take a selected path. The same thing happens with the multiplexer, the input bit (either one or zero) will propagate to one of the outputs, depending of the control signals (that set the path). The demultiplexer will take one bit from multiple input bits and propagate it to the single output depending of the control signals.

The comparator is used to determine which of two binary number is the highest. The mathematical operations (+ - x /) will also work on binary numbers.

A special type of encoder is the one-hot encoder. It will take a certain number of input bits, and generate a single high bit among the output bits (all other are zeroed). In the example animated GIF below, you can see how this encoder works. When the wire turns green, it means that the input is high. There is only one high output (lit LED) at a time. The gates used are 3-pins AND gates; observe that there are little bubbles at various inputs, this is a shortcut to indicate that the corresponding input is inverted. (ps. I used Logisim circuit simulator on Linux and took screenshots of the possible combinations to finally animate the cropped screenshots with GIMP)

The one-hot encoder circuit is used to create a decade counter. A popular decade counter chip is the CD4017 in the CD4000 series of IC. This integrated circuit is really old and we can see the chip layout (transistors) in the datasheet. In the picture below, you can see the mask of the real chip.

Sequential circuits

I won't go in the details of sequential circuits, I will keep that subject for later. A sequential circuits is a combination (no pun intended) of registers and combinational circuits. What's special with them is that their outputs will depend on when the inputs change (time factor). These circuits need a clock signal as a time base. Also, sequential circuits have internal states (memory effect) that are kept in different registers. The most complex digital structure like processors and state-machines use sequential circuits to work. An example circuit is a pass code locked door. The door will unlock only if a certain pattern of button is pressed sequentially. That would not be possible with combinational circuits.

6 Feb 2013

Digital Systems Part 2 - Transistors implementation

In the last post about digital systems, you learned the differences between the different logic gates. Now, we're going to look at how to make AND/OR gates with NPN transistors. But first, we need to talk a little bit about the purpose of the transistors.

The Bipolar Junction Transistor (BJT)

The theory behind the transistors is quite complicated (quantum theory, semiconductors and electronic doping). Fortunately, you don't have to know about all these things to understand the operation of the transistor. Keep in mind, transistors can operate in different modes but in this post we are only going to learn about the saturation mode. First, take a look at the schematic diagram of the BJT and it's TO-92 (Transistor Outline) casing :

In the saturation mode, the transistor is behaving like a simple switch. The transistor is a 3-pin device : emitter, base and collector (EBC). This switch will let the current flow in only one direction, from the collector to the emitter. The condition required to let current flow in the switch is that there is a small current flow between the base and the emitter. In other words, the base is a control pin and applying a voltage to it will close the switch (thus resulting in a current flow from C to E).

A small current flow from the base to the emitter will produce a large current flow between the collector and the emitter

Making gates with BJTs

With only two NPN transistors, we're able to build a AND/OR gate. The transistors used in the circuit will be the 2N3904. The circuit is simple : we have 4 switches (labelled 1 to 4) in a DIP package connected to a AND gate and a OR gate. The output of the AND gate is connected to a yellow LED; The output of the OR gate is connected to a red LED. In the table below, you see all the possible switch combinations. Without any doubts, S1 and S2 are wired to the OR gate (red), S3 and S4 to the AND gate (yellow).

Truth Table

S1 S2 S3 S4 Red LED Yellow LED
0 0 0 0 OFF OFF
0 0 0 1 OFF OFF
0 0 1 0 OFF OFF
0 0 1 1 OFF ON
0 1 0 0 ON OFF
0 1 0 1 ON OFF
0 1 1 0 ON OFF
0 1 1 1 ON ON
1 0 0 0 ON OFF
1 0 0 1 ON OFF
1 0 1 0 ON OFF
1 0 1 1 ON ON
1 1 0 0 ON OFF
1 1 0 1 ON OFF
1 1 1 0 ON OFF
1 1 1 1 ON ON

The Circuit On A Breadboard

The upper part is the OR gate, the lower part is the AND gate. The small components in black are the 2N3904 NPN transistors. On the left, all switches are off, on the right : 1 on - 2 off - 3 on - 4 on.


The circuit Schematic

I think the diagram below speaks for himself. With the OR part, the two switches are in parallel, so if one of the switch is closed, the red LED will light. For the AND part, the two switches need to be closed for the yellow LED to light. I chose 10 kiloohms for the base resistors (R1-R2-R3-R4) to produce 1mA of current from base to emitter. For the LED resistors, I chose the value of 680 ohms so 12mA is flowing in the LED. Please take a look at my post about diodes if you do not remember how to calculate the current through the LEDs.

That's it for today! In the next part, we will look at integrated circuits that contains four to six logic gates of the same kind (74 series); this will help us to make digital circuits faster. The goal will be to create complex structures with logic gates. See ya!

3 Feb 2013

Digital Systems Part 1 - Logic Gates

In electronics, there is the analog world and digital world. The analog circuits operate on continuous valued signals. Digital circuits operate on discrete signals values i.e. 1/0, on/off, high/low, true/false. In the digital world, we're interested in bits, that is binary numbers. You can learn more about the binary number base here. In numeric circuits, each signal (wire) is seen as either being high or low (two-valued logic). Depending on the voltage at which the circuit operate, the high value will be the power supply voltage : 3.3V, 5V, 12V, 24V... The low value will be equal to the ground reference.

Logic gates

The logic gates are the basic building blocks of digital systems. They provide the most simple operations on binary signals. With a combination of multiple logic gates, you can build complex circuits e.g. adders, comparators, encoders/decoders, timers, multiplexers, etc.  Here are the logic gates that we are going to work with (you can see the schematic diagrams of the gates and their truth table) :

The NOT gate

The most simple logic gate, the inverter will flip the value of the bit at the input pin (left pin on the picture above). Imagine you have a light connected to a N.O. (Normally Open) push button, when you press the button, the light will turn on. If you connect the light to a N.C. (Normally Closed) push button, the light will always be on unless you press the button. With an inverting gate, you could easily change the behavior of an N.O. contact into a N.C contact and vice versa.

The AND - OR gate

These gates are used to make logical equations. For the AND gate, all the inputs have to be on for the output to come on. Example : if button A is pressed AND button B is pressed, the LED will light up. For the OR gate, one of the inputs have to be on for the output to come on. Example : if button A is pressed OR button B is pressed, the LED will light up.

The XOR gate

The XOR logic gate serve a special purpose : when you look at it's truth table you realize that the output is on only when the inputs bits are not the same. This gate is then used to detect if there is an inequality of the input bits. The XOR gate is also used to compute the sum (S) of a one-bit adder. S being the sum, C being the carry bit : 

0 + 0 : S = 0, C = 0
0 + 1 : S = 1, C = 0
1 + 0 : S = 1, C = 0
1 + 1 : S = 0, C = 1

From the following equations can you see that S = A XOR B and C = A AND B? Here is the schematic of the one-bit adder.

In the second part of this tutorial, we're going too see how simple logic gates can be made with Bipolar Junction Transistors (BJTs).