Timer / Timed Trigger / Pulse / Threshold recognition
Posted: Sun Sep 11, 2016 8:26 pm
With the new changes to circuit network an interesting performance tweak was introduced. The state of the network is only calculated, when a value changes.
This behavior will enable circuits, that was unthinkable before.
But what, if you have signals, that change every tick? A time-signal (adding 1 every tick) for example? Or using values from logistic network, that can change also every tick. For that case the amount of CPU usage is the same as before.
So there is a simple solution:
Reduce the number of changes to the circuit network.
This device is a bit complex, cause it enables different functionality, but in general it works like so:
There are three parts: Intervals, triggers and switch. A trigger is checked each interval. If it triggers, the switch switches the input signals through to the output.
I did some rework below, since yesterday. In general I added intervals to the second and third trigger. And I renamed operation to switch.
1. Triggers:
Intervall: Some (slider-like) control that let's choose how many ticks between two checks will pass by. It can be switched between ticks and seconds. Zero turns the interval off.
It displays also the frequency of the trigger in Herz.
An extended (normally hidden) functionality of the intervall is the shift. With this you control the synchronicity of the intervalls. You need to know that the intervall is triggered by a modulo-operation: game-time module X ticks. If that is equal to the shift-value, the intervall triggers.
By default the shift is a random value. But if you set the interval of two timer-devices to the same shift (and frequency, or multiples of the frequency of other intervalls of course) you can synchronize the changes, which might become very important for some cases.
The implementation of the timers allow to precalculate the next interval! This means the device can be turned off in the meantime, cause nothing changes without interval.
Thresholder: What input signal needs to change how much, before the switch will be triggered. This consists of four elements:
- An interval, which works exactly as above.
- The item you want to watch for
- The threshold: Just an a value, which represents the amount that the input signal must change, before it triggers the switch. A negative threshold-value will trigger only, if the signal is within the threshold.
- A switch: Integer, % of input value.
- A switch: input to buffer when triggered, input to buffer each interval
This uses any input signal and checks each interval-time, if the input signal and buffered signal and differs too much and will trigger the switch if the input signal changes more than the defined threshold of the previous buffered value.
By default the buffer (compare-value) will be overwritten only, if the switch is triggered. But it can be copied also each interval (the last switch). In that case this element will trigger the switch only, if there is a sudden change on the input signal.
The current buffer value is always shown somewhere.
Comperator: The comperator constists of two elements:
- An intervall, which works exactly as above.
- Input signal comparison - as known in inserters etc.
This element compares the chosen input signal every X ticks and triggers switch if condition goes from false to true.
You can use all elements at the same time.
2. Switch
The switch is simple: Every time the above explained is triggered the input signal is "switched through" to the output.
There are two switch-operation modes:
- Triggered: The input signals are copied to the output signal for one tick. At any other time there is no output signal at all.
- Hold: When triggered it copies all input signals into an buffer and outputs that signals until the next trigger.
- Triggered has a hidden value "Hold-time", which is by default 1 tick. If you change it, the output holds the signal longer.
Examples
Simple timer:
Constant combinator as input signal to the trigger. Interval to some value. Switch-operation to "triggered". Will output the input ever X ticks.
Blinking lights:
You want to make warning lights for the train crossing (two lamps continuously flash). Constant combinator, interval, switch-operation to triggered.
Now set the trigger-holding-time to 50% of the intervall. This outputs the signal for lamp one. Lamp two is the negation of this signal (simple combinator logic).
There are many, many more use cases for this, but I'm now too lazy to explain all.
This behavior will enable circuits, that was unthinkable before.
But what, if you have signals, that change every tick? A time-signal (adding 1 every tick) for example? Or using values from logistic network, that can change also every tick. For that case the amount of CPU usage is the same as before.
So there is a simple solution:
Reduce the number of changes to the circuit network.
This device is a bit complex, cause it enables different functionality, but in general it works like so:
Code: Select all
interval
every X tick
|
v
triggers
|
input signals v input signals
====================> switch ==================>
There are three parts: Intervals, triggers and switch. A trigger is checked each interval. If it triggers, the switch switches the input signals through to the output.
I did some rework below, since yesterday. In general I added intervals to the second and third trigger. And I renamed operation to switch.
1. Triggers:
Intervall: Some (slider-like) control that let's choose how many ticks between two checks will pass by. It can be switched between ticks and seconds. Zero turns the interval off.
It displays also the frequency of the trigger in Herz.
An extended (normally hidden) functionality of the intervall is the shift. With this you control the synchronicity of the intervalls. You need to know that the intervall is triggered by a modulo-operation: game-time module X ticks. If that is equal to the shift-value, the intervall triggers.
By default the shift is a random value. But if you set the interval of two timer-devices to the same shift (and frequency, or multiples of the frequency of other intervalls of course) you can synchronize the changes, which might become very important for some cases.
The implementation of the timers allow to precalculate the next interval! This means the device can be turned off in the meantime, cause nothing changes without interval.
Thresholder: What input signal needs to change how much, before the switch will be triggered. This consists of four elements:
- An interval, which works exactly as above.
- The item you want to watch for
- The threshold: Just an a value, which represents the amount that the input signal must change, before it triggers the switch. A negative threshold-value will trigger only, if the signal is within the threshold.
- A switch: Integer, % of input value.
- A switch: input to buffer when triggered, input to buffer each interval
This uses any input signal and checks each interval-time, if the input signal and buffered signal and differs too much and will trigger the switch if the input signal changes more than the defined threshold of the previous buffered value.
By default the buffer (compare-value) will be overwritten only, if the switch is triggered. But it can be copied also each interval (the last switch). In that case this element will trigger the switch only, if there is a sudden change on the input signal.
The current buffer value is always shown somewhere.
Comperator: The comperator constists of two elements:
- An intervall, which works exactly as above.
- Input signal comparison - as known in inserters etc.
This element compares the chosen input signal every X ticks and triggers switch if condition goes from false to true.
You can use all elements at the same time.
2. Switch
The switch is simple: Every time the above explained is triggered the input signal is "switched through" to the output.
There are two switch-operation modes:
- Triggered: The input signals are copied to the output signal for one tick. At any other time there is no output signal at all.
- Hold: When triggered it copies all input signals into an buffer and outputs that signals until the next trigger.
- Triggered has a hidden value "Hold-time", which is by default 1 tick. If you change it, the output holds the signal longer.
Examples
Simple timer:
Constant combinator as input signal to the trigger. Interval to some value. Switch-operation to "triggered". Will output the input ever X ticks.
Blinking lights:
You want to make warning lights for the train crossing (two lamps continuously flash). Constant combinator, interval, switch-operation to triggered.
Now set the trigger-holding-time to 50% of the intervall. This outputs the signal for lamp one. Lamp two is the negation of this signal (simple combinator logic).
There are many, many more use cases for this, but I'm now too lazy to explain all.