Logic gates with a microcontroller


0

A solid knowledge of logic gates is the basis of programming and electronics. This is required in any project. Truth tables are a great way to visualize the results of different combinations of logical networks. In school, students study truth tables precisely, but they are often not accurately remembered. The device designed in the essay can help students better visualize truth tables in a simple way. The whole project is based on the use of a microcontroller. Logic gates: Logic “1” is synonymous with “real” and “high”. Logical “0” is a synonym for “error” and “subscript”. In digital electronics, there are three basic operations: NOT (negative): if the input value is “0”, the output is “1”, and vice versa. AND (logical product): the output value is “1” only if all inputs are “1”, and in all other cases the result is “0”; Or (logical sum): The result is “0” only if all the entries have the value “0”, and in all other cases the result is “1”. Digital circuits that perform these operations are called “logic gates”, as shown in Fig. 1. The NOT gate always contains only one input, while the AND and OR gates can have two or more inputs. The project includes the following logic gates: OR; And the; Nand. Nor; XOR; Figure 1: Logic gate symbols The logic gate or logic OR gate is a logic separation process. Provides input from two or more logic signals and returns “1” if at least one signal is equal to “1”. If all of the flags are “0”, then the result is equal to “0”. The logic AND gate The logic AND gate is a logical link operation. It provides inputs from two or more logic signals and returns “1” at the output only if all input signals are equal to “1”, otherwise it returns “0”. A NAND logic gate operating is equivalent to an AND gate, but the output is inverted. The logic NOR gate its operation is equivalent to the OR gate, but the output is inverse. XOR logic gate The XOR gate provides the exclusive classroom logic operation. It returns the boolean “1” only if one of the entries is “1”. It is often used as a logic NOT gate comparator. The logic NOT gate forms the inverter and provides the logic NOT operation. It receives a signal at its entrance and replays it at its exit. Truth Tables The project we are implementing requires the implementation of truth tables for logic gates on devices. The ability to turn on or off some triggers when the inputs are varied is certainly effective for understanding logical network operation. The truth table (see Figure 2) is a tabular representation of all possible combinations of values ​​at the inputs of logic gates and the corresponding values ​​in the outputs of these gates. A truth table allows to represent all possible cases in a tabular manner. It is useful for understanding numerical states of the logic circuit. Figure 2: Truth table wiring diagram There are many ways to implement the project described in this article. It can be made with separate electronic components and this solution will have an educational purpose instead, the project involves using a microcontroller. With some other input and output ports, it’s easy to program a complete logic system. The decision-making process is completely assigned to the firmware, which controls the logical levels of the input and displays the results through some of the LEDs. The wiring diagram, shown in Figure 3, provides for the use of PIC 16F876 but any other type of microcontroller can be used successfully. An external MCU clock is of the RC type. The clock frequency determination is managed by the following formula: T = R * C * 2.3 is F = 1 / (R * C * 2.3) using a 4.7 k أوم resistor and a capacitance of 22 pF, the microwave frequency is approximately 4204861 Hz (4.2MHz). Buttons A and B are the entries for logic gates. Pressing both puts the C0 or C1 ports of the microSD at a high level. Otherwise, they have lower logic potentials thanks to the presence of pull-down resistors of 10kOhm. The six LEDs, preceded by the same number of 220 ohm limiting resistors, represent the outputs of the logic gates OR, AND, NAND, NOR, XOR and NOT. The NOT gate concerns only the entry of key “A”. The entire system is powered by 5V. Figure 3: Firmware Logic Gate System Wiring Diagram with Great Cow Basic. The list of firmware is made with the free Grat Cow Basic compiler and you will find it attached to this article (see Figure 4). It is very simple. Let us explain in detail the different operations carried out by the controls. #chip 16F876, 4: This router is used to set the correct type of MCU and relative clock frequency (not critical in this application); y = z: These commands initialize the PIC ports to act as input or output; If portc.0 = 1 OR portc.1 = 1: it is a conditional check that checks the OR gate and the NOR gate; If portc.0 = 1 AND portc.1 = 1: it is a conditional check that checks AND gate and NAND gate; If (portc.0 = 0 and portc.1 = 0) or (portc.0 = 1 and portc.1 = 1) then: it is a conditional check that checks the XOR port; If portc.0 = 0 then: is a conditional check that checks the NOT port. All checks are executed in an infinite loop. It is advisable to carefully study the list of programs and look for alternatives in coding. Figure 4: Great Cow Basic development environment for programming PIC microcontroller firmware with ladder language The same program can be executed using ladder language. It is imperative to have in-depth knowledge, especially regarding the rational use of contacts and relays. Figure 5 illustrates the set of “scores” that comprise the entire program. This type of graphical coding may seem simpler than the procedural type, but we will see that the type in the base language provides more development capabilities and complete control over the system, as well as a simple environment for debugging, updates and adjustments. Fig. 5: The same firmware written in ladder language made the PCB to create the board for the logic gates. The printed circuit must be created and its effect is shown in Fig. 6. It is very simple but due to the presence of the microcontroller fingerprint, it is recommended to use the photoengraving technique. It measures 102mm x 86mm. Figure 6: Logic Gate PCB System When the PCB is ready, you need to drill 1 mm holes in the messenger pads. She then welds the components, starting with the low-rise components and then continuing with the larger components (see Figure 7). We recommend the PCB socket for the microcontroller. Pay attention to the direction of the polarized components. A small soldering iron of about 30 watts with a narrow tip should be used for soldering. Figure 7: Layout of components Creating the circuit in Figure 8 is very easy and accessible to everyone. Figure 8: 3D view of the BOM full circle. The electronic components are easy to find and are listed in the following material list: 1 Capacitor 22 pF; 6 LEDs; 6 resistors of 220 ohm; 2 resistor 10 kOhm; 1 resistor 4.7 kOhm; 2 keys or buttons; 1 photo 16f876. The only connections to the enclosure that must be made are those related to the circuit’s power supply and the two switches. As can be seen from the component layout, the LEDs are already placed on the PCB. This solution is really suitable, but it would be better to create an enclosure showing the actual design of logic gates, such as the one shown in Figure 9. In this case, it is necessary to mount the illuminated components on the top panel and carry out proportional wiring with the panel. Figure 9: It is recommended to create a container with a logic gate design. The test is very simple. The LEDs for the logic gates by supplying the circuit will be lit dimly, depending on the pressure of the “A” and “B” switches. As you can see, this version of the circuit offers two-input logic gates. Conclusions The visual and graphic presentations are always clearer than written or readable ones. This rule is also valid for electronics and mathematics. It is much easier to see with your own eyes how logic gates work, to understand how they work. This project is very useful for teachers and professors in universities and electronics schools. Attachments GCB Files: is the Firmware Source List written with Great Cow Basic; HEX files: It is the compiled executable file ready to be uploaded to the MCU; LD file: The source file for the program written in Ladder.


Like it? Share with your friends!

0

What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win
Joseph

0 Comments

Your email address will not be published. Required fields are marked *