# Digital encoder simulation using Pspice : tutorial 15

In this tutorial I will explain you the working of a simple digital system known as a digital encoder. At the start a brief and concise introduction to encoders specifically a simplest 4×2 encoder is provided with the explanation of the output they will show. An encoder is the opposite of a decoder or a multiplexer. It is used to encode the numbers into binary digits as you will see shortly. After that the circuits is simulated using PSPICE and the result are compared with the theoretical discussion provided (which should be same). You are provided with an exercise to do it by yourself, at the end of the tutorial and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.

### Introduction to digital encoder

An encoder in its simplest terms is a circuit, a device, a software program or a person that can convert information from one format or type to another. In digital world, however, encoders are named as devices which can change the binary digits from one format to another. The block diagram of a simple 4×2 encoder is shown in the figure below,

Figure 1: Block diagram of encoder

This encoder will encode a four-bits binary number in two-bit binary number. The internal diagram of a simple 4×2 encoder is shown in the figure below,

Figure 2: Encoder circuit diagram

If the value of A0 is 1 then then output will represent a binary 0 and if A1 is 1 and all others are zero, then the output will be a binary 1. The truth table of a 4×2 encoder is shown in the figure below,

Figure 3: Truth table of encoder

This implies that when A0 is 1 the output will represent 0 (00) and when A3 is 1 the output will show 3 (11) as is obvious from the above truth table.

### Digital encoder simulation using PSpice

• Encoder in its simplest form is a 4×2 encoder. By 4×2 we mean that the number of inputs is 4 (the first term of the name) and the number of outputs is 2. An encoder as we have discussed above is used to encode the digital numbers from one format to another. Lets’ know design the circuit for an encoder on PSPICE using the techniques we used previously. Write design manager in the search bar of your laptop. PSPICE design manager will open, after that click on the run schematic button to open the schematic as shown in the figure below,

Figure 4: Opening new schematic

• After you open the schematic before designing the circuit on the schematic first save it so that you can use it in future. Click on the file icon at the top and then click on save as or simply press Ctrl+S on the keyboard to save the schematic as shown in the figure below,

Figure 5: Saving schematic

• At the top bar of the schematic you just save click on the get new part. This block contains all the components that can be needed in the simulation of an electric circuit as we have done in previous tutorial. Refer to the figure below to see the get new part.

Figure 6: Getting new part

• In the search portion of get new part block type ‘7432’ this will show you an OR gate. As is obvious from the circuit given in the introduction part and OR gate is the main component of the encoder. Refer for the figure below,

Figure 7: Placing OR gate

• Again open the get new part block and in the part name type stm this will show a list of digital sources. Select a simple digital source and place it next to the OR gates. Refer to the figure below,

Figure 8: Placing digital source

• The placed components for an encoder circuit is shown in the figure below,

Figure 9: Placed components

• Now in order to complete the circuit diagram we need to connect the components and for connecting we use to the draw wire block as shown in the figure below,

Figure 10: Drawing wire

• After connecting all the connections, the complete circuit thus formed is shown in the figure below,

Figure 11: Complete circuit diagram

• The digital source at the bottom of the circuit diagram is represent the input source A0. As you can see from the figure of the circuit diagram in the introduction part A0 is not connected to any component as shown in the circuit diagram above. Next step is to place the voltage marker at the input and output nodes of the circuit. A voltage marker is placed at node where we want to see examine the voltage. From the top of the schematic select voltage marker as shown in the figure below,

Figure 12: Voltage marker

• Place the voltage marker at the output ends of the OR gate and at each end of the input digital source. The placed voltage markers are shown in the figure below,

Figure 13: Voltage marker

• If we are interested in viewing the voltage waveform at a specific line or a wire, we can also label it. Double click on the line you want to label and give it a suitable name as shown in the figure below,

Figure 14: Labeling a line

• After labeling all the input and output wires the circuit diagram will look like the one shown in the figure below,

Figure 15: Labeled circuit diagram

• We can also name any device according to their use in the circuit. Double click on the device you want to label and in the Package reference designator block type the name you want to give to the device. Naming of a device is done only to differentiate it from other sources and there is no any other purpose of naming a device. Refer to the figure below to understand naming a device,

Figure 16: Labeling a device

• After labeling all the devices according to their use in the circuit, the circuit will look like the one shown in the figure below,

Figure 17: Labeled devices.

• Next step is to adjust the attributes of the input devices. As there is no use of the A0 digital source in the circuit diagram and is only placed for the understanding purpose we can also remove it and the functionality will remain same and we will adjust the attributes of all the signals according to the truth table given in the introduction part.

Figure 18: Attributes of A0

• A0 will be 1 at the end of the 4s simulation, as is obvious from the truth table.

Figure 19: Attributes of A1

• A1 will be 1 for 1s before the previous source i.e. A0 was 1 and zero otherwise as shown in the figure above and before A1 A2 was one i.e. 1 for 1s as shown in the figure below.

Figure 20: Attributes of A2

• And at the very start A3 will be one and zero otherwise as shown in the figure below,

Figure 21: Attributes of A3

• For simulation setup click on the analysis part at the top and then click setup as shown in the figure below,

Figure 22: Simulation setup

• After that click on the transient block and adjust the properties of the transient as shown in the figure below,

Figure 23: Transient block

• The last step to do here is to simulate the circuit you designed. Click on the analysis button again and click on simulation as shown in the figure below,

Figure 24: Simulation

• Another window will pop-up displaying the output of the circuit you design as shown in the figure below,

Figure 25: Output of the encoder

If we compare the output of the encoder with the truth table they both will be same.

Exercise:

• Design a 8×3 encoder using the same techniques provided in this tutorial.