Page 1 of 1

[13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Fri Jul 22, 2016 5:08 pm
by Tinyboss
Now that 13.9 fixed the problem with disabled belts not stopping items properly, we can use wired belts to make a very simple, cheap, and reliable hysteresis loop that is compact and requires no power.

For those who don't know, a hysteresis loop is used to switch something on and off based on an input signal, while avoiding very quick on-off switching. For example, you might want to turn on iron smelting when there are fewer than 40k iron plates, and leave it on until there are more than 60k plates.

Here's the hysteresis loop. The signal (in this case iron) comes in from the left, and the power switch on the right turns on when the input level goes below the lower threshold, then stays on until the input level goes above the upper threshold:

Image

When iron drops below 40, the power turns on and stays on until iron is above 60, then it turns off.

Edit: I realized there's a flaw with this, since if the input signal goes very briefly above the upper threshold and then falls back below (which is probably not at all uncommon in a typical setup), the alien artifact can get stuck on the upper left belt. Luckily there's a simple fix: put three artifacts (or whatever you use) on the belt, all on the inside lane, like this:

Image

This ensures that power can't get switched off until the first artifact has cleared the top-left belt, and is available to re-trigger the sensor when needed.

My attempt at proving it is reliable (I'm new to this so it's very possible that I'm making some bad assumptions):
  • It cannot get stuck with the output on and the input signal over the high threshold, because in that case only the lower-right belt is stopped, and any artifacts on the sensor belt (top-right) must move off.
  • It cannot get stuck with output off and input below the low threshold, because in that case only the top-left belt is stopped. Since all three artifacts can't fit on the stopped belt, at least one must circulate around to the sensor belt, and remain there (since the input signal is high).
  • If the input is between low and high, then both top-left and bottom-right belts are stopped, so no artifacts can move onto or off of the sensor belt, which means the output state can't change.

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Sun Jul 24, 2016 2:25 am
by siggboy
This is beautiful. I'm surprised that nobody has answered yet (probably all on vacation).

What you've built is the equivalent of a Schmitt Trigger, without combinators. Goes to 1 above threshold, goes to 0 below threshold, retains value in between -- exactly like a Schmitt Trigger.

It can also be used as a toggle/latch, even if one does not need the feedback behaviour. It can even simply be changed to pulse the toggle event instead of holding it.

It's so good for controlling power supplies with accumulators, because it doesn't use power itself, so one does not need to worry about that aspect.
Edit: I realized there's a flaw with this, since if the input signal goes very briefly above the upper threshold and then falls back below (which is probably not at all uncommon in a typical setup), the alien artifact can get stuck on the upper left belt.
I've tested with single tick inputs, and they're definitely too short to allow the item to move. So the trigger signal needs to be longer than that. XKnight could probably say right away what the necessary tick length is, because he's probably already tested this aspect :).

Edit: OK, so I've tested it. If you use Express Belts for the contraption, and put three items into it (as advised), then the trigger signal needs to be at least 4 ticks long for it to reliably switch states. With 3 ticks it sometimes works, with 2 ticks it always fails. If you use slower belts you need even longer signals.

So using express (blue) belt is necessary for best performance.

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Wed Jul 27, 2016 4:40 am
by MatthewGP
I just wanted to say thank you. This is an awesome little thing that got rid of a bunch of pain in the butt stuff. Cheers!

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Wed Jul 27, 2016 8:16 am
by vanatteveldt
Nice idea to do this with belts since it doesn't consume power.

I did something similar in 12.x with two inserters to/from a chest connected via an underground belt, reading the chest content as trigger and inserting out if signal > MAX, and inserting into the chest if signal < MIN:

viewtopic.php?f=8&t=24938
screenshot

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Mon Sep 19, 2016 5:18 pm
by Mendel
Thanks! This works great for controlling steam engines

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Thu Apr 27, 2017 2:36 pm
by Cazadore
i just want to chip in that the picture links are broken/defunct.

if anybody has a mirror or screenshots that would be much appreciated. i need those to build the latch system.

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Thu Apr 27, 2017 2:51 pm
by Tinyboss
Hey Cazadore, thanks for the heads up. Dropbox made it so free users can no longer host images. I moved them to imgur.

But now that alien artifacts are gone in versin 0.15, my design is no longer viable. ;-)

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Thu Apr 27, 2017 3:53 pm
by Cazadore
well, i just use bricks as sentilens then.

but anyway, thank you very much for the new links. much appreciated.

Re: [13.9+] Cheap no-power hysteresis in 4x4 space using belts

Posted: Sun Mar 26, 2023 8:16 am
by Qilili
siggboy wrote: Sun Jul 24, 2016 2:25 am If you use Express Belts for the contraption, and put three items into it (as advised), then the trigger signal needs to be at least 4 ticks long for it to reliably switch states. With 3 ticks it sometimes works, with 2 ticks it always fails. If you use slower belts you need even longer signals.
So using express (blue) belt is necessary for best performance.

Necroposting it for simple fix for this from your reddit post:

https://www.reddit.com/r/factorio/comme ... &context=3
Instead of putting three items on the belt, could you not just set the top left (>60 one) to also read belt contents. Then if production momentarily goes above 60 and the item stops on that belt the machine will still be enabled