v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

User:SL/Logic Gates

From Dwarf Fortress Wiki
Jump to navigation Jump to search

This includes:

  • NOT, AND, OR, and XOR gates. NOR and NAND gates have single-sentence instructions, since you can build them by changing one pressure plate in an OR or AND gate, respectively.
  • Repeater (which repeatedly toggles the output signals (it has two) between ON and OFF)
  • Memory - intended for replacing one-use pressure plates with resettable versions (one SET input signal, one CLEAR input signal, one output signal)

The most useful things are the repeater and memory, in my opinion, but the others can be useful too.

Example uses for each gate

Repeater: Repeatedly toggling things between ON and OFF states (like hatches, spikes, etc)

Memory: Making resettable one-use pressure plates which are reset by a lever. When the SET input (from one of the aforementioned pressure plates) is triggered, the memory changes its output to the ON state until it receives the CLEAR (reset) signal. The pressure plate turning off does not turn off the memory's output.

NOT gate: Reversing the effect of a switch or creature-sensing pressure plate, generally linked to a memory device. You can, of course, mod the memory device to send the opposite signal instead of using a NOT gate.

AND gate: Requiring more than one condition to be true for something to occur. For instance, a system on/off switch and the output of a memory device could both be linked to an AND gate, and the AND gate's output could be linked to a repeater. The repeater would not run if the system on/off switch was OFF, or if the memory device was not outputting ON.

OR gate: You could link two 1-7 water sensors to an OR gate, and link that to a NOT gate, and link that to some floodgates or doors which act as emergency bulkheads, closing when water is detected in the area. Or, link the OR gate to bridges which raise instead (but you may crush things, and bridges are slower than doors).

XOR gate: If you wanted hallways with raising bridge bulkheads which closed if water approached but opened if water got past them, you could build a water 1-7 pressure plate on either end of the hallway, outside the bulkheads, and link them to an XOR whose output is linked to the bulkheads. When water reaches one pressure plate, the bridge bulkheads would both raise. If the water was moving so fast that it filled most of the hall before the bulkheads closed, and it then reached the second bulkhead some time later, both bulkheads would open. I'm not sure how this would actually be *useful*, though. :P

NOR gate: A NOR gate returns TRUE (ON) only if both inputs are FALSE. Instead of using the OR gate example with a NOT gate, you could use a NOR gate linked to two 1-7 water sensors, whose output goes to doors or floodgates. When the pressure plates are both waterless, the floodgates will be open. When one detects water, the floodgates close. (If you used 0-0 pressure plates with an OR, you would get an OFF signal if both plates detected water, or an ON signal otherwise (which is the same as 1-7 NAND 1-7))

NAND gate: A NAND gate returns TRUE (ON) whenever both inputs are not both TRUE (e.g. ON NAND ON is OFF, but every other combination is ON). Instead of the OR NOT or NOR example, you could link two 0-0 water sensors to a NAND gate, and link the NAND gate's output to raising bridges. 0-0 NAND 0-0 is the same as 1-7 OR 1-7. If there is no water on both pressure plates, the NAND gate will output an OFF signal. If, however, either has water, it will output an ON signal.

Bigger example of something useful

Example combination of devices to make invaders trigger repeating spikes until you disable them via a lever, and to allow you to turn the device completely off and make it not activate even if something walks over the pressure plates:

  • Devices required: Pressure plates, spikes, memory, repeater, AND gate, two levers, optional NOT gate for one of the levers.
  • System On/Off Switch: A lever, hooked to AND gate's first input. Should be ON when you want the device to work, and OFF when you want it to not work. If you want it reversed, then instead hook the lever to a NOT gate's input and hook the NOT gate's output to the AND gate's first input.
  • Invaders Fled Switch: A lever, hooked to Memory's CLEAR input. Pull (switch to ON) to make the repeater shut down, then pull again (switch to OFF) to set the lever up for the next time it has to be used.
  • Pressure plates for detecting Mobile Bad Things: Each one is hooked to memory's SET input. Place a row of these in your entrance or what have you, so that there's no way to get past them without stepping on one.
  • Memory: SET input hooked to all of the aforementioned pressure plates. CLEAR input hooked to Invaders Fled switch. Output hooked to AND gate's second input.
  • AND gate: First input hooked to System On/Off Switch. Second input hooked to Memory's output. Output hooked to Repeater's ENABLE input.
  • Repeater: ENABLE input hooked to AND gate's output. First output hooked to checkerboard black square spikes. Second input hooked to checkerboard white square spikes.
  • Checkerboard patterned spikes:
    • Black squares: All hooked to repeater's first output.
    • White squares: All hooked to repeater's second output.
  • Note: Spikes take about twice as long as hatches or doors to respond to signals. Bridges are also slow. (I haven't tried floodgates, since doors are fast)

Demonstration of one repeater hooked to both spikes and hatches, showing the speed difference etc: http://mkv25.net/dfma/movie-281-repeaterinaction

What you need to make these

These gates use water for computing, but input and output signals are mechanical in nature (linked pressure plates etc). They require power and are constructed on top of (ideally) a murky pool, (non-pressurized) dwarf-made cistern, river, stream, brook, or aquifer. Each one uses one or two pumps only, so the power requirements are small.

The ideal thing to build these on top of would be an aquifer, since it is capable of absorbing huge amounts of water while also providing huge amounts fairly rapidly. Building on a river or stream may be dangerous (maybe only if the river is entirely 7/7 despite the gates' pump) - it is possible to cause a catastrophic overflow centered on the pump which can only be ended by blocking the pump's input square with a hatch or disconnecting it from power. Damming the river MIGHT prevent an overflow, but would not stop one that is already in progress. v33g

You could theoretically replace the pump and input hatch with a hatch in a channel above the pump output square, and provide water from above. You'd have to be sure to floor over the top of the gates, though, to make sure that the pressurized water doesn't overflow, and you'd have to be careful about overflow from whereever the water drains to, too (if it fills to 7/7 it could flow up through other drain channels, or stairs, etc).

Advice for building these on pools

  • These gates slowly deplete the water source which they are connected to while pumping, if it is a finite source (e.g. a murky pool).
  • Running them on top of a a pool which is filled to 7/7 is safe.
  • Refilling a pool to 7/7 from another water source is (usually) safe.
  • Running a pump on top of a pool which is connected to a water source is, however, NOT safe.
  • If you want to build gates on murky pools or dwarf-made cisterns, the best thing to do is to provide a means of disabling all the gates remotely (lever linked to gear assemblies between the gates and power, for instance), and provide a connection to an infinite source (river, brook, aquifer, or the like) via a floodgate which is controlled by another lever. Disable your gates prior to refilling, then open the floodgate to refill, then close the floodgate to disconnect the pool from the water source, and only then re-enable the gates. The pressurization and overflow problem can (theoretically) only occur on a murky pool if something refills the pool while there is water in the logic gates (But I'm not 100% certain about that).
  • Make sure your refiller's source (pumps are sources, or a water source if it's directly connected to it without pumps) is on the same z level as the pool, or you will likely cause a castastrophic overflow even if you don't have any gates on top of it.

General advice and information on variants

Keep in mind that there IS a delay in operation with these gates due to the delay in hatch response to pressure plate signals. (Doors, by the way, respond at the same speed as hatches. Bridges are slower.)

I've built two variants of these gates, 'Faster' and 'Safer'.

Short description of both variants

  • 'Faster' is faster but can become unreliable if the pump runs out of water. In practice, the 'faster' pumps usually will run out of water in a murky pool, or in a river which is flowing from the output's side towards the drain's side (haven't tried the other way, but it might work better).
  • 'Safer' has blocked drains when sending an ON* signal, so it is safer, but generally switches from ON* to OFF* a little more slowly than 'Faster'.
  • * = For NOT, NAND, and NOR gates, swap ON and OFF in the previous sentence to get the correct meaning.

Detail

  • The 'Faster' variant does not use bridges to prevent water from draining while it is being pumped, whereas the 'Safer' variant does. This causes the 'Faster' gates to switch states faster when the 'Safer' bridges would be lowering, but if the water source is low, the gate can become unreliable. In testing, a 'Faster' NOT gate (for instance) sending an OFF signal, built on a small murky pool, periodically flips its output ON for a couple seconds. The 'safer' variant does not become unreliable unless you run almost completely out of water in the entire pool/brook/etc, but switching can be a little bit slower in one direction due to the bridges.
  • Larger murky pools, and having your input in the center instead of the edge of the pool, or in a strong river or the like (especially if you pump from the river feed end towards the river drain end, or better still, if river water enters the map from both ends of the river (Hard to tell unless you try to drain it!)), should reduce the likelihood of the 'Faster' variant becoming unreliable.

Useful note for 'Safer'

  • You can mitigate the slowdown for 'safer' variants by changing all 4-7 pressure plates to 7-7, and all 0-3 to 0-6, if you are building on a river or aquifer. If your water level is low, however, this will make the gates take longer to switch to ON*, or they may never turn on. (That will not work at all on the repeater because of the way it tests water depth at water level instead of in a pump-fed chamber)
  • * = For NOT, NAND, and NOR gates, replace ON with OFF in that sentence.

Gate Diagrams

All diagrams are top-down.

Common symbols in the diagrams

  • # is a wall.
  • @> is a pump which pumps from west to east. An @ with a v below it pumps from north to south (the only one of these is in the OR gate).
  • H is a hatch, almost always over water.
  • ^ is a pressure plate.
  • . is a channel over water.

Doors for maintenance and construction are not shown. You may replace any walls with doors (as long as DF allows it). I generally have two doors per gate.

Power sources are not shown. You will probably want to build windmills on top of these, but you can provide power in any way you see fit.

NOT gate

Faster

#######
#H@>^.#
#######

Safer

########
#H@>^B.#
########

Details

  • The H is a hatch which should be over open water. The @> is a pump which pumps from the west, to the east. The ^ is a water 0-3 pressure plate. The . is a channel, which is connected to the water source below.
  • For the safer variant, the B is a 1x1 bridge which raises to the west. It should be linked to your input signal.
  • The H is linked to your input signal.
  • The ^ is linked to your output devices.
  • You will need a windmill or the like to power the pump.

How this works

  • If the input is OFF, the hatch will be closed, water will not be pumpable, and water already on the pressure plate will and evaporate or go down the drain.
  • If the input is ON, the hatch will be open, allowing water to be pumped up. The pump pumps water fast enough to keep the pressure plate above 3 water, keeping the output signal OFF.
  • In the safer variant, the bridge will block water when the input is ON, keeping it on the pressure plate.


AND gate

Faster

########
#H@>D^.#
########

Safer

#########
#H@>D^B.#
######B##
     ###

Details

  • The H is a hatch which should be over open water. The @> is a pump which pumps from the west, to the east. The D is a door. The ^ is a water 4-7 pressure plate. The . is a channel, which is connected to the water source below.
  • The H is linked to your first input signal.
  • The D is linked to your second input signal.
  • The ^ is linked to your output devices.
  • For the safer variant, each B is a 1x1 bridge which raises west. Each one should be linked to a different input signal.
  • You will need a windmill or the like to power the pump.

How this works

  • Both inputs have to be ON to allow water to reach the pressure plate.
  • For the safer variant, if either input is OFF there will be a path through one bridge to the drain. It is only blocked when both are ON.

OR gate

Faster

     ###
     #H#
     #@#
  ####v#
  #H@>^##
  #####.#
      ###

Safer

Replace the bottom-right 3x3 area with this 5x3 area:

      ^####
      #BB.#
      #####

Details

  • Note that the safer OR gate is quite a bit slower at shutting off than the faster one, due to the added distance to the drain as well as the bridge delay.
  • The Hs are hatches which should be over open water. The @> is a pump which pumps from the west to the east, and the @v is a pump which pumps from the north to the south. The ^ is a water 4-7 pressure plate. The . is a channel, which is connected to the water source below.
  • The top H is linked to your first input signal. The bottom H is linked to your second input signal.
  • The ^ is linked to your output devices.
  • You will need a windmill or the like to power the pump.
  • For the safer variant, each B is a 1x1 bridge raising west, each of which should be linked to a different input signal.

How this works

  • If either input is ON, water will flow into the center and cover the pressure plate.
  • For the safer variant, if either input is ON the path to the drain will be blocked. Both have to be OFF for the drain to be accessible.

XOR gate

Faster

########
#H@>B###
#H@>B^.#
########

Safer

#########
#H@>B#DD##
#H@>B^BB.#
##########

Details

  • The Hs are hatches which should be over open water. The @> are pumps which pump from the west, to the east. The ^ is a water 4-7 pressure plate. Each B is a 1x1 bridge which raises west. Each . is a channel, which is connected to the water source below.
  • The top H is linked to your first input signal. The bottom H is linked to your second input signal.
  • The top (top-left if you're using 'safer') B is linked to your second input signal. The bottom (bottom-left if you're using 'safer') B is linked to your first input signal.
  • The ^ is linked to your output devices.
  • You will need a windmill or the like to power the pumps.
  • For the safer variant: The Ds are doors. For the following instructions, consider 'left' to be the leftmost in the set of two doors/bridges to the right, and consider 'right' to be the rightmost one. The left door and the right bridge should be linked to the first input, and the right door and the left bridge should be linked to the second input.

How this works

  • If no inputs are ON, the hatches are closed, and the bridges are all lowered (passable). Any water in the system will drain, and none will be pumped.
  • If one input is ON, one hatch will be open, and one bridge will be blocking. Water will flow through the non-blocking bridge, so the pressure plate will be triggered.
  • If both inputs are ON, both hatches will be open, but both bridges will be blocking. Water will not reach the pressure plate.
  • For the safer variant's drain:
  • * If no inputs are ON, both right bridges are passable and both doors are closed. Water will flow over the bridges.
  • * If the first input is ON, the left bridge will be raised (blocking), the right door will be open, and the left door will be closed. Water can not reach the drain.
  • * If the second input is ON, the right bridge will be raised (blocking), the left door will be open, and the right door will be closed. Water can not reach the drain.
  • * If both inpust are ON, both bridges will be raised (blocking), and both doors will be open. Water will flow through the open doors.

NOR gate

Identical to the OR gate, except that the pressure plate is 0-3 instead of 4-7.

NAND gate

Identical to the AND gate, except that the pressure plate is 0-3 instead of 4-7.

Repeater

  • This is two levels in size. The bottom level should be at the same level as a water source such as a murky pond.
  • X is a floodgate which allows or disallows water entering the system. @> is a pump which draws from the west and pumps to the east.
  • ~ is the water source. Ideally it should actually be a solid dirt/rock/whatever tile on the side of a pool/river/whatever before you start construction. You can install the floodgate first, and then dig your channel above, which will let the tile fill with water.
  • There is only one version of this, no 'faster' or 'safer' variants. (2 or more of these will increase the frequency(speed), however they have to be desynchronized)

Bottom level

####
#^^X~
####

Top level

######
#H@>.#
######

Details

  • The hatch (H) should be just above the leftmost (4-7) pressure plate, and should be linked to it.
  • The floodgate (X) is your ENABLE input. Hook it to something to enable or disable the system. (An ON signal enables the repeater, an OFF signal causes it to stop repeating after a short delay)
  • The left pressure plate is water 4-7, and the right pressure plate is water 0-1. The right pressure plate is ... iffy. Whether it flips regularly or not depends on how fast water enters the gate. It appears that once the repeater is turned on, it may take a minute or two for the right pressure plate to begin flipping regularly (the repeater seems to somehow slow down how fast water enters it after a minute or so of running).
  • The left pressure plate and the right pressure plate can be linked to different things that need to toggle repeatedly. The left pressure plate is very reliable. The right one is not so reliable. It will generally (if it's working) be ON while the left one is OFF, and vice versa.
  • You may optionally want to hook an additional lever to the hatch in order to open it temporarily to allow full draining in the event that you need to let dwarves into the repeater body. That would be your MAINTENANCE input.

Memory

  • The primary purpose for this is replacing one-use pressure plates with resettable versions which use this device to remember the ON signal from the pressure plate until a lever (or whatnot) is flipped to clear it.
  • This has two input signals (SET and CLEAR), and one output signal.
  • Note: If either the SET or CLEAR signals are levers, you should flip them off again after flipping them on.

Diagram

#######
#H@>^H#
#######

Details

  • The Hs are hatches which should be over open water. The @> is a pump which pumps from the west, to the east. The ^ is a water 7-7 pressure plate.
  • The left H is linked to your SET input signal. The right H is linked to your CLEAR input signal.
  • The ^ is linked to your output devices.
  • You will need a windmill or the like to power the pump.

How this works

  • When the SET signal is received (e.g. the pressure plate is stepped on, whatever), the left hatch opens, and the pump fills the right compartment with water. Our pressure plate (the output) flips to ON.
  • When the SET signal is no longer being received, the pump can no longer pump, but the compartment remains filled, so the pressure plate remains ON.
  • When the CLEAR signal is received, the right hatch opens, and the water drains. If the hatch is not open for very long, enough will still drain that our pressure is no longer at 7/7 water, so it will flip OFF.
  • If the SET signal and CLEAR signal are both ON at the same time, the output is unknown and possibly unpredictable: If the pump can hold the pressure plate tile at 7/7 despite the drain, it will be ON. If it runs out of water to pump and the tile stays below 7/7, it will be OFF. If it oscillates between 7/7 and lower values, you may (or may not, depending on the speed at which it changes) get seemingly random signals from the output.

Extra notes on the Memory device

  • If you want to avoid the simultaneous SET + CLEAR = INSANITY problem (As described in the last note in the "How this works" section), and do not mind CLEARing taking a little longer, you may use a 4-7 pressure plate instead of a 7-7 one. This should result in an ON signal whenever both SET and CLEAR are ON at the same time. Note that if you aren't having that problem (it's staying at 7/7 despite the drain), if your water source depletes over time the problem may start occuring some time in the future.
  • Sending multiple SET or CLEAR signals is harmless, which means you can hook as many pressure plates as you want up to one memory's SET input.