## Reset a Combinator Clock

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
NoriSilverrage
Fast Inserter
Posts: 158
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

### Reset a Combinator Clock

I'm doing what is probably a overly complex combinator setup for a Nuclear Reactor setup.
Basically, like many others, I want it to only insert fuel if steam is under a certain number and to only insert one fuel cell.
However, unlike other options I've seen for this, I also want them to insert a second fuel cell, if after 100s (or maybe more) the steam tanks still haven't recovered.

What I came up with works for this except for one issue, the clock/counter I have remembers its count if the on signal turns off. So if it was at tick 5000 and the steam is good, it'll be at 5000 when the steam is no longer good.
I tried a bunch of different things to try and reset the issue, but couldn't come up with a good solution. I suppose I could maybe wire the clock into the SR to do a reset there.

Basically, this is just a SR up top (the arithmetic simply divides by 1k to make the numbers more manageable), clock is in the middle, with a pulse generator on the lower left. I more or less sourced these from the Combinator 101 thread and have tweaked them a bit as needed.
BP

Lav
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

### Re: Reset a Combinator Clock

If you want a counter that resets to zero after signal disappears, you can use two conditionals before the memory cell:

First conditional: IF signal > 0 THEN A = 1
Second conditional: IF signal > 0 THEN B = 1
Memory cell (arithmetic combinator with output connected to own input): A = A * B

When signal > 0, conditionals output A = 1 and B = 1, and the memory counter effectively becomes A = A * 1 + 1. When signal disappears, memory cell instantly resets to zero.

Though there are probably better designs for this, it's just what I invented on the spot.

And I don't understand why you input another fuel cell after only 100 seconds. The only thing that's going to get you is those cells uselessly sitting in reactors for the remaining 100 seconds, and then being used even if that's no longer necessary. I prefer to always time my fuel input to used cell output, it's easier and less error-prone.

NoriSilverrage
Fast Inserter
Posts: 158
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

### Re: Reset a Combinator Clock

Lav wrote:snip
Thanks. I'll play around with this.

As for your question. I tried to do a setup that timed the fuel insert to the used fuel output, but I couldn't get it to work how i wanted. I followed this design:
https://wiki.factorio.com/Tutorial:Circ ... lear_power
and the issue I found was that all the inserters would insert a fuel every time any of the other inserters took fuel out. I didn't see a way to keep the inserter's signal separate since they required a signal from the combinators and also from the other inserter. I tried a few different things to make it work, but no dice.

How does your setup's logic usually look?

~Edit: Your counter works super well and is way smaller then the reset stuff I was attempting. Thanks. I am still curious on your setup's logic though.

Lav
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

### Re: Reset a Combinator Clock

NoriSilverrage wrote:
Lav wrote:snip
Thanks. I'll play around with this.

As for your question. I tried to do a setup that timed the fuel insert to the used fuel output, but I couldn't get it to work how i wanted. I followed this design:
https://wiki.factorio.com/Tutorial:Circ ... lear_power
and the issue I found was that all the inserters would insert a fuel every time any of the other inserters took fuel out. I didn't see a way to keep the inserter's signal separate since they required a signal from the combinators and also from the other inserter. I tried a few different things to make it work, but no dice.

How does your setup's logic usually look?
You need to count the number of extracted used cells. When this number matches or exceeds the number of reactors, send a signal to insert and reset the counter.

My setup usually looks like this:

1. Used cells accumulating memory cell -> conditional (used cells >= reactors then A = 1).
2. Conditional for each fuel cell chest (if fuel > 0 then F = 1) -> another conditional (if F = reactors then A = 1).
3. Conditional for steam (if steam < some threshold then A = 1).

All three conditions output into the same sub-network, and another three combinators are feeding from it:

4. If A = 3 then A -> feeds into own input (increasing A input to 6).
5. If A = 3 then I = 1 (insertion signal).
6. If A = 3 then reset extracted used fuel cells counter.

Combinator #4 ensures that A=3 condition is only maintained for 1 tick within that sub-network. This is why all combinators are checking for A=3, not A>=3.

For my scalable nuclear design I'm also adding another small block of combinators which track the construction of new reactors - when that happens, they imitate the signal for used fuel cell extraction (so the rest of the setup knows that those reactors are empty). But this is a separate entity and only useful if you plan for later expansion of your plant (unlike, say, simply building another one).

NoriSilverrage
Fast Inserter
Posts: 158
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

### Re: Reset a Combinator Clock

Lav wrote:
NoriSilverrage wrote:
Lav wrote:snip
Thanks. I'll play around with this.

As for your question. I tried to do a setup that timed the fuel insert to the used fuel output, but I couldn't get it to work how i wanted. I followed this design:
https://wiki.factorio.com/Tutorial:Circ ... lear_power
and the issue I found was that all the inserters would insert a fuel every time any of the other inserters took fuel out. I didn't see a way to keep the inserter's signal separate since they required a signal from the combinators and also from the other inserter. I tried a few different things to make it work, but no dice.

How does your setup's logic usually look?
You need to count the number of extracted used cells. When this number matches or exceeds the number of reactors, send a signal to insert and reset the counter.

My setup usually looks like this:

1. Used cells accumulating memory cell -> conditional (used cells >= reactors then A = 1).
2. Conditional for each fuel cell chest (if fuel > 0 then F = 1) -> another conditional (if F = reactors then A = 1).
3. Conditional for steam (if steam < some threshold then A = 1).

All three conditions output into the same sub-network, and another three combinators are feeding from it:

4. If A = 3 then A -> feeds into own input (increasing A input to 6).
5. If A = 3 then I = 1 (insertion signal).
6. If A = 3 then reset extracted used fuel cells counter.

Combinator #4 ensures that A=3 condition is only maintained for 1 tick within that sub-network. This is why all combinators are checking for A=3, not A>=3.

For my scalable nuclear design I'm also adding another small block of combinators which track the construction of new reactors - when that happens, they imitate the signal for used fuel cell extraction (so the rest of the setup knows that those reactors are empty). But this is a separate entity and only useful if you plan for later expansion of your plant (unlike, say, simply building another one).
Nifty! I should have thought about counting them on the belt. Sigh.
Thanks for the response and help!

Lav
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

### Re: Reset a Combinator Clock

NoriSilverrage wrote:Nifty! I should have thought about counting them on the belt. Sigh.
Thanks for the response and help!
It's better to connect the inserters that extract used cells from the reactors - set them to "read hand" instead of "enable/disable", and set pulse mode to ensure the inserter only sends it's contents for a single tick.

NoriSilverrage
Fast Inserter
Posts: 158
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

### Re: Reset a Combinator Clock

Ah, ok that makes sense, plus no belt delay.

Laie
Long Handed Inserter
Posts: 54
Joined: Fri Dec 25, 2020 6:18 pm
Contact:

### Re: Reset a Combinator Clock

Necro Necro -- OP probably no longer cares about an answer, but when I searched for how to reset a clock this topic came up first. So I think it's a good place to post my solution.

I am using, in order:

a) A Steam Gauge with SR Latch for hysteresis. Will emit T=1 when steam is OK.
a1) An arithmetic combinator to multiply T*12k. So the whole contraption will emit T=12,000 when Steam level is OK, or nothing if steam is low.

b) A standard clock counting on T from 1 to 12k. If steam is OK, it receives T=12k from the steam gauge, thus disabling the clock (no output a.k.a T=0). If steam pressure drops, the gauge will turn of the 12k signal and the clock will start ticking at 1.

c) Another three decider combinators: One is true if the clock is ticking (T>0), one is true if little time has passed (T<30), and the third mashes both together and emits I=1 if T is between 1 and 30.

Behaviour: When the steam pressure drops, the clock starts running and I (for inserters) will be true for the first half second of it's run time. As steam pressure goes above the upper threshold, the clock will be disabled; when it drops to the lower value, the clock will again start running, toggling another insertion.

If steam pressure never goes above the safe threshold, the reactor is working at or near capacity. In that case, the clock will simply keep ticking away and you will get another insertion when it loops past 12k cycles and starts over at 1.

If, somehow, you manage to R&S the SR latch on the steam gauge before a unit of fuel has been fully consumed, that will lead to a premature insertion. This might happen if you allow biters into the power plant, or accidentally start restructuring it at runtime, but I cannot imagine any other reason.

foamy
Filter Inserter
Posts: 379
Joined: Mon Aug 26, 2019 4:14 am
Contact:

### Re: Reset a Combinator Clock

There's really no need to check every reactor. One is enough. This means you can implement a used-cell based timing circuit that will fail-on, and so require no manual intervention to start-up (or restart after a supply interruption), and do so with exactly one combinator.

Take one output inserter. Set it to read hand contents (pulse mode). Take an input inserter for the same reactor, set it to read hand contents (pulse), stack size 1, enable if all signals are 0. Add an arithmetic combinator set to subtract used fuel cells from fresh fuel cells, outputting fresh fuel cells. Wire it input to output as a memory cell, then connect both inserters to that line.

You can then gang all the other input inserters with the same line so long as they are not set to read-hand-contents. This will synchronize all the reactors provided fuel is available, and you can also send in any other blocking signals you like (e.g. one for sufficient steam) on the same wire as long as it doesn't use the signals the memory cell does.