How to sample a signal based on a clock?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
skydivertricky
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Oct 10, 2019 7:40 am
Contact:

How to sample a signal based on a clock?

Post by skydivertricky »

So I have combinators set up so I have a counter running.
I have another clock (At different frequency) and I want to sample the counter value on this 2nd clock.
How can I do this with combinators? Is it possible?

What Im trying to do is work out if a number is increasing or decreasing over time. to do this I need to sample a signal at a given point in time so that I can compare it to the previous.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: How to sample a signal based on a clock?

Post by DaveMcW »

Multiply the counter by -1. Output this as the same signal on the opposite color wire as the counter.

Connect both wires to a decider combinator. If the value is positive, the signal is increasing. If the value is negative, the signal is decreasing.

skydivertricky
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Oct 10, 2019 7:40 am
Contact:

Re: How to sample a signal based on a clock?

Post by skydivertricky »

This works if the value changes rapidly. But Im trying to monitor accumulators. The values are pretty static, so I need to know whether its been increasing/decreasing over a period of several ticks.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to sample a signal based on a clock?

Post by eradicator »

Build two rolling-average contraptions with different time spans (i.e. 1sec and 10sec). Then compare those. If the 1sec is larger than the 10sec the value is increasing. Depending on the fluctuation strength of the signal you might be able to use the origin directly instead of the 1sec average.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Yoyobuae
Filter Inserter
Filter Inserter
Posts: 499
Joined: Fri Nov 04, 2016 11:04 pm
Contact:

Re: How to sample a signal based on a clock?

Post by Yoyobuae »

skydivertricky wrote:
Thu Oct 22, 2020 9:39 pm
This works if the value changes rapidly. But Im trying to monitor accumulators. The values are pretty static, so I need to know whether its been increasing/decreasing over a period of several ticks.
As mentioned by DaveMcW the easiest way to convert a varying signal into a signal which represents the rate of change is doing something like this:



The arithmetic combinator (and the way it is wired) calculates the difference between the value of the signal in the previous tick with the value of the signal in the current tick. If the result is positive the signal is increasing, and negative if it is decreasing. In other words it calculates the first difference of the signal (if the signal was continuous, it would be the first derivative).

Now the signal from accumulator changes rather slowly, remaining constant for many ticks before changing. In the above example I used a storage tank instead because the signal from a storage tank changes more quickly, usually once per tick (which makes it easier to demonstrate the "rate of change").

Luckily we can further process the rate of change signal of an accumulator to detect charging/discharging:





In this example I added a SR latch to hold last state of the accumulator, either charging/discharging. It doesn't tell you by how much it is charging/discharging though (or if the charge is constant).

If you actually want a more detailed signal then just "charging/discharging" then you use a filter on the output of the arithmetic combinator using a rolling average circuit to get a pretty accurate rate of change signal (the number shows the charge/discharge rate of the accumulator in kW):



Post Reply

Return to “Gameplay Help”