Digital Electronics

Introduction

We live very much in the digital age, surrounded by computers, video game machines, music and video players, mobile phones and so much more. The advantage of digital electronics over handling data in analogue form is that with digital signals, data can be represented using binary which uses off and on signals, simplifying the circuitry needed to process the data.

I, like many others, have grown up and watched once purely analogue devices become totally digital; radios are a very good example. Once large pieces of equipment have shrunk over the years to a tiny size (although, that is in part thanks to the miniaturization of electronic components, in particular the use of transistors).

The natural world that we live in, however, in an analogue one; light, sound, heat and the like continually change and cannot be represented in digital form without first converting them. For example, for a computer to be able to record sound picked up by a microphone, it must first convert the analogue signal from the microphone into the digital equivalent.

On this page you will find lots of information about digital electronics which I invite you to read as little of, or as much as you like.

New: Memory (1/1/2017)

Microcontroller, System on Chip and FPGA (27/5/2015)

Logic ICs (24/11/2013)

Logic function tester (24/11/2013)

You can email me at james.boshikoopa@gmail.com

To return to the main Electronics page please click here.

Digital Signals

A digital signal can only ever be on (logic 1) or off (logic 0), which is represented by a change in voltage. For example, logic 0 could be represented by anything from zero volts to almost half the supply voltage and logic 1 as anything from just above half to the full supply voltage. There is often an area of the supply voltage about the middle that is not definitely logic 1 or logic 0, so circuits should be designed to keep within the range that is acceptable as logic 0 and logic 1.

You may be wondering that if digital signals can only use either logic 0 or logic 1 at one time, how can larger numbers and other, more complex data be represented? The answer is that we can send a series of digital signals through a wire, known as series, or we can group together multiple signals, which is the parallel approach. Please read the Binary section before moving on.

Logic Gates

Logic gates are decision making components that operate on binary signals, and can either be used on their own, or can be connected together to form complex circuits. In general, a logic gate will have one or more inputs and often the one output, which will be dependent on its input(s).

The combination of inputs and the resulting output is often shown in what is known as a truth table since it lists all possible states and the outcomes. We will start with the most basic logic gate, the NOT (inverter) gate and its truth table which can be seen below.

A

0

1

Q

1

0

 The NOT gate has one input called A, and a single output called Q; the output is the opposite of the input. One use of the NOT gate is to activate something by a logic 0 value in a system that outputs a logic 1 under some condition.

 

You can put NOT gates at the inputs and outputs of other gates to change their behaviour, effectively creating new gates. If you were to feed the output of a NOT gate into the input of another NOT gate, the output of the second NOT gate would be the same as the input of the first NOT gate.

 

A more versatile logic gate is the OR gate which has two or more inputs but just the one output. The truth table that follows is for a 2-input OR gate:

 

 

An OR gate's output is at logic 1 when either or all of its inputs are at logic 1. If a NOT (inverter) gate is placed at the output of an OR gate, it becomes a NOR gate (i.e. Not-OR), in which case its output is only at logic 1 one when all of its inputs are at logic 0, as below:

 

 

If all of a NOR gate's inputs are connected together to form a single input, the gate becomes a NOT (inverter) gate (in which case, in the above truth table only the first and last lines are valid since A would be the same as B).

 

Since NOR is an OR gate with its output inverted we can represent both the OR gate and the NOR gate in a single truth table:

 

 

The output for the OR gate is Q and the output for the NOR gate is Q̅; the bar above the Q means 'not', so Q̅ means not-Q. You will sometimes see /Q, that is, the forward-slash symbol used to mean 'not' since it's a lot easier to type on a computer than the bar above the letter which requires a special key combination.

 

The bar above a letter or name, or the forward-slash symbol before a letter or name is also used to signify that a signal is 'active low'. For example, to sound a buzzer, it may be required to use a logic 0 value to turn the buzzer on and a logic 1 value to turn the buzzer off. If, however, the signal was 'active high' the opposite would be true; logic 1 would turn the buzzer on and logic 0 would turn the buzzer off. This idea of 'active high' and 'active low' it should be clear, is related to inverting signals.

 

An AND gate also has two or more inputs and a single output. By looking at the AND truth table below you can see that its output is at logic 1 only if all off its inputs are at logic 1.

 

 

By placing a NOT (inverter) gate at the output of an AND gate, it becomes a NAND (Not-AND) gate, which will have a logic 1 signal at its output unless all of its inputs are at logic 1 (see following truth table).

 

 

If all of the inputs to a NAND gate are tied together to make a single input, the gate will behave like a NOT (inverter) gate, just like we saw with the NOR gate.

 

Like with the OR and NOR gate, we can show the conditions and outcomes for both the AND and NAND gate in one truth table. The output Q is for the AND gate and the output Q̅ is for the NAND gate.

 

The exclusive-OR (XOR) gate has one or more inputs and a single output. Its output is at logic 1 if either but not all of its input are at logic 1. This is shown in its truth table below:

 

 

 

If a NOT (inverter) gate is placed at the output of an XOR gate, it becomes an exclusive-NOR (XNOR) gate whose output is at logic 1 if all of its inputs are either at logic 0 or logic 1. This is illustrated in its truth table, below:

 

 

It should be no surprise now that both the XOR and XNOR gate conditions and outcomes can be shown in a single truth table. As below, Q represents the output of the XOR gate and Q̅ is the output of the XNOR gate.

 

Logic ICs

Although we can make logic gates out of discrete components, such as transistors, there are ICs already available that contain one or more logic gates. The two most famous and still widely used today logic gate IC ranges are the 7400 and 4000 series. Some of these chips house a number of individual logic gates to be connected up as needed outside the IC. Others are made up of internally connected logic gates which form complex circuits including shift registers and counters, to name but a few.

For example, the 7400 contains four 2-input NAND gates, the 7404 offers six inverter gates, the 4001 houses four 2-input NOR gates and the 4049 comprises six inverter gates. The key difference between the 7400 and 4000 series is that the 7400 series uses Transistor-Transistor Logic (TTL) whereas the 4000 series uses Complementary Metal-Oxide-Semiconductor (CMOS) technology. The main advantages and disadvantages of these two technologies with regards to the 7400 and 4000 series are listed below:

The choice of whether to use a 7400 or a 4000 series chip can be based on the points in the table above. 7400 ICs are limited to a 5V power supply so for portable designs generally the 4000 series would be a better option. As the 4000 ICs internally are made of fewer transistors compared to 7400 chips, some of the 4000 ICs combine the abilities of several 7400 ICs (e.g., a counter and decoder).

When handling 4000 ICs much greater care is needed than the 7400 series as 4000 ICs can be damaged by electrostatic discharge, although static build up and release should be avoided when handling any IC. Another problem with 4000 chips is that unused inputs cannot be left floating while the chip is powered, that is not connected to either of the power supply connections or the output of another logic gate, otherwise the chip may use more power than normal or behave oddly. That said, even with 7400 ICs it's best to not have any unused inputs floating. If a 7400 series IC input is left unconnected while powered it will float to logic 1 whereas with 4000 series ICs can float to any logic level.

Within the 7400 and 4000 series there are a number of variations which attempt to address some of their issues. These variations are denoted by a number of letters between the device number, such as the 74LS74 which differs to the 7474 in that it is a lower power version.

Logic function tester

The logic function tester was designed as a way of learning how the main logic gates (AND, NAND, OR and NOR) work. Have a look at the circuit diagram that can be found below:

SW1 selects the logic type, and SW2 and SW3 set the state of the two inputs, A and B, as reflected by LED1 and LED2 respectively. The output of the selected logic gate is indicated using LED3.

It is intended that the circuit is only used in temporary form such as on breadboard, as a number of shortcuts have been taken. Firstly, only one logic gate is used from each of the 7408, 7400, 7432 and 7402 whereas a better approach (although would be harder for beginners to follow) would be to create each logic type from just one logic gate (e.g., NAND), which would waste less logic gates.

Secondly, the outputs of the logic gates are connected together which should normally not be done as it could damage the ICs. It is safe to do so in this circuit as only one of the ICs receives power at once. Even so, it would be much better to have all ICs powered at once and connect LED3 to a single output of a logic gate using a switch.

To see the circuit in action why not check out my video on logic gates:

http://youtu.be/gpTxtcZkZ80

Memory

Often, we need the ability to either temporary or permanently store data values that are used by a system, whether it's as simple as remembering that a button was pressed or looking up complex values as part of a formula. There are two main types of memory, which take the form of microchips, and they are RAM (Random-Access Memory) and ROM (Read-Only Memory). A RAM chip can store a number of values which can be read back and changed an unlimited amount of times as long as there is power; if power is lost the RAM will loose its stored values. Thus RAM chips are said to be volatile and they are typically used to temporary store data such as state information and calculation results.

RAM can be divided up into two main types which are SRAM (Static Random-Access Memory) and DRAM (Dynamic Random-Access Memory). To store each bit in a SRAM chip a flip-flop type arrangement is used consisting of around 6 transistors. SRAM was once was the most frequently used type of RAM until it was taken over by DRAM. DRAM uses only a transistor and capacitor to store a bit of information and while this means the cells have to constantly be refreshed to keep the data, because of the simpler circuitry a lot more memory cells can be placed on a chip compared to SRAM.

As a contrast, ROM is non-volatile, in that the data the chip holds will not be lost if the power is removed. ROM chips come in two main types; those that have fixed data that can never be changed and those that can have their data altered multiple times, which are usually referred to as programmable. Examples of the first type are mask ROM's (data set by the manufacturer) and OTP ROM's (One Time Programmable; the chip is bought blank and programmable by but cannot be changed again). ROM's that can be programmed multiple times include EPROM (Erasable Programmable Read-Only Memory) chips which are erased by exposing the UV (ultraviolet) window to a UV light source (which sets all the memory cells to 1's) and then programmed electrically (which sets the required bits to 0's). UV ROM's typically will have a sticker covering the UV window after the chip has been programmed, typically giving information about what is stored on the chip. Another form of re-programmable ROM is EEPROM (Electrically Erasable Programmable Read-Only Memory), which can be erased and programmed as much as a million times in-circuit (no need for a UV ROM). Lastly, there is flash memory which can be re-written typically 100, 000 times but has to be programmed in blocks rather than on the byte level (although that may be handled internally by the chip).

To further illustrate how an OTP ROM works I'm going to talk about the 27C256 IC which is a 32K x 8 ROM and you'll see how it's possible to program the chip multiple times, with a catch. The 27C256 was available in both UV window versions and non-UV window versions, with the latter the one I'll be talking about here. When bought new all the cells with be 1's (the bytes will be 0xFF) and once a bit is programmed as a 0 it can never be changed again. This does mean, however, you could program a byte multiple times if you use certain values but you cannot go back to a previous value. So, if the byte started on 0xFF, I could, for example, program it to 0xFE, then 0xFC, and so on, each time taking just 1 bit low.

It is easy to accumulate a collection of ROM chips that cannot be re-programmed from taking apart equipment and the like. You may wonder what use you could make of such chips that have fixed data but they can still have a use. Why not use the values stored in the ROM's as a 'random' number generator? By chance the values will vary quite a bit between cells with some repeated patterns which, if it's a program, can seem random. Why not use the values in the ROM to produce varying colours of an LED or even to make sound.

Parallel VS. Serial

When sending data through a circuit or from one device to another, the information can be sent in either serial or parallel form. When data is transferred over a serial connection it is usually sent one bit at a time which has the big advantage that only a few connections are needed (e.g., data and ground). On the downside, serial data can be more difficult to work with as often data is stored in parallel form in memory (groups of bits forming numbers, etc.) and must then be converted to serial. Also, looking at the raw serial data it can be hard to work out the information that is being sent as it is just a stream of 1's and 0's.

With parallel, groups of bits are sent simultaneously, such as to make up a byte (usually, 8 bits). This requires more connections but can be faster than serial transfer and more closely matches the way data is often stored, requiring little or no conversion before the data is sent. Therefore, data in parallel form is usually much easier to work with than serial data.

Sending data in serial form has greatly replaced transmitting data in parallel form. On most older computers, for example, the parallel port was used for connecting printers, scanners and so on. Nowadays, most often devices are connected to a computer using USB (Universal Serial Bus). While USB is much more complicated to work with than the parallel port it is a much more intelligent and faster connection and USB cables are cheaper to make as they use only four wires.

Internally in computers, hard drives, CD drives, etc, were connected to the motherboard using a parallel connection called PATA (Parallel Advanced Technology Attachment). However, PATA was replaced with a serial interface called SATA (Serial Advanced Technology Attachment) which uses fewer wires than PATA, reducing the chance of interference and allowing better air circulation, which keeps components cooler.

Binary

Please go to Number Systems.

Create Your Own Computer

Please go to Create Your Own Computer page.

Microcontroller

A microcontroller is a simple computer contained in a single chip; it contains a CPU core, RAM, I/O (Input/Output) interface, timing and many feature flash memory to store program code and configuration, and is typically used to do something very specific. Whereas once upon a time many chips and other components would be needed to make a computer system, microcontrollers bring all those many parts into a small, cheap IC. One of the key advantages of microcontrollers over other systems is that they can easily be connected to switches, lights, and many other forms of input and output either directly or through additional circuitry. Example real world uses of microcontrollers include their use in TV (DVD, media player, etc.) remote controls, electronic toys, robots, domestic appliances, and so on.

Probably the two more common range of microcontrollers are the PIC and AVR series and within those series are a huge range of devices from simple to very complex in terms of processing power, how much RAM they have, the number of I/O, and so on. Development boards are available in which microcontrollers can be programmed and tested; development boards such as the Arduino make it much easier to use microcontrollers as they are a working system that needs very few additional components to be connected, depending on what you want to do. The main thing you then need to work on is your code which the microcontroller will then run, but likely there is already available the necessary software libraries and example code to get you started.

Microcontrollers are ideal for use in devices that must have precise timing such as remote controls, test equipment, computer mice and keyboards. Hobbyists have been able to push microcontrollers to simulate protocols not normally supported by a microcontroller to output, for example, a VGA signal, by using a technique called bit banging. Bit banging generally makes use of a general purpose I/O pin on a microcontroller (that is one that does not have a hardware defined protocol assigned to it) to emulate a protocol. This has the advantage of expanding a microcontroller's ability but does require that the microcontroller spend more time communicating than other tasks so it may be difficult to balance the tasks.

To learn more about microcontrollers, please check out my pages; Arduino, Pic Microcontroller, Raspberry Pi Pico.

System on Chip

When we need more processing power including the ability to run an operating system then a System on Chip (SoC) can be used, which is like a souped-up microcontroller. They are typically used in portable devices, such as tablets and mobile phones, with the single board computer Raspberry Pi being a good desktop example. The Raspberry Pi runs Linux and provides user programmable I/O like a microcontroller but is not so good when guaranteed timing is needed as the O/S may give priority to other tasks. You can, however, use a microcontroller and SoC together which is what some people do with the Arduino and Raspberry Pi.

You may like to read my page on the Raspberry Pi.

For more information about the above topics and for practical examples of them being used please click here.

FPGA

Then we come to the Field-Programmable Gate Array (FPGA) which is a programmable IC in a totally different way to a microcontroller or SoC. An FPGA consists of thousands of programmable logic blocks (or logic elements) which can take on different roles (flip-flop, memory cell, etc.) and can be connected in different ways as well as having independent I/O blocks. An FPGA can be configured to become whatever you want it to be unlike a microcontroller or similar chip which has fixed internal elements that are connected in an unchangeable way. If you want the FPGA to be a processor core (that is, an emulated CPU) then that is possible and you can even put a complete system (such as a retro computer) on to an FPGA.

FPGAs are a lot more complex to use than microcontrollers and even a basic FPGA will have thousands of logic blocks and perhaps 100 I/O connections. Another point to note is that most FPGAs don't have internal flash memory and instead rely on an external flash chip and because of this FPGA's are typically somewhat slower (although still very fast) to start up than microcontrollers as they have to read in the configuration information. But this does mean that during the prototyping phase you can keep making changes to the FPGA without updating the flash memory, which is faster, and should the design go wrong you can fall back onto the last saved design in the flash memory if needed.

Another advantage of FPGAs over a typical microcontroller is that they can process multiple streams of data at once whereas many microcontrollers can only process one stream at a time. Another plus point to FPGA's is that they can easily be re-configured unlike a circuit that uses fixed elements which would need soldering to change. FPGAs can even be used to prototype other types of chips (such as a SoC) or complete systems.

Like SoCs, FPGAs come in high pin count packages (100 pins or more) which means the ICs aren't breadboard friendly. When starting out with FPGAs it's a good idea to get an FPGA development board which contains the FPGA and support circuitry as well as test inputs (e.g., switches) and outputs (e.g., LEDs). Some boards have many inputs and outputs but are likely to cost more than plain boards, and will have less I/O you can use. You will also need a programmer which will either be built into the development board or will be a separate unit.

Because of the complexity of FPGAs a lot of effort is required even to get an FPGA to flash an LED and that is not counting the hard work the development software does behind the scenes. Fortunately, good FPGA development software will provide both basic logic and complex logic elements to get you going; even emulated versions of hardware logic chips such as the 74' series ICs, as well as other useful logic blocks such as RAM and ROM (which can be initialized with your own values).

For more information about FPGA's please click here.

All content of this and related pages is copyright (c) James S. 2010-2023