• 12/5/11 3:51 pm
- 1.4k views • 0 today
- save_alt 158 downloads
- Progress
- 100% complete
Added CreditPeri_Rawesome
31
Redstone Adding/Subtracting Machine
This machine is an improvement on my last design. Firstly, instead of using levers for inputs, it uses buttons and an RS NOR latch array. This means that you no longer have to find and deselect your previous choice first, it does that for you when you press your new selection. The machine can can now add/sub two numbers 0-30, improving on the previous 0-30.
Thanks to Peri_Rawesome for taking the time to help me program the delay, it was a big project made easier with his help
How it works (simply)
1) An button is pressed in one of the input centres. The button is connected to an array of RS NOR latches, it first resets all the RS NOR latches so there is no choice, then after a short delay activates the chosen RS NOR latch, so that preference is active. This is then done for the other input.
2) Both inputs feed directly into pre-programmed decoders that will take the decimal input and convert it into a 5 bit binary number. Now we have our red and blue lines, one for each of our inputs, each holding 5 bits of information.
For Addition
Providing the 'add/subtract' lever is set to add, the information from the red line will pass straight into input A of the 5 bit adder, and the blue line will pass straight into input B.
The two numbers are added together, and a 6 bit binary output is produced (the sixth bit being the carry bit).
Because the 'add/subtract' lever is set to add, this output will pass straight through into the orange wool decoder. This decodes the binary into a decimal values. The decimal value then passes into the 7 segment display decoder, which hides/shows the appropriate parts of the display.
For Subtraction
Subtraction is a little more complex. If the lever is set to subtract, the red line will be inverted. This is achieved through an XOR gate. In addition the red line passes through the XOR gate, but because the subtract line (the line of redstone that has power if the lever is set to subtract) is off the output isn't changed the red line continues untouched into the adder. However, when the subtract line has power, the XOR gate will invert the red line so we have an inverted input A and a normal input B going into the adder. This is how subtraction is achieved in binary adders.
However, our subtraction output will be inverted, so we use another set of inverters to invert the output so long as we used subtraction. Providing the output number is still positive, the output will pass straight through to be decoded.
If we do subtraction and the output is a negative number, something extra has to happen. We can check if the number is negative because out subtract line will have power (We can't get a negative number from ADDING two positive numbers) and we will have a our carry bit on (because we are now working in two's compliment).
The activates two sets of sticky pistons, the first stops the signal going straight into being decoded, the second allows our output to pass through into the next stage. Note that in this next stage the output has once again been inverted, so we are now working with the original output we have from the adders.
Now lets look at how this bit works with an example. Say the answer to our equation is -8
In two's compliment that is 111000
In two's compliment you subtract from the most significant bit to get your negative answer. Here, the most significant bit is 32. Subtract the remaining true bits, 16 and 8 and we are left with: 8; and because we know we're using two's compliment it's -8. Now of course with redstone we can't just subtract these values, so we have to go about it another way.
What happens if we invert our two's compliment value:
000111
The answer is seven, one short of the actual value. This is true for any two's compliment number, the inverter result is always one short of the correct number. So what we do in the adding/subtraction machine next, now we know we are working with a negative number, and I previously stated we have inverted it, is add one to it! We can do that comfortably with adders. So we have our inverted two's compliment number going into input B in this new adder, and we have our line that is only powered if we are subtracting and there is a true carry bit going into input A of the first bit of our new adder.
Our output here is our negative number, this can feed straight into the the decoder and be put on the display. Also, we have our line that is only true if we are working with negative numbers feed straight into a set of sticky pistons on the display that reveal our negative sign, so we know the number is negative.
Simple really ;)
More like this
387143
2



Have something to say?