# Tic - Toc - Atomic clock?

## Recommended Posts

After reading a thread about morbs and how they spawn every 1.5 cycles I started wondering how to build a proper stopwatch.

• (+) We have a clock that works x seconds, then stops for 600-x seconds(0<=x<=600), so we have a 600 second stopwatch.
• (+) We have filter/buffer gates that can measure up to 200 seconds(they can also measure0.1sec and 0.5 sec if set manually, that's important for later!)
• (-) However, you can't really measure 300 seconds, then restart, can you?

So here's what I came up with:

I'm basically using 2 filters(filter+OR+NOT) to measure separately (x) seconds and (x-1) seconds, after which filters are restarted. The idea is to have the 2 filters synchronize at the time that you want.

In the picture, the "ONI" logic-wires will become active every x*(x-1) seconds.

There's one very nasty constraint to this - logic gates have a delay between switching signals.

Spoiler

This delay is big enough that it causes problems with such a clock. In my "small clocks" there are 3 delays(1 for the filter, 1 for OR gate and 1 for NOT gate). From trying and failing, I convinced myself that those delays are around 100ms each, so if top timer resets 3 times and the bottom timer resets 4 times, the bottom timer will measure 0.3 seconds more, since it reset 1 timer more. This basically means that the difference in resets must be 1! If you pick for example 3 and 5 seconds for filters, the "3sec" filter will reset 5 times and the "5sec" filter will reset 3 times. The difference of 2 resets(0.6seconds) is bigger than 0.5 seconds and the synchronization will fail, leading to a skip in the clock, which something we definitely don't want!.However, if the filters synchronize after x and x-1 resets, the whole setup works because the delay is less than 0.3 seconds.

Long story short, I have the filter on the right set to 0.5 sec - mitigates 1 cycle of logic gate delay, so top filter "waits" that extra delay time it takes for the bottom filter to catch up. This means that the top "small clock" that has the extra 0.5sec filter needs to be set to the bigger of the 2 numbers(in the case of the picture x instead of x-1).

The easiest way to use it is to set top and bottom filters to something like 31 and 30 seconds and you will measure 930 seconds.

Spoiler

In fact you'll measure a bit more, 0.3 seconds/reset, so 930+31*0.3=939.3s

However, there are other ways to choose "x" and "x-1" so that you measure closer to 900.

Spoiler

Now let's discuss what you can do with this clock:

• This gives you an "easy" way to measure 30 seconds as 6*5(in case you're too stupid to use only 1 filter ).
• If you want 300 seconds, things get more interesting(unless you use 2 consecutive filters with 200+100 or 150+150 ).
• To split it into 2 numbers, we obviously can't use x*(x-1) (since no 2 consecutive numbers multiply to 300). However, if we're smart we can use 60 and 50, since they have a least common multiple(LCM) 300. But how did we choose 60 and 50?
1. split our number into prime factors - 300=3*10*10=3*2*5*2*5
2. Using some of those, make 2 consecutive numbers by multiplication, e.g. 5 and 3*2(6), so (5,6)
3. Multiply those 2 numbers(5,6) by all the other unused factors, in our case those are 3*2*5*2*5 (10), so we multiply 5 and 6 by 10 to obtain our final numbers (50,60)
• Note that step (2) has multiple solutions. You can also pick (2,3)*5*5*2=(100,150), or (3,4)*25=(75,100). Those are the 3 solutions I see for 300. It is enough to find 1 of them!
• OK, now imagine we want to measure 900 seconds, or better yet, 3000 seconds(I actually have a use case for the 3000 scenario - feeding dreckos every 5 cycles, so they don't starve to death and still eat relatively little). How many consecutive filters would you need for that?
• Well, it doesn't matter, since for 3000 = 3*2*2*2*5*5*5=24*25*5=> (24,25)*5 = (120,125) works! That means setting the top filter to 125 and the bottom one to 120 will get you ~3000 seconds(in fact you need to add ~0.3sec per reset, but since you only have 25 resets, that means 7.5 sec, so you will measure ~3007.5 sec)
• I'm not sure if anyone would want to measure more than this, but the theoretical maximum is 200*199=39800 seconds, which is 66.(3) cycles. Now that I'm writing this, I'm thinking it might be used for automating a volcano/geyser, given that it's active time = dormant time < 66 cycles.

So here are the Technical restrictions:

• Top filter needs to be bigger than bottom filter.
• Top filter needs to reset exactly 1 time less than the bottom filter before synchonization.
• Least common multiple needs to be the synchronization number that you are trying to measure.

All three of those points are valid when choosing x and x-1 seconds for the top and bottom filter, respectively(with sync at ~x*(x-1) seconds). However, as discussed above, there are other "smarter" ways to choose the filter settings that will yield more accurate results.

To summarize the (-)drawbacks / (+)benefits of this stopwatch:

• (-) uses 8 logic gates - I'd say that's a lot
• (-) ineffective for measuring <600 seconds - better use a filter/clock for this(or even use consecutive filters - it will cost you less materials and less space)
• (-) not all times are measurable - you can't measure 113 seconds(or 311 for that matter, as both 311 and 113 are prime, so the only other factor except the number itself is 1)
• (-) it's not 100% accurate - measuring x*(x-1) seconds will measure actually x*0.3 seconds more, because you will make x resets and the logic circuits will slow you down 0.3 seconds between each reset
• You need some math to figure out how to set it up

• (+) You can measure, though with some math, though inaccurately, times that are significantly bigger than 1 cycle, e.g. 900sec or 3000sec or more(up to 66 cycles).

Here is a short cheat sheet of typical numbers that you would want to measure:

Approximate Cycle length 1 - 15:

1. (25.24) - 608sec ( or forget this clock and use clock sensor + 3 buffers @200sec => cheaper & easier & accurate)
2. (50,48) - 1208 sec
3. (75,72) - 1808 sec
4. (100,96) - 2408 sec
5. (125,120) - 3008 sec
6. (150,144) - 3608 sec
7. (175,168) - 4208 sec
8. (200,192) - 4808 sec
9. (74,73) - 5425 sec
10. (110,108) - 5958 sec
11. (82,81) - 6669 sec
12. (85,84) - 7169 sec
13. (89,88) - 7861 sec
14. (92,91) - 8403 sec
15. (165,162) - 8928 sec

If you want a better approximation(or a bigger/smaller one) either calculate it yourself or ask in this thread, I can try to find one for you.

Here's the thread that inspired me to make this:

I'd be happy if someone has a use for this monster of a clock.

##### Share on other sites

Sometimes I swear that some of you are playing a different game than I am.

I can understand Mandarin written left handed with crayon more than this.

##### Share on other sites

Sorry, I'm right-handed

##### Share on other sites

Sometimes I swear that some of you are playing a different game than I am.

I can understand Mandarin written left handed with crayon more than this.

You are not alone

##### Share on other sites

2 hours ago, martosss said:

So here's what I came up with:

Interesting design.  It lets us use more than single day clocks.  Also, dear goodness, you made me get my sandbox active to remember how the paths for everything is labeled. XD  I do not like the AND vs. OR symbols.

Out of curiousity, how did you get the buffer to accept a 0.5s value?  I can only get it to set to 0.1 or 1s.

For those having trouble following the build, to understand the path, you need to look at the manual reset which fires up the first OR on the bottom left which turns the system OFF.

Because I was curious, I'll try to break down the logic loop.  I was ending up doing it for myself on a notepad page anyway, so might as well share.

There are two timer loops.  The FILTER on Upper and Lower loop turn turn on once every (x) or (x-1).  Upper loop is continuous, the lower loop and its manual reset are the control.  Breaking it down to only the upper loop will help you understand it if you build it in a sandbox.  The Filter runs through its timer, then turns itself back off by flowing into the OR gate, which activates the NOT gate, which flips the Filter back off.  Once the Filter's off again, the NOT gate is reversed back via the OR gate, so the filter starts running through its timer again as the NOT turns it back on.

With the Upper and Lower loops not synchronizing most of the time, only one loop will be active at any one point, so the AND gate cannot fire into the result on the far left, where all the wires are hanging into nowhere.  At some point, they synchronize, and the AND gate can fire.  The BUFFER gate on the upper loop to the upper right is there to make sure that millisecond activation failures can be caught properly.  When the AND gate fires, it resynchronizes both of the FILTER loops by activating the two OR switches, resetting everything to remove the millsecond differences so the next synchronization can be on time.

##### Share on other sites

@WanderingKid Regarding the 0.5 second filter, I actually noticed this just after using 1 second and having problems with fasle positives - you can use the slider with the mouse VERY CAREFULLY to move it to 0.1 and then a little to the right so it's 0.5. Writing the numbers with a keyboard doesn't work.

And yea, I forgot to mention what gates I use, but you can just click on the building menu("=" for logic elements) and plan a gate for building to see its type. I use 2 NOTs(triangles) and 2 ORs("cut cylinders") on the left, and 1 AND gate(the "whole cylinder") on the right.

##### Share on other sites

5 minutes ago, martosss said:

@WanderingKid Regarding the 0.5 second filter, I actually noticed this just after using 1 second and having problems with fasle positives - you can use the slider with the mouse VERY CAREFULLY to move it to 0.1 and then a little to the right so it's 0.5. Writing the numbers wit ha keyboard doesn't work.

And yea, I forgot to mention what gates I use, but you can just click on the building menu("=" for logic elements) and plan a gate for building to see its type. I use 2 NOTs(triangles) and 2 ORs("cut cylinders") on the left, and 1 AND gate(the "whole cylinder") on the right.

Oh, I can see 'em, I just always forget what means what when I look at it without having the game active.

##### Share on other sites

4 minutes ago, WanderingKid said:

Oh, I can see 'em, I just always forget what means what when I look at it without having the game active.

You can also google them - https://en.wikipedia.org/wiki/Logic_gate

##### Share on other sites

14 hours ago, martosss said:

Writing the numbers wit ha keyboard doesn't work.

I've had this problem and it annoys the heck out of me.  I can't get it to "hold" if I put anything other than 01. or 1 or higher in .....

##### Share on other sites

30 minutes ago, Denisetwin said:

I've had this problem and it annoys the heck out of me.  I can't get it to "hold" if I put anything other than 01. or 1 or higher in .....

I didn't even know it's possible to have 0.5. Just now when I played around with the logic elements for some time I randomly used the slider to get it to 1 and saw that there is a 0.5 option as well. That actually made me very happy, since using 1sec was causing sync problems - 0.5 sec works better.

##### Share on other sites

The delay for all logic gates is 1/11 of a second, I don’t know where that number comes from but I tested it and that’s what it is.

##### Share on other sites

19 hours ago, AverageHuman said:

The delay for all logic gates is 1/11 of a second, I don’t know where that number comes from but I tested it and that’s what it is.

That makes sense, @R9MX4 said in a recent discussion that it's 33ms, but it feels way slower, so I think you're right. That would explain the problems that I was having and how the 0.5sec solved it - 3 gates are 0.3s, and if 1 clock restarts twice it's 0.6 seconds and it fails.

##### Share on other sites

On 2018/8/1 at 2:32 AM, AverageHuman said:

The delay for all logic gates is 1/11 of a second, I don’t know where that number comes from but I tested it and that’s what it is.

5 hours ago, martosss said:

That makes sense, @R9MX4 said in a recent discussion that it's 33ms, but it feels way slower, so I think you're right. That would explain the problems that I was having and how the 0.5sec solved it - 3 gates are 0.3s, and if 1 clock restarts twice it's 0.6 seconds and it fails.

Did your tests are conducted on 3× speed mode?

##### Share on other sites

No, my tests use the filter/ buffer gates and many other gates that switch fast to test it ... and i pause to see what happens ... but regardless .. if i set the timer to 0.5 sec and one of the small clocks resets twice(6 logic gates wroth of delay), the filter at 0.5sec misses and the clock doesn't work properly. That means the delay from 6 logic gates is more than 0.5 sec, so I'd say 0.1sec sounds pretty plausible, more than 30ms or 60 ms

##### Share on other sites

I did a rough test in 1X speed. 27 Not Gate connected with each other to make up a circle. In 200 seconds, signal ran 90 laps. So signal takes 82 ms to move forward one gate. 82 is not an integer multiple of 33. A bit strange.

##### Share on other sites

What I did baffled me ... I had a filter gate set to some time, e.g. 0.5 sec, and during that time it sent a signal to many gates ... I wanted to see how many delays are equal to 0.5 seconds ... and I counted them ... and guess what - each run was different with the same time! So a certain time,  for example 0.5sec might produce 5 or 6 or 7  logic gate delays ... that really sucks when you're trying to make a clock! But anyways, I made it regardless That's why you need that last 0.5sec filter to get rid of noise. It's annoying though - logic is so unreliable in some cases!

##### Share on other sites

Took me quite time to came up with door compressor I wanted (long ago)

So you mentioned you can help with math for your clock, i always wanted to close off a door to farms so dupes will ONLY enter when its harvest time.

##### Share on other sites

Spoiler
2 hours ago, Scorpio King said:

Took me quite time to came up with door compressor I wanted (long ago)

So you mentioned you can help with math for your clock, i always wanted to close off a door to farms so dupes will ONLY enter when its harvest time.

Ugh, Can you explain what each door is supposed to do and what the different states are?

I don't know what you want to achieve with this setup. OK, I'll write my thought process here ... What are 1, 2 and 3 set to? Imagine 1, 2 and 3 are set to 1, 10 and 100(I want to see how they affect the doors). Also label doors A B and C from top to bottom.

So when you switch ON:

• door A will open instantly(0.2sec) and stay open for at least 10 seconds, but potentially much more. It will stay open until 10 seconds after you switch OFF and bottom Filter(2) gate is disabled.
• door B will open after 1.4 seconds and stay open for a long time, similarly to A, but will close 20 seconds after switch is OFF and the bottom Filter(2) is disabled
• between door A and B opening, the XOR will be green so the top Filter(1) will start filling up. After 1 sec it will become active and door 3 opens. However, it will be disabled 0.2 sec later because of the XOR getting 2 green inputs. That means door C will basically stay closed for now(this might change when we flip the switch to OFF).

So the setup will reach equilibrium state after 1.4 seconds(after "1"+0.4 seconds).

Then we switch OFF:

• after 10.2 seconds door A closes.
• after 20.4 seconds door B closes.
• XOR will be green for 110.4 seconds. between door A and B, we have 10.2 seconds of XOR green time in which top filter(1) will be green for 9 seconds and door C will open.

At this point I realize that you probably mean 1=1sec, 2=2sec, 3=3sec. Then in my setup you need to substitute 100 for 3 seconds, and 10 for 2 seconds. So

• after 2.2 seconds door A close
• after 7.6 seconds XOR will disable top filter(1)
• XOR will be active from 2.2 until 7.6
• Top filter(1) becomes active after 3.3 seconds and door C opens
• after 4.4 seconds door B closes
• Bottom filter(3) becomes active after 5.4 seconds
• Left buffer(2) becomes active after 7.5 seconds
• door A opens
• XOR is disabled
• Top filter is restarted
• bottom filter is disabled
• door C closes

Ugh at this point I'm lost. You said it's a pump, so I imagine it will start to repeat? This does look like a complicated pump! If I were you I'd use an atmo sensor to control the pump myself instead of this manual switch.

OK, so the pump has nothing to do with your question .. the joke's on me...

You can use the clock for harvesting! Indeed, that is one more use case.

OK, imagine you want to harvest for 1 cycle and plants grow for 6 cycles. That means you need to open the door every 7 cycles and close it 1 cycle later.

This means you need 1 "big" clock to measure 7 cycles(4200 seconds) and 3 buffers on the output that measure in total 600 seconds.

4200 = 100*6*7=7*5*5*3*2*2*2 = magic happens = (24,25)x7=(168,175).

Here is the setup:

So this will open the door for 600 seconds every ~4203 seconds. If you need, you can add more buffer gates to increase the time on the left. Also, if you need a different time than 7 cycles, you need to calculate it yourself, or tell me the open/close times that you need so I calculate it for you.

##### Share on other sites

@martosss Sweet! Ill adjust it a bit and use that. Thanks a lot.

Slime restricted shroom rooms im looking at you!

##### Share on other sites

OK, here is a cheat-sheet to get the numbers for the filters:

• for less than 9 cycles you can use (25,24)*X, where X is the cycles that you want to count. Here is a list of the filter numbers for cycles 1- 8:
1. (25.24)
2. (50,48)
3. (75,72)
4. (100,96)
5. (125,120)
6. (150,144)
7. (175,168)
8. (200,192)
• Why it works - 24 and 25 synchronize at exactly 600(1 cycle), so any multiple of those two will synchronize at a multiple of 600.
• for a number of cycles that is multiple of 5 (e.g. 15) you can use (55,54)*X/5. For example 15 cycles would be (55*54)*15/5=(55,54)*3=(165,162).
• 10 cycles - (110,108)
• 15 cycles - (165,162)
• 55,54 sync at 2970, which is ~3000 seconds(5 cycles), so any multiple of those will sync at a multiple of 2970. You can also use (56,55) if you want a bit higher(they sync at 3080)

How did I come up with those numbers? Find an approximate square root of the number of seconds and take the 2 adjacent numbers.  E.g. sqrt(3000)~54.77, so take 54 and 55 - that's the closest solution to 3000

Note that this approach only works if the two results are less than 200! So for (55,54), you can't calculate 20 cycles because you'll need filters that can count 220 and 216 seconds.

OK, added to the 1st post, I hope that encourages people to use this clock.

##### Share on other sites

I have to say, I think this stop-watch is pretty clever in design for how long it can count up too.  I'm not sure I'd ever use it, but still clever.

On a theoretical note, lets say you wanted to count even higher then it's maximum, couldn't you then combine the output of two of theses stop-watches though an AND gate?  Using the same math scheme?  Stop-watch A being X with Stop-watch B being X-1 ?

x*(x-1)=A

y*(y-1)=B

A*B=C

Even for smaller cycle counts this could be useful if you're wanting several different cycle counts.  A=2, B=5, A*B=10

##### Share on other sites

4 hours ago, The Flying Fox said:

I have to say, I think this stop-watch is pretty clever in design for how long it can count up too.  I'm not sure I'd ever use it, but still clever.

On a theoretical note, lets say you wanted to count even higher then it's maximum, couldn't you then combine the output of two of theses stop-watches though an AND gate?  Using the same math scheme?  Stop-watch A being X with Stop-watch B being X-1 ?

x*(x-1)=A

y*(y-1)=B

A*B=C

Even for smaller cycle counts this could be useful if you're wanting several different cycle counts.  A=2, B=5, A*B=10

If I understand you correctly, you want to have 2 of those huge clocks to measure 10 cycles? 1 measures 2 cycles, the other measures 5 cycles? That would mean you need 18 logic gates and one half of your base as a ticking bomb. but Why would you want to measure 10 cycles in this way if you could measure 10 cycles with only 1 clock using the proper numbers for X and X-1(110 and 108 instead of "X" and "X-1", since 110*108/2 = 10 cycles)

However, you're missing the fine print on logic gates. That would have been a possible solution in a perfect world. However, our logic gates are as reliable as a bicycle in the desert.

• Currently each logic gate has ~0.1 sec delay between receiving a signal and acting on it to change its output.
• To make things worse, Buffer and Filter gates don't have a reliable time measurement - sometimes they measure exactly 2 seconds, sometimes they measure 1.9 seconds. The meaning of this is, the number of delays for 1 second varies between 8-12(or 9-11), but it's not constant! So one time the filter/buffer will measure 9 delays, the next time it will measure 10 delays, the next time 11 ... I haven't figured the exact mechanics and I don't intend to. I can only tell you that they are unreliable for fine measurements.

As you can see from the previous posts with the cheat sheet, even with relatively "good" numbers, I still measure 1 cycle with 2-3 seconds delay. Now imagine you're trying to measure 2 cycles on 1 unreliable clock and 5 cycles on another unreliable clock and pass them to an AND gate ... how much time will you wait in order to make sure everything still works and the clock doesn't de-sync or sync sooner? As you can see I have that buffer set to 0.5 seconds on the right side of my setup - this is exactly to make sure that those nasty delays don't break the sync between the small clocks. A simple "AND" gate between 2 of those clocks will cause the following:

clock A measures 2.001 cycles and turns green, clock B measures 5.001 cycles and turns green => they sync after 3335,667 cycles(from this LCM calculator), when your dupes have long-since magmafied. As you can see, a small difference in the measurement can cause a huge difference in the sync time. Of course this can be fixed - you add another buffer before the AND gate for one of the clocks and wait a few seconds. You need to calculate how long you need to wait! This depends on the delay for each reset. Moreover, if clock A resets 2 times and clock B resets 5 times(as will happen in your case) you need to wait 3 "reset delays" in the end with the A clock, so that the B clock will catch up. This is the reason I choose x and x-1(25 , 24 or 82 , 81) instead of just co-prime numbers(e.g. 3 , 7 or 2 , 5).

BTW This is the reason that my clock uses 3+3+2 gates instead of 2+2+1 - I could have removed the OR gates and the right Buffer that are used for reseting the clock and fixing delays if everything was working perfectly accurately ... but it doesn't, so I need them. And that's the reason this clock is relatively inaccurate.

Anyways, up to now I can see this being useful for farms and ranches, since you need to wait a long time for egg hatching and plant growing/harvesting. There you don't need exact times and something like 10 seconds delay isn't important, so it doesn't matter if you're measuring 10 cycles or 10 cycles±20 seconds. Thus I think that clock can be useful. However, if you want to measure exactly 10 cycles(6000 seconds ±0.1 sec accuracy) with this setup you'll have troubles. I'd suggest you scroll up, open the Morb thread and use the other version of a clock that is posted there - it uses a clock sensor that activates every cycles and "remembers" how many times the clock activates.

##### Share on other sites

2 minutes ago, martosss said:

If I understand you correctly, you want to have 2 of those huge clocks to measure 10 cycles? 1 measures 2 cycles, the other measures 5 cycles? That would mean you need 18 logic gates and one half of your base as a ticking bomb. but Why would you want to measure 10 cycles in this way if you could measure 10 cycles with only 1 clock using the proper numbers for X and X-1(110 and 108 instead of "X" and "X-1", since 110*108/2 = 10 cycles)

...

Oh, it was merely an theoretical example to the theoretical question.  The actual numbers weren't important.  I was just thinking someone could have a need for separate cycle counts in their base.  By having two differently set clocks you can have two cycle times, but then have a third by using an AND gate to multiply them together to get a third.  But, I can understand that the logic gate delay would make getting them to go off together at the same time (At the right time) would be all but impossible after long periods of the two clocks not syncing together.

PS.  I found that increasing the UI scale temporary can make it easier to set the Filter/Buffer gate to setting between 0.1 and 1, although it's still not easy to do so.

##### Share on other sites

18 minutes ago, The Flying Fox said:

Oh, it was merely an theoretical example to the theoretical question.  The actual numbers weren't important.  I was just thinking someone could have a need for separate cycle counts in their base.  By having two differently set clocks you can have two cycle times, but then have a third by using an AND gate to multiply them together to get a third.  But, I can understand that the logic gate delay would make getting them to go off together at the same time (At the right time) would be all but impossible after long periods of the two clocks not syncing together.

PS.  I found that increasing the UI scale temporary can make it easier to set the Filter/Buffer gate to setting between 0.1 and 1, although it's still not easy to do so.

Well, to be honest, if you know what you're doing, it's not that hard. But then again, if you know what you're doing you will just find a smarter way of doing it instead of using 2 of those monsters. I consider this to be the "heavi-watt" of clocks - you use only 1 of it and only when you don't have other options.

You are right, since this clock measures up to 39800 seconds, in theory using 2 clocks will let you measure ~39800²(one measures 200,199=39800, another measures 198*197 = 39006, then they work until they sync together, measuring ~0.8billion seconds). Fun!

And that's an interesting find about the UI scaling, although I honestly don't plan to abuse it(and can't think of a way to abuse it either). Currently the logic gates are unreliable as they are, so it wouldn't matter much if I can measure 4 seconds or 4.3 seconds. Having 0.1, 0.5 and 1 is pretty much enough for most practical needs.

##### Share on other sites

This is more intuitive

and it`s easier.