Jamming more signals into your signals so you can signal more while you signal

This board is to show, discuss and archive useful combinator- and logic-creations.
Smart triggering, counters and sensors, useful circuitry, switching as an art :), computers.
Please provide if possible always a blueprint of your creation.
Post Reply
User avatar
DingoPD
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Thu Jun 13, 2013 1:22 am
Contact:

Jamming more signals into your signals so you can signal more while you signal

Post by DingoPD »

I'm sure someone smarter already came up with this before, but for what it is worth, here's my take on getting more signals to do more things to be able to debug more often. I come from era where bit flag arrays stored in integers were still a thing, since then I've had a soft spot for bit manipulation.

Optional TL:DR backstory on the end ...
signal_multiplexing.jpg
signal_multiplexing.jpg (661.79 KiB) Viewed 4645 times

There are 4 signals: (A), (B), (C) and (D), they represent resource requests as trainloads, since none of these will ever go over 255, we could jam them all into single signal, then get them back out on the other side. that way we can use single signal to send requests for 4 different resources, and still know how many trainloads it'll take, so we can dispatch more than one train if need be.

The signals are 32 bit signed integer, so we can jam 4 signals that are 8 bits into single signal, and with some trickery at the end, we can have 4 - 0-255 unsigned signals on the other end, all 4 transmitted by using only single signal. Or in another words, take care of two resources on both supply and receiving ends using single signal.

Multiplexing the signals on sending end is dead easy, just take number smaller than 256 and bit-shift it right by specific number of bits, 0 for first, 8 for second, 16 for third and 24 for last, then send them out all as single signal.

De-multiplexing on the other end is just little more complicated, we start with the highest 8 bits, shift them left by 24, that gives us value of the fourth signal, we take that value, shift it right by 24 bits, and subtract the result from the main signal, that gives us first three signals without the fourth. Then we just repeat the steps shifting backwards by appropriate amount of bits to get the remaining signals.

Last bit of trickery is to convert signal (D) from signed to unsigned. If the result for signal (D) is negative, add 256, and we done.


To use the blueprint you will need Justarandomgeek's awesome Nixie Tubes, one of the mods i can't do without, thanks geek! :)

---

The next logical step would be to throw away the need for knowing how many train loads are available or requested, and use single signal as 32 flags, to track supply and requests of 16 resources at once :)

But why?:

I tend to use single large signal network for my trains that holds amount of available resources and requests for the same across the whole map, so when request comes in for load of iron ore, signal (1) increases by 1, and appropriate train station is enabled. Whichever train in the train yard, that has a load of iron ore is the closest takes off, and delivers the ore. Then it goes past nearest iron ore mine that has enough ore to fill it and refills it self, then it goes back to train yard. All this takes two signals, one is (1) and the other is (iron ore), so now I'm using two signals to manage offers and requests for single resource.

This works fine as long as you don't come up with the moronic idea where you want a factory where no more than single step in production will be done, without the results traveling by a train. This is precisely what I'm doing right now. I have few choices, i could break up the large signal network to smaller parts, but that is no fun. I like to eat my cake and keep it too. So i decided to complicate the hell out of everything, and this is the result.
Efficiency is just highly developed form of laziness.

User avatar
DingoPD
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Thu Jun 13, 2013 1:22 am
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by DingoPD »

Since i had built the multiplexer in my playground, i couldn't resist to plug in few signal generators and see how fast it can be pushed ... not very fast i found out, it works fine for my train signals, but it balks when you start pushing multiple updates per second. So after couple of alternate versions, I've got this.
Instead of bothering with calculating the individual signals and all that subtracting, and maths in general, i decided to just give the bits a nice shove right the edge and be done with them.
signal_multiplexing_2.jpg
signal_multiplexing_2.jpg (502.81 KiB) Viewed 4630 times



The way it works:

On the left are 4 pulse generators and counters, they just there so i have something to send down the wire.

Then the 4 multiplexers, all they do is take the value of the signals A to D, and shift them by 0, 8, 16 and 24 bits respectively, and output each as the signal (BLUE).

Signal goes over the green wire to the de-multiplexers.

For example, on (A) signal, which is the lowest 8 bits, i first shift 24 bits to the left, that drops all the bits but the lowest 8 right off the edge. Then it gets shifted back 24 bits to the right. That puts them right back where they were, but all the higher bits are now zeroed out. Funny enough this makes the number a signed integer. so the decider combinator, the arithmetic combinator and the constant combinator are there to turn it back into unsigned 8 bit integer.

The rest of the signals follow the same pattern, they just get shifted by different amount to the left, and 24 to the right.

Main advantage is that each signal is now calculated independently, so no more glitches, and since there is less maths, and bit shifting is cheap in terms of CPU costs, it should be easier on the CPU hamsters :)

---

In the end I've decided to use the same signal for supply and demand signaling, that means i need only two numbers per signal, that increases the available range from 0-255 to 0-65535, and i don't think I'll be managing to sit on that many trainloads of stuff for some time.
Efficiency is just highly developed form of laziness.

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by Jap2.0 »

Come on, the word signal is only used 55 times on this page!

On a more serious side note, this is cool, although I have no idea how it works (I might take a look at it eventually).
Last edited by Jap2.0 on Mon Jan 07, 2019 10:23 pm, edited 1 time in total.
There are 10 types of people: those who get this joke and those who don't.

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

Re: Jamming more signals into your signals so you can signal more while you signal

Post by DaveMcW »

DingoPD wrote:
Tue Sep 18, 2018 3:04 am
that increases the available range to 0-65535, and i don't think I'll be managing to sit on that many trainloads of stuff for some time.
Do you really need 16 bits of accuracy? You can do a lot better if you settle for 3.

A 6-bit float has decent coverage of all the interesting numbers. And you can fit 5 of them in one signal!

6 bit float.png
6 bit float.png (28.96 KiB) Viewed 4547 times

Or how about a 5-bit float. You can fit 6 of them in one signal!

5 bit float.png
5 bit float.png (14.66 KiB) Viewed 4547 times

User avatar
DingoPD
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Thu Jun 13, 2013 1:22 am
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by DingoPD »

Jap2.0 wrote:
Fri Sep 21, 2018 9:06 pm
Come one, the word signal is only used 55 times on this page!
the subject should have been a warning for ya, hehe :) I'm suprised you counted them, myself i lost count after about 4.
Jap2.0 wrote:
Fri Sep 21, 2018 9:06 pm
On a more serious side note, this is cool, although I have no idea how it works (I might take a look at it eventually).
I did notice your signature :P
Last edited by DingoPD on Mon Sep 24, 2018 9:51 pm, edited 1 time in total.
Efficiency is just highly developed form of laziness.

User avatar
DingoPD
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Thu Jun 13, 2013 1:22 am
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by DingoPD »

DaveMcW wrote:
Sat Sep 22, 2018 9:15 am
Do you really need 16 bits of accuracy? You can do a lot better if you settle for 3.
My thought behind it was i can track supply and demand with the same signal, since there is more signals than there is items in the game (with the extra signal tab), i should have enough signals to cover every item conceivable. as long as i use iron for iron, copper for copper .. etc. And that leaves the whole alpha, numerical and color range for extras.

This is just the global signal network, for local only purposes i can always recycle signals too :)

Edit: oh and i think i just realized why you were talking about floats (wikipedia lol) .. doing that in factorio is a bit over my head ... i do binary really well though, i got 1010 fingers :)
Efficiency is just highly developed form of laziness.

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by Jap2.0 »

DingoPD wrote:
Mon Sep 24, 2018 9:13 pm
Jap2.0 wrote:
Fri Sep 21, 2018 9:06 pm
Come one, the word signal is only used 55 times on this page!
the subject should have been a warning for ya, hehe :) I'm suprised you counted them, myself i lost count after about 4.
Jap2.0 wrote:
Fri Sep 21, 2018 9:06 pm
On a more serious side note, this is cool, although I have no idea how it works (I might take a look at it eventually).
I did notice your signature :P
Nah, I'm too lazy to count - I just used ctrl+f.
Also, thanks - I believe you're the first person to comment on that (which is surprising considering how much time I waste spend productively on here.
There are 10 types of people: those who get this joke and those who don't.

User avatar
DingoPD
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Thu Jun 13, 2013 1:22 am
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by DingoPD »

Jap2.0 wrote:
Mon Sep 24, 2018 10:04 pm
... I believe you're the first person to comment on that ...
That is really suprising, sometimes when i read the stuff here, i get this feeling that about half the silicon design teams from both intel and amd play factorio or troll the forums for ideas ...
Efficiency is just highly developed form of laziness.

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by Jap2.0 »

DingoPD wrote:
Tue Sep 25, 2018 3:32 pm
Jap2.0 wrote:
Mon Sep 24, 2018 10:04 pm
... I believe you're the first person to comment on that ...
That is really suprising, sometimes when i read the stuff here, i get this feeling that about half the silicon design teams from both intel and amd play factorio or troll the forums for ideas ...
Yeah, a lot of people who are into computers, technology, engineering, etc. are on here. I'm guessing that many of them have noticed but just haven't mentioned it.
There are 10 types of people: those who get this joke and those who don't.

IGotBaconSoda
Burner Inserter
Burner Inserter
Posts: 15
Joined: Thu Mar 24, 2016 7:45 pm
Contact:

Re: Jamming more signals into your signals so you can signal more while you signal

Post by IGotBaconSoda »

Hey guys,

I jumped on the logistic train wagon and needed a mux/demux for my project, and this thread inspired me.
I want to post my solution in case you still have issues with tick-delay, for suggestions as to how improve mine, and maybe to help another down the road.
(If any combinators are unclear, I can provide more details/save file)

Image

Alt-Mode
Image

Description: I tried to keep everything separated in its respective sub-units.
Left: Multiplexer; A B C D will send left bit-shifted values (on Iron Ore) over red wire. Copper and Wood are signal noise (positive and negative values resp)
Right: Filter; Pull Iron ore signal from red wire, and output to Demultiplexer
Demultiplexer; Filter relevant bit frame from Iron Ore (Bitwise AND), then right shift down to original value.
(Here, I have 3 channels on 8 bits each, for up to 255 values each over A B C; 7 bits for channel D--damn sign bit. In the end, I too settled for only 2 channels per signal, affording 4095 values with some room on the signal to spare for future projects)

Here's what I've got for tick count:
Tick 0: A = 0 -> A = 1 (Initial signal, ideally the signal of what'll be filtered--Iron Ore here--to enable Each -> Each during <<)
Tick 1: Each << x -> Iron Ore (left shift to relevant frame)
Tick 2: Each > 0 -> Each (Filter)
Tick 3: Each < 0 -> Each (Filter)
Tick 4: Each - (-2^32) -> Each (Filter Output)
Tick 5: Each AND Decimal Bit Frame -> Each
Tick 6: Each >> x -> Each (Final output, Iron Ore = 1)

My main bottleneck is the filter, and would love help on a solution to filter signals in the current build (0.16.51). (Thanks in advance!)
My main constraint is the signal must be set externally (ie via constant combinator).
Currently, it works by subtracting 2^32 from any positive incoming signal, decides which new signal is now negative, then adds the 2^32 back.

Hopefully the 0.17 release has a buff to circuits (specifically being able to compare two values on the same signal from different wires). *wink* *wink*

Signal.

Post Reply

Return to “Combinator Creations”