PC [Updated] Finally a working logic gate based 4 bit full adder

Atledbet_11

Official Terrarian
Before I get started, I would like to thank NiraExecuto for their thread on how terraria's code treats wires, logic gates, etc.

I Created a youtube video demonstrating the 4 bit full adder I created, but it was put together kind-of abruptly and is a little lower quality than i would like it to be because my computer randomly started blue screening all of a sudden while I was recording.


So, now I will go over the Diagrams etc.

To begin I will Show you the old, Broken, Full adder.
Whenever C-in + A + B are on, you get output O + C-out. Which is correct for a full adder.
But if C-in + A + B are on and you deactivate either A or B, The or-gate gets the "smoke/steam error"
This steam error causes the C-out to be powered when it is not supposed to be powered. If the output
is on and runs into the C-in for the next bit then the addition will not be correct.

35086b760e7100f1.jpg


Now to look at how the "steam error" in this adder occurs.
If you read NiraExecuto's thread, you will understand why it occurs.

633959a8d662f024.jpg


So here we have a picture of the wiring in the original 1bit Full Adder.
As you can see, the Or-gate has two inputs, both being the and-gates.

So the error here occurs at the timing of the outputs for the and-gates.
The one at the bottom gets both of its inputs from the A/B switches, however the and-gate at the top gets one of its inputs directly from the C-in Switch and the other from the output of an xor-gate. Since one of the top and-gate's inputs come from a logic gate, the and gate is technically-according to the game code for wiring-slower than the other and gate by one "tick".
And therefore when the output for the bottom and gate toggles, it gets to the or gate earlier. So when the top and gate is outputting, and the bottom and-gate is not, it takes longer for the top and-gate to turn on than the bottom and-gate takes to turn off. So when you deactivate A/B the or-gate is on, then it turns off, and turns back on all in one iteration of the circuit. And according to the game code when it detects a gate turning on multiple times in one iteration it will switch off and emit steam from the gate.

So... now how to fix that :>
The way you fix it is to get the and gate outputs to reach the or gate a the same time without considering the wire color based timing, so all you have to do is delay the bottom and-gate by one extra logic gate worth of delay. The way you do this without changing the value of the wire is by adding an or-gate with only one input. Then you run the output of the and-gate to the single input of the or-gate, and the output of the or-gate to the original or-gate.

So here is an example of the fix.

2d6a0744efc737bf.jpg


This new or-gate Delays the output of the bottom and-gate so that it reaches the original or-gate at the same time as the top and-gate. And as I demonstrated in the youtube video, this solution works. :>

Yet again Thanks NiraExecuto.
Also thanks to ZeroGravitas, it was your video that led me to the [T-MEC] forums. I then decided to like the page and signed up for alerts on it. The first [T-MEC] alert I received was Nira's, so technically I would not have completed it without ZeroGravitas, the [T-MEC] community, and NiraExecuto.

I will Try to keep check on this Thread in case any of you leave replies or questions, but I graduate tomorrow so I may not see them if you post tomorrow (May 27, 2016).
And by the way, if anyone was wondering, this is my first forum post. :>
 
Last edited:
A nice full adder -- I honestly thought it would have taken up more space. The wiring is nice and simple, too! Nicely done all around. I do kind of wonder if there's any smaller versions out there, though...

Also, congrats on the graduation! Go forth and do great things.
 
A nice full adder -- I honestly thought it would have taken up more space. The wiring is nice and simple, too! Nicely done all around. I do kind of wonder if there's any smaller versions out there, though...

Also, congrats on the graduation! Go forth and do great things.
Thank you, and I would love to see some smaller adders than the one I managed to make :>
 
I am looking at how this is wired and I am able to see how to reduce the horizontal width by 2 blocks, but that's about as small as I can see it getting.
Well, even if it's only 2 tiles smaller, building an 8bit or larger version would end up saving a full adder worth of space.
 
So, for your first design, you copied the litteral gate layout of real world full adders:
full-adder1.jpg

But the OR gate broke due to receiving input from different layers of gates, as explained in:
NiraExecuto's thread
Order of Operations, Smoke and how to prevent it.

I would love to see some smaller adders
Well, it feel like cheating, since it uses the super-handy FLLFF (faulty logic lamp flip-flops), but I (almost accidentally) made a binary adding machine that uses just one gate per bit (in each of 2 registers). I posted it only onto my thread comparing two types of flip-flop implementation with Terraria gates. I'm not sure if it has any particular drawbacks, verses using your full gate based adders, but seems able to immediately add a binary number stored in a row of FLLFF to a second (accumulator) row of FLLFF. So 1/6th the number of gates, effectively (?). Here it is doing a subtraction, which is just addition to a binary number that has been inverted (compliment form):
It's setup like my old hoiktronic ALU was, except that the ripple-through seems to happen instantaneously (and uses a fraction of the space). A fair bit of an upgrade in mechanics capabilities! (Note, the middle rows of gates are a shift-right-1-place function and a reset function. Also, I originally had the wrong Gif uploaded, that didn't show arithmetic, so thanks for spurring me to check it!)

this is my first forum post
Great first post and thanks for coming along. :) I hope you have a fun graduation!
 
So, for your first design, you copied the litteral gate layout of real world full adders:
full-adder1.jpg

But the OR gate broke due to receiving input from different layers of gates, as explained in:

Order of Operations, Smoke and how to prevent it.


Well, it feel like cheating, since it uses the super-handy FLLFF (faulty logic lamp flip-flops), but I (almost accidentally) made a binary adding machine that uses just one gate per bit (in each of 2 registers). I posted it only onto my thread comparing two types of flip-flop implementation with Terraria gates. I'm not sure if it has any particular drawbacks, verses using your full gate based adders, but seems able to immediately add a binary number stored in a row of FLLFF to a second (accumulator) row of FLLFF. So 1/6th the number of gates, effectively (?). Here it is doing a subtraction, which is just addition to a binary number that has been inverted (compliment form):
It's setup like my old hoiktronic ALU was, except that the ripple-through seems to happen instantaneously (and uses a fraction of the space). A fair bit of an upgrade in mechanics capabilities! (Note, the middle rows of gates are a shift-right-1-place function and a reset function. Also, I originally had the wrong Gif uploaded, that didn't show arithmetic, so thanks for spurring me to check it!)


Great first post and thanks for coming along. :) I hope you have a fun graduation!
Thank you for the reply, and I plan to look into how your adding machine works, because it looks pretty cool. But time to go to graduation practice for now.
 
Does this deisgn work when mutiple are chained together, and the outputs are turned on at the exact same time? Try turning all A inputs on at the same time, and then when they are still on, turn on all the B inputs at the same time as well. If it doesn't smoke then I am very impressed :)
 
Does this deisgn work when mutiple are chained together, and the outputs are turned on at the exact same time? Try turning all A inputs on at the same time, and then when they are still on, turn on all the B inputs at the same time as well. If it doesn't smoke then I am very impressed :)

This design has the same issue and as such isn't really usable in a larger system. The solution I posted on your thread is the same design as what the OP posted here, I just built top down as opposed to left-right. For simplicity here is the final 4-bit full-adder that can handle simultaneous input of all bits:

CbmhvQ8.png


This thread shows how we reached this build and why the additional relays are necessary.
 
I know its been two years xD, but after testing alot of adders including Crawlr's here I found that in cases like 5 + 7 where the inputs all happen simultaneously with one switch, one of the xor's will smoke.

The math makes it pretty clear that this is due to the ripple carry effect of this adder style. So the solution is to build a CLA Adder, where each Cary Bit is calculated at the same delay. This allows you to compensate the carry delay by adding delay to the output of A xor B equal to that of the overall carry delay.

I dont currently have a working example of this, but I do plan to work on this tonight. If anyone else wants to have a go at it, just start with the carry logic necessary for the 4 bit adder xD
[doublepost=1524640779,1524584781][/doublepost]okay, so after building and testing, i have a design that works with many different operations. I already have the ability to do A+B, A-B, A+1, A-1. The circuit is basically just a CLA adder with the propper timing delays so that each operation takes the same ammount of time, around maybe like 5-6 gates of delay. I dont remember atm tbh lol. But each of these operations workwith simultaneous imputs.

I will upload a video tomorrow entailing how everything works, and post it to this thread for those who are interested

https://imgur.com/JDSOEbx
JDSOEbx

https://imgur.com/qlCjja1
qlCjja1

[doublepost=1524795581][/doublepost]Okay, so after fixing a minor flaw in my wiring with the design, i have finished my logic gate based CLA Full adder using the logic gates xD
I plan to design a decoder for the op codes so that the design will be more fluid and then i will compact the entire design. Feel free to replicate my design and try to break it lol.


let me know if you have any questions xD
[doublepost=1524931969][/doublepost]also all of my binary is backwards, rip brain
 
Back
Top Bottom