RedPower Tutorial

Revision as of 01:47, 10 April 2012 by Miniboxer (talk | contribs)

The amazing redpower logic gates tutorial by mehungary!

A Few opening Words

Welcome to My tutorial and explanation of how to build effective logic circuits. Red Power as a part of Technic has logic gates, and with logic gates comes the ability to design and implement many many things. My guide is not to teach you what to do, but only to help you do it with out the endless headaches of trial and error. Sure you can solve almost any simple logic gate function by flailing around ideas until it works, however there is no guarantee that such a circuit was designed with as few resources as possible, nor that it will work for every input. If you have Questions ask away, I'll do my best to answer them or find a resource that can.

Resources

Logic Simulators

Say you want some complex circuit, and you have done some work on how to build this circuit, well then its time to test it. There are a few FREE logic gate simulators. You can find many on a simple Google search. All my examples will be done with Logisim, so if you want to build a circuit using any other Simulator go ahead, however don't complain that its not working the way i describe it if your using a different Simulator.


Information Regarding Combinational Circuits

Due to Red Power Not having Adders, or Registers or Really any Combinational Circuitry you will have to build every device yourself using logic gates, which in some Combinational circuits could be very costly, and take up a lot of space for one component that you might be using a few of. So unless you Plan Accordingly Implementing this stuff Could be Very Frustrating. That Said I Will Cover this Topic as it is important to building more advanced circuits. Here are some Links for you Viewing pleasure(more to come). Bit Adder [1] Shift register [2] Decoder [3]

Other Sources

Here I will put Links to Other Tutorials related this Topic A tutorial On Gates. [4] All the Truth Tables for Gates [5]

Basics

A Simple Example

We will start with a simple problem one that is very common for most technic Users. We have 2 or more Metal doors to an Entrance. We know that one door will open and the other will close if they are side by side it is a very annoying thing to have to have only one door, or worse have lots of switches or buttons to open/close each door manually. However this problem can be easily fixed using Logic gates and some preparation.

Lets break down this problem. First we only want 2 switches one for outside and one for inside. Second we only want to open these two Doors at once. So we have only one output. Lets also say that we want theses doors Closed only when both the switches are in the same place.

Switch Switch Outside Inside | Door

 OFF      OFF    | CLOSED
 OFF      ON     | OPEN
 ON       OFF    | OPEN
 ON       ON     | CLOSED

As we can see in the table above This is the desired operation of our circuit. If you have ever taken a logic course this should look familiar to you, this table represents the logic of exclusive or, we happen to have a Gate that works in the same way, a XOR gate. Here is our Logic Circuit from logisim

the logic circut diagram described in the last sentence.
The circut implemented in minecraft


Truth Tables

These Tables represent your input and output, and the combinations you can have. You will have 2^n combinations of input where n is the number of inputs. For example we have 2 inputs so our total combinations result in 4 Like the table in the simple example. For General Purposes you'll rarely need to go over 4 inputs, and well if you do you'll need machine help to reduce. 4 Inputs is the recommended max for simple logic circuits to be simplified by hand (4 inputs will result in 16 combinations). Count UP in binary from the top of the table to the bottom.

The Binary 0 = OFF The Binary 1 = ON Represent Each Input With a single letter. Output is on when your desired input combination is active

Example: Input|output a b c | e 0 0 0| 0 |m0 0 0 1| 0 |m1 0 1 0| 0 |m2 0 1 1| 0 |m3 1 0 0| 0 |m4 1 0 1| 1 |m5 1 1 0| 1 |m6 1 1 1| 1 |m7 BINARY DECIMAL

Boolean Algebra Logic Gates

There is A LOT to cover with Boolean Algebra so i'll just give you what i think you will need to know, if you want more look it up on the net. The Basic Rules Multiplication = AND logically Addition = OR logically ~ = NOT logically (if P was =0 then ~P = 1) There are 17 Identities to Boolean algebra used to reduce the equations, they are nice however we don't need to know them if we can use K-maps.

Translating your Table Into a Boolean Algebraic Expression. In the truth table section the example table has a list of base10 numbers with lower case m's beside them like m0. These's are called the Sum of min terms we use these in K-map reduction. But they also represent The variables we want to see in an Algebraic Expression. Its quite simple the number in binary is the min term's number, and the binary number itself represents the Algebraic expression. when converting from Binary to algebraic 0 = ~variable and 1 = variable.

For example: 000 is = 0 in base10 so its min term is 0 and it's algebraic representation is ~a*~b*~c.

The min terms we use are the ones that the output = 1 on. In the table example there the min terms are m5,m6,m7 and can be represented buy the algebraic expression:

     m5        m6           m7       min terms

1 0 1, 1 1 0, 1 1 1 Binary a*~b*c + a*b*~c + a*b*c Algebraic

Translating Your Boolean Algebraic equation into logic gates X*Y = AND gate X+Y = OR gate ~X = NOT gate ~(X*Y) = NAND gate ~(X+Y) = NOR gate (X*Y)+(~X*~Y) = XOR gate (~X*Y)+(X*~Y) = NOR gate

So if we have the expression a*b+a*~b then we would need 2 AND gates, 1 NOT gate, and 1 OR gate, and it would look like this:

as a general Rule start with multiplication (AND gates) first.

K-MAPS

What are K-maps? Well they are useful tools in reducing your min terms into the most efficient Circuit your circuit can be straight from a truth or state table. Below are the k-maps and the locations of the min terms. K-map with 4 elements

K-map with 8 elements

K-map with 16 elements


Using K-MAPS The first thing you'll need to do is make a k-map with the same number of min terms. Then mark the min terms that make your output on from your table. As you can see there may be block that at adjacent to one another we will use these to reduce.

The Rules of reduction: 1) You can only use adjacent Blocks NO DIAGONALS!!! 2) Blocks on the edge are adjacent to other edge blocks 3) In the Future there will be I don't care Areas these can be used as adjacent blocks 4) The Number of adjacent blocks in order to be reduced must be a power of 2. ie 1,2,4,8,16 ==2^0, 2^1, 2^2, 2^3 , 2^4. 5) The number of variables that are reduced are; X - N where X is the number of variables, and N = 2^N adjacent blocks. 6) The variables that change from block to block in the area to reduce are the ones reduced. 7) If the number of adjacent blocks = the total number of blocks then the Value is 1 8) You can use adjacent blocks more than once.

An Example Of K-map Reduction:

F(ABCD) = SUM {0,1,2,4,5,6,7,8,10,15} - Different syntax for sum of min terms

Blue Dots = Our Selected min Terms Line 1 = ~A*~C Line 2 = ~A*B Line 3 = B*C*D Line 4 = ~A*C*~D Line 5 = A*~B*~D total = ~A*~C* + ~A*B + B*C*D + ~A*C*~D + A*~B*~D and here is what that Circuit looks like


Implementing the Circuits in Minecraft

Ahh the best part where we actually do what we want. There are some problems with directly taking your wonderful and pretty circuit diagram to actual operation in Minecraft. There is the issue that there most gates have only 3 inputs, using less than three is doable, but using more than 3 inputs into a gate requires some more planing. As you can see in the circuit above that the OR gate has five inputs not three. To solve this we need to use more gates without affecting the outcome of our circuit. Its fairly simple to do.

The Solution is to Add another layer of the same kind of logic gates. We went from having a 5 input OR gate to having 3 OR gates. Implemented in Mine craft

Advanced

Flip-flops and Latches

These Circuits can store information in different states. The only latch that Red power gives you is the RS latch, the simplest latch. IMO it would have been better to give us the JK flip-flop because it can be easily made into other Latches and flip flops. Understand that the reason behind this is because they are using only circuits that operate with 4 sides and most Flip Flops need at least 5 inputs, so RS is about as good as it will get. They also could have given us the d-flipFlop as they also only need 4 sides, and would have been much more useful than the RS flip-flop, but didn't for some reason...

Check this out for Circuit diagrams and information regarding the circuits. http://en.wikipedia.org/wiki/Flip-flop_(electronics)#JK_flip-flop

I will be using D flip-flops because for State tables D Flip-Flops are very easy to use. However if your going to build a d-flipflop don't use a RS latch instead build one out of 4 NAND gates and 1 inverter, you will get fewer errors this way.

Here is The D-FlipFlop using a RS Flip-Flop DON'T BUILD IT THIS WAY!


(in logisim you will need to also use the clock input to check operation or just use D-flipflops)

MAKE YOUR D-FLIP FLOPS THIS WAY! Here is the better version of a D flip-flop Using NANDS


For the most part we attach the clock signal to the E (enable) input, and the Data we want to store in the D (data) input. No matter what the d input is the output will only change on a clock pulse or while enable is on.

State Tables

State tables are not simply input and output, but rather Current state and next state, there can also be an output attached to some states. For example we want to create a sequence of outputs that changes every clock pulse. A sequence can repeat itself or it can just go until it ends and then needs to be reset. 00,10,11,01 is a sequence lets say that it repeats itself, but also lets have it reset if our input is 0 and continue on if its 1. Also the states themselves are the outputs. Lets First Represent this with a Diagram.

Here is it's State Table min |Current| | Next term|D1 D2 | input | D1 D2 m0 |0 0 | 0 | 0 0 | m1 |0 0 | 1 | 1 0 | Q1 on m2 |0 1 | 0 | 0 0 | m3 |0 1 | 1 | 0 0 | m4 |1 0 | 0 | 0 0 | m5 |1 0 | 1 | 1 1 | Q1, Q2 on m6 |1 1 | 0 | 0 0 | m7 |1 1 | 1 | 0 1 | Q2 on (Q is the Input For the D Flip-Flop) Q1 = m1,m5 Q2 = m5,m7


Q1 = ~D2*Input Q2 = D1*Input

Here is the resulting circuit diagram.


Multiplexers

These are like digital switches, they also can be used as NOT gates, AND gates, and OR gates. Multiplexers are also similar to Decoders, Encoders and Demultiplexers. Those will be covered later.

Multiplexer and it acting as a logic gate. A 2-1 Mux is as simple as it gets.

The multiplexer has 2^n inputs and n controls. When the control is on it selects the input Labeled Input 1 to output, when the control is off it selects the input labeled Input 0. So if the selector was 0, and Input_0 was 1 then the output would be 1.

Here is an example of a 8-1 Mux.

Here is a table on how it works

S3 S2 S1 | Input Selected to Output


0   0   0  |  0
0   0   1  |  1
0   1   0  |  2
0   1   1  |  3
1   0   0  |  4
1   0   1  |  5
1   1   0  |  6
1   1   1  |  7

Binary    | Decimal (base 10)

Encoders and Decoders

These are not very hard at all. They are used mostly to compress information, or expand information. An encoder can take lots of inputs and turn them into a few outputs, while a decoder takes a few inputs and makes more. the smallest you can make one is a 1 to 2 decoder , and an encoder 2 to 1. This is very useful if you want to transmit information without it taking up a lot of wires.

Some Rules about decoders and encoders: 1) The number of inputs for an encoder is 2^N 2) The number of outputs for an is N 3) The Opposite is true for Decoders.

An example of an encoder; If you had 4 inputs then you would have 2 outputs because n=2 if 2^n =4. Here is the truth table for an encoder 3 2 1 0 | B1 B2 0 0 0 1 | 0 0 0 0 1 0 | 0 1 0 1 0 0 | 1 0 1 0 0 0 | 1 1 Here's an encoder. One problem with this type it that it must always have some input, or you will be getting a default output which you might not desire.


This is a priority encoder, which lets you know if there is any actual input into the encoder, via the bottom output.


Decoders

These are just the opposite of encoders. Here is the truth table for a 2-4 decoder.

B   C | m0 m1 m2 m3

0   0  |  1    0   0    0
0   1  |  0    1   0    0
1   0  |  0    0   1    0
1   1  |  0    0   0    1

The output is the min term of the binary input.

Here is a 2-4 decoder with enable (E)


I added an enable because you'll be outputting m0 constantly if i didn't. It also works well with the priority encoder.

Here is a Priority encoder to a decoder with enable.


Other Circuits

Here I will cover Adders, Registers, even and odd parity, Grey code and how to build every circuit out of only NAND gates.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Need wiki hosting?

Do you need a wiki for your Minecraft mod/gaming wiki? We'll host it for free! Contact us.

Other wikis

Indie-game wikis
Powered by Indie Wikis