Combinators & Circuit Logic 102: Logic Gates

Combinators & Circuit Logic 102: Logic Gates

Definition

In electronics, a logic gate is an idealized or physical device implementing a Boolean function; that is, it performs a logical operation on one or more logical inputs, and produces a single logical output.

One of the uses of Logic Gates is to create memory storage through the use of an SR Latch. The other is to evaluate more complex conditionals. Lastly, Logic Gates can be used to make intelligent resource routing decisions, help factories to prioritize materials to the use for which they are most desperately needed.

Practical ExamplesIf you have enough Light Oil and Petroleum Gas tanks, you want to convert your Heavy Oil to Solid Fuel but only if you don't have enough Lubricant tanks. With this kind of logic gate, you can prioritize Lubricant over Petroleum Gas, but control storage to something other than a full tank. (e.g., keep at least 1000 of each unit before permitting Heavy Oil to be cracked, converted to solid fuel or converted to Lubricant; and then route the Heavy Oil to the best destination based on the logic desired.)

If you have enough stored Steel and enough stored Straight Rail and Curved Rail, then stop producing steel. But, if you have insufficient Rail or Steel, Steel will continue to be produced.

You could go one step further and evaluate the downstream effect of Iron Plate starvation on other Assemblers and say that if you run out of anything that requires Iron Plate, that Steel Production should shut down.

NOTE

All picture examples of the Logic Gates shown below assume the criteria being DC1 - Iron > 100, DC2 - Copper > 100, with 200 Iron (with a DC that converts this to A=1), 100 Copper (with a DC that convert this to A=2).

Other practical examples for specific Logic Gates are provided; as other scenarios occur to me, or as suggestions are made, I will incorporate that information into the guide.

References And Summary

Friday Facts #88: Combinators[www.factorio.com]

Combinators 101[forums.factorio.com] by GopherAtl.

https://www.youtube.com/watch?v=YUCa2lAwNsc

Unnecessarily complicated Logic Gate video, but still useful for the beginner.

AND


Combinators & Circuit Logic 102: Logic Gates image 15

SettingValueEvaluation{Signal Type}=2

or

{Signal Type}>1Output{Signal Type}=1Inputs Required2

Input 1Input 2Output000100010111

Assuming that your inputs are binary (true=1, false=0) and of the same signal type (Red Science Packs Signal, Green Signal, 0 Signal, etc.) then through the power of Combinators 101 and magic, a single Decision Combinator is capable of rendering an AND gate quite simply.

Connect binary inputs (red & green) to the Decision Combinator, connect either Red or Green outputs. Configure DC1 parameters as {signal type} > 1, output {signal type}=1.

If the two inputs are both 1, they will be added together and equal 2. Since both are true, 2 will be the summed input value to DC1. This will meet criteria for output of {signal type=1}

Non-binary inputsIn the event that you do not have binary inputs (e.g., timer = 30 seconds, more than 2000 heavy oil, less than 1000 batteries), you have to render these tests down to binary outputs.

Practical Applications

For example, if you want to make steel, but only if you have a surplus of iron plates (>4k iron plates) and are low on steel (<1k steel) you could configure your circuit network as follows:

DC1 accepts input from circuit network, configured "iron plates > 4000" output is "A=1"

DC2 accepts input form circuit network, configured "steel < 1000" output is "A=1"

DC3 (AND gate) accepts input from DC1 and DC2, configured as "A>1" output is "A=1"

Now, you can feed DC3 output back into the circuit network and connect your circuit network to all of your smart inserters that insert steel plates into your furnaces. Then set the smart inserters to "A>0".

When Iron Plates is over 4K and Steel is under 1K, the smart inserters in front of the your "steel" furnaces will now start inserting iron plates into the furnace to produce Steel.

Blueprint StringH4sIAAAAAAAA/8WTb2vbMBDGv0rQa6nYCekGRYV9jlCMKl26A/2bJJcE4e/ei+KNOdtKUgZ9Zc53fu7R77FMWNmglV0NsoIvWBCyrNUrB5IZ0GggCR3cM3pV

QmI8hkxDwct6kGJ7t+VHKfqJG0yg2/s118H7c0FSO9azJ1kTGJJtG44DGrmeponv2PpvvS3XmPSI5VT002mSJA3OirMrWfeYchkyvnhlZS3HSJaxgGP8bB9T

8CJaVYA1hVyUL7LvOipcVOl0IMkeGQ9jieOl0iumMir7U+zcFN+aVDwOOoy+DPsU3ICevpZsr2ymTeR2xmfDC+aCWujvkItI8GOkJ1xC/EoIu+kqav2SDP+t

tfkD2i8fV8b4wRQ/GA5BjOTpE+NxYHB0AiydMlFKMVi4ALNp0VwNsmscu9s5LnJ972p8uQ34e5Bm3kva8hNp3y9hZ6esFVa5uBy74bpsL7Eu0c3N/4TukbUF

qJt2RW/gQMH+88+h4YcEZUx+NTyAN282PNLnigUAAA==

OR


Combinators & Circuit Logic 102: Logic Gates image 37

SettingValueEvaluation{Signal Type}=1

or

{Signal Type}>0Output{Signal Type}=1Inputs Required2

Input 1Input 2Output000101011111

Assuming binary inputs, an OR gate is possible with a single Decider Combinator configured to accept signal type exceeding a value of 0. With two possible inputs, the signal type has a possible range of 0-2 just like the AND gate (described above) but instead of only firing when the signal is > 1 (requiring both inputs to be true, aka a binary value of 1) the OR gate fires when either value is true (binary 1).

Practical Example

If you want to configure your oil refineries to convert Heavy Oil to Lubricant and Crack to Light Oil, but if either Lubricant or Light Oil are full, you want to convert the Heavy Oil to solid fuel, you could set up an OR gate to facilitate.

DC1 accepts input from the circuit network, configured "Lubricant > 2400" (2500 is full for vanilla storage tanks), outputs "A=1"

DC2 accepts input from the circuit network, configured "Light Oil > 2400", outputs A=1

DC3 (OR gate) accepts input from DC1 and DC2, configured as "A>0", outputs A=1

Connect DC3 to a Small Pump, configured as A>0.

Feed this Small Pump into an assembler that converts oil to solid fuel.

Now, whenever your Lubricant is nearly full, and Light Oil is nearly full, instead of the heavy oil backing up in the storage tanks (potentially blocking the Refinery from processing crude oil and blocking other oil related production lines) it will get converted to solid fuel.

NOTE: My personal preference is to allow Lubricant to back up until you research the ability to enable Advanced Oil Processing and then Crack any surplus that threatens your refinery with stoppage. While it's not as efficient[forums.factorio.com] to crack oil as it is to render the oil down to solid fuel[forums.factorio.com] and use it for some other purpose. However, to my way of thinking, as long as you have a surplus of Coal, and an abundance of accumulators and solar panels, Oil Power Plants (Steam Engines running on Solid Fuel) is a waste and subject to increased pollution concerns.

Blueprint StringH4sIAAAAAAAA/8WT3WobMRCFX8XoWiq7Dm4DQYE+RyiLIo3TAf1V0pYYse+esbwp2W1rbN/kyoxn9szRdyQTNjZoZTeDrOALFoQsa/XKgWQGNBpIQgf3jF6V

kBiPIdNQ8LK+SrH7suMHKfqJG0yg2/9broP3p4KknljPfsiawJBs23AY0MjtNE38iW3/1dtxjUmPWI5FPx0nSdLgrDi7knWPKZch44tXVtZyiGQZCzjGT/Yx

BS+iVQVYU8hF+SL7rqPCRZWOB5LskfEwljiulX5jKqOy72KnpvjepOJh0GH0Zdin4Ab09LVke2UzbSK3Mz4bXjAX1EL/hFxEgl8j/cIa4j0h7KaLqPVLMvxD

6+4vaH98XBjjjSneGA5BjOTpE+NxYHB0AiydMlFKMVhYgblr0VwMsmscu+s5LnI99zS+XQf8HKR33gva8hNpf13Czk5ZK6xycTl2xXPZrbEu0c3Nm9GtL2pb

gLppV/QGXonuf28ODT8kKGPym+EBvHkDE8knlooFAAA=

NOT


Combinators & Circuit Logic 102: Logic Gates image 58

SettingValueEvaluation{Signal Type}=0

or

{Signal Type}<1Output{Signal Type}=1Inputs Required1

Input 1Input 2Output0n/a11n/a0

Single Input Only

The NOT gate is also known as an Inverter because it takes any binary input and inverts that input. Because of the way Combinators work, the Combinator must check for condition {Signal Type} = 0, and output {Signal Type} = 1 if true. Because of limitations in the output of the Combinator, it is not possible to configure the Combinator as {Signal Type} = 1 and output {Signal Type} = 0. (Even though this is the exact behavior derived from {Signal Type} = 0} configuration

The NOT gate is differentiated from the NOR (Negative OR) gate in Factorio by the fact that it can only accept a single input. If you connect a second input to a NOT gate it becomes a NOR.

Practical ExampleCreate a signal to send to a remote outpost indicating the need for a particular resource-- have a Train Stop that

Blueprint StringH4sIAAAAAAAA/8WTb2vbMBDGv0rQa6nYCekGRYV9jlCMKl26A/2bJJcE4e/ei+KNOdtKUgZ9Zc53fu7R77FMWNmglV0NsoIvWBCyrNUrB5IZ0GggCR3cM3pV

QmI8hkxDwct6kGJ7t+VHKfqJG0yg2/s118H7c0FSO9azJ1kTGJJtG44DGrmeponv2PpvvS3XmPSI5VT002mSJA3OirMrWfeYchkyvnhlZS3HSJaxgGP8bB9T

8CJaVYA1hVyUL7LvOipcVOl0IMkeGQ9jieOl0iumMir7U+zcFN+aVDwOOoy+DPsU3ICevpZsr2ymTeR2xmfDC+aCWujvkItI8GOkJ1xC/EoIu+kqav2SDP+t

tfkD2i8fV8b4wRQ/GA5BjOTpE+NxYHB0AiydMlFKMVi4ALNp0VwNsmscu9s5LnJ972p8uQ34e5Bm3kva8hNp3y9hZ6esFVa5uBy74bpsL7Eu0c3N/4TukbUF

qJt2RW/gQMH+88+h4YcEZUx+NTyAN282PNLnigUAAA==

NAND

SettingValueEvaluation{Signal Type}<2Output{Signal Type}=1Inputs Required2

Input 1Input 2Output001101011110

Practical ApplicationsProbably one of the most practical Logic Gates in Factorio-- if you need Iron Plates and Iron Gears to make Transport Belts (Yellow Belts) and you run out of either or both Iron Plates and Iron Gears, then you can send a signal 'up stream' to your factory or downstream to automatically adjust consumption behavior.

For example, if you run out of either, you could tell your insterters associated with Fast and Express Belt production to not activate (since they consume Iron Gears, and Iron Gears consume Iron Plates, and both Gears and more advanced Belts will increase the train on Plates and Gears, further slowing down your regular Transport Belt production.)

Blueprint StringH4sIAAAAAAAA/8WT3WrjMBCFXyXoWlpsl+wWuir0OcpiVGnSHdBfJXlpEH73ThzvsnZ/SHKTqzCZ8Zmj70gmbGzQym56WcEXLAhZ1uqVA8kMaDSQhA7uCb0q

ITEeQ6ah4GV9lWL7bcv3UrQjN5hAT/93XAfvjwVJPbKW/ZI1gSHZacO+RyO7cRz5I+s+6m25xqQHLIeiHQ+TJGlwVpxdybrDlEuf8dkrK2vZR7KMBRzjR/uY

ghfRqgJsUshF+SLbpqHCRZUOB5LsnvEwlDislf5gKoOyf8WOTfEwScV9r8PgS79LwfXo6WvJdspm2kRuZ3w2PGMuqIX+DbmIBC8D/cIa4i0hbMaTqLVLMvy/

1s07aP98nBjjhSleGA5BjOTpivE4MDg4AZZOmSilGCyswNxM0ZwMspk4NudzXOT61dP4cR7wryDNvLsF7Z9XpP19CTs7Za2wysXl2BnPZbvGukQ3Ny9Gt76o

0wLUk3ZFb+CVgv305tDwXYIyJL/p78CbN8Hepv+KBQAA

NOR


Combinators & Circuit Logic 102: Logic Gates image 83

SettingValueEvaluation{Signal Type}=0Output{Signal Type}=1Inputs Required2

Input 1Input 2Output001100010110

Negative OR; or the inversion of the OR gate. If A or B is true (which includes if both A and B are true) then return zero, otherwise return 1.

Practical ApplicationsIf you have neither Lubricant, nor Petroleum Gas, then you will want to split Heavy Oil usage between the two in order to Crack Heavy Oil down to Petroleum Gas, and convert Heavy Oil to Lubricant.

If you have neither Stone Brick, nor Steel (for the production of Concrete, or other products that require both), then you will want to activate your Steel Furnaces and Stone Furnaces to produce both in order to produce Concrete.

The advantage of gating behavior is that when stocks are above the desired threshold, the Logic Gates shut off production and thus reduce pollution. In this way, you can Logic Gate Assemblers, Refineries and Chemical Plants so that they're only active (and polluting) when the resources they produce are running low (rather than running full tilt, all the time, resulting in run-away pollution.)

Blueprint StringH4sIAAAAAAAA/8WTb2vbMBDGv0rQa6nYCekGRYV9jlCMKl26A/2bJJcE4e/ei+KNOdtKUgZ9Zc53fu7R77FMWNmglV0NsoIvWBCyrNUrB5IZ0GggCR3cM3pV

QmI8hkxDwct6kGJ7t+VHKfqJG0yg2/s118H7c0FSO9azJ1kTGJJtG44DGrmeponv2PpvvS3XmPSI5VT002mSJA3OirMrWfeYchkyvnhlZS3HSJaxgGP8bB9T

8CJaVYA1hVyUL7LvOipcVOl0IMkeGQ9jieOl0iumMir7U+zcFN+aVDwOOoy+DPsU3ICevpZsr2ymTeR2xmfDC+aCWujvkItI8GOkJ1xC/EoIu+kqav2SDP+t

tfkD2i8fV8b4wRQ/GA5BjOTpE+NxYHB0AiydMlFKMVi4ALNp0VwNsmscu9s5LnJ972p8uQ34e5Bm3kva8hNp3y9hZ6esFVa5uBy74bpsL7Eu0c3N/4TukbUF

qJt2RW/gQMH+88+h4YcEZUx+NTyAN282PNLnigUAAA==

XOR


Combinators & Circuit Logic 102: Logic Gates image 96

SettingValueEvaluation{Signal Type}=1Output{Signal Type}=1Inputs Required2

Input 1Input 2Output000101011110

Exclusive OR; Returns true only if A OR B, but not if NOT A and NOT B, and not if A and B.

Practical Applications

Any simple practical applications?

Blueprint StringH4sIAAAAAAAA/8WTb2vbMBDGv0rQa2nYCdkGRYN9jjKMJl2yA/2bdC4Nxt+9F8cds7uOZKP0lTnf+bnHv0dyaeOTNX7T6QEiISFUPQzRBNDCgUUHRdkUvmM0

lIqQOVUeSlEPj1rtP+zlSat2lA4L2On9VtoU46VgqXvRim96KOBYdtpw6tDp7TiO8l5s/9TbS4vF9kjnoh3PkyzpcFacXenhgKVSV/EYjdcDnTJbRoIg5MU+

lhRV9oZATAqVTCTdNg0XIZty/iEtvgiZesr9WukBC/XGP4tdmurrJJVPnU19pO5QUugw8tdaHIyvvIndzvh8OmIltMr+gEqqwM+en7CG+JkRNuNV1NolGflb

a/cC2i8fV8b4nykeC0B8kxyZd2b775hkAId9UOAZSOFAc/KwYribUryaeTMhb25HvjgCzF++5L5bjbx60T7dlsnfOD5HsghEv2MgH5d51GC8V96EvBy74fLt

11iX6ObmP6Nbn+VpAdpJe8Do4JHpvnq4ePiuAPUlbro7iO4J+0SA4dgFAAA=

XNOR


Combinators & Circuit Logic 102: Logic Gates image 108

Exclusive Negative OR

SettingValueEvaluationDC1 {Signal Type}=0

DC2 {Signal Type}>1

DC3 {Signal Type}>0Output{Signal Type}=1Inputs Required4 - feed the same two inputs into DC1 and DC2, then feed DC1-output and DC2-output into DC3Combinators RequiredUnlike other gates, the XNOR gate requires 3 combinators in order to create the XNOR gate itself.

Input 1Input 2Output001100010111

This requires a Double Gate. The circuit builder must set up a signal to feed into both an AND and NOR gates, then feed the output from those gates into an OR gate.

If either the AND or the NOR gate is true (output A=1) then the third OR gate would return true. It's not possible for a signal to be both AND and NOR, so the the alternative is if the inputs to the initial AND and NOR gates are A or B but not both or neither, then the final output is A=0.

Practical Example

Can anyone think of a practical use for the XNOR gate?

The picture above shows a XNOR gate that is checking for Copper Plates > 100 and Iron Plates > 100.

If Copper Plates > 100 and Iron Plates <= 100, then the light will go out.

If Copper Plates <= 100 and Iron Plates > 100, then the light will go out.

If Copper Plates and Iron Plates <= 100, or both > 100, then the light will come on.

Blueprint StringH4sIAAAAAAAA/82U8W7bIBDGXyXib5hsZ003VUzqc1STxeCSnYSBAa4aWX73XZxsmlmyJemi7q+I8PkOft99GL+wXiu7aOUALmNGSHIYnOpAMgMaDUShffcF

nco+Mh58IpF3cniR4u7dHd9KUY/cYAQ9/d9w7Z3bL6jUE6vZZzlEMFR26rBt0cjlOI78iTXH9lZcY9Q95t2iJt0mAriZpCkkJKKuBg9NDweXwxpjym3CjVNW

Dnkb6FaYoWN8f0OM3olgVQY2VUhZuSzrqqJFF1Tc3VmyT4z7Poe+rPSMMffK/ii23xSPU6mwbbXvXW7X0XctOvpasrWyiTrRac8kXF0N+P2vhJqjEOtC8tOQ

36X3r+D9J0oH4HPc8ma4rd9gyqiF/gopiwjfevqFcqw/EPNqPAtzPQfDTzkwMTvb9kOw/nGuytAcGYkyetfmigwJdL83TFYHBvtOgCVikRwP3kIBeTnZfGEW

r/CkzNkR7mVaT3p44yDW/8m7t5xYV5ezXv2ddXMu6483fufecvhX89lPnbJWWNWFueyCl/C+xLo7D+rpkwGdgRearpPuk/ghQu6jW7QP4Mx3I2EnXJgIAAA=

Applications


Combinators & Circuit Logic 102: Logic Gates image 128
Combinators & Circuit Logic 102: Logic Gates image 129

Low Resource Warning Lights

On the inner ring of the Storage Tanks, the lights light up when the stored Liquid/Gas drops below an acceptable threshold.

This is another example that would signal when water levels (possibly feeding a Steam Engine farm) drop below acceptable levels.

NOTE: When connecting lamps to the circuit network, it is not necessary to use a Decision Combinator to convert the 'analog' signal of the quantity of a particualr item to a 'binary' signal to send it to the lamp-- it is possible to configure the lamp directly to only turn on when {signal type} < {quantity}. However, for the purposes of making Blueprints, especially in more complex Combinator machines, it's a lot easier to replicate a design that includes a conversion process to binary and then operates based on the binary behavior. (It's NOT possible to do an AND or OR gate without first converting to to binary.)

Set-Reset Latcheshttp://steamcommunity.com/sharedfiles/filedetails/?id=680913381

Similar, but not exactly like a pair of NOR-gates. Behavior is unique because of the tick differential behavior (output is always one tick behind input) which results in the 'memory cell' like behavior.

Source: https://steamcommunity.com/sharedfiles/filedetails/?id=689782550					

More Factorio guilds