Binary counter clock for complex signal patterns

    Joined
    Jun 16, 2015
    Messages
    26
    Reaction score
    4
    I made a binary counter clock so you can make complex signaling patterns. Small space, simple to expand.

     

    Olxinos

    French fry. Caution: very salty!
    Joined
    May 7, 2015
    Messages
    151
    Reaction score
    88
    You don't need the And gates to increment your counter (actually, you don't need the not gates either to increment it, but you'll probably need those anyway to compute the signals for your lights):
    - first solution: simply adapt your logic to use the 2 complement of N (ie -(N+1)[2^B]) instead of N, and simply make a chain of flip-flops (so you decrement your counter, but since you use -(N+1) instead of N, it's as if you incremented it)
    - second solution: send the incrementing signal to all flip-flops in a chain, that works (it's like computing N-(2^b-1) modulo 2^b which is exactly the same thing as computing N+1 modulo 2^b)

    I'm nitpicking but i like to optimize circuits :p
    Also the second solution can be used to reverse your animation easily (simply redirect the signal on all flip-flop if you want to go forward, or on the first flip-flop if you want to go backwards)

    [...]
    Practical example: two way counter

    You probably already know about this thing:
    View attachment 12827
    This is basically a counter, a decreasing counter actually, the current state can be seen as the binary number 111 (7 in decimal) and if i press the button i get:
    View attachment 12828
    110 (6 in decimal)
    once again:
    View attachment 12829
    101 (5 in decimal)
    That's great, but what if i want an increasing counter?
    Well actually if i say that on=0 and off=1 instead of on=1 and off=0, i get 000 then 001 then 010, so it can also be seen as an increasing counter.
    Okay, but if i want two buttons, an increase AND a decrease one? Now this is less trivial.
    Actually there is a really simple solution:
    View attachment 12830
    just press that new button and...
    View attachment 12831
    Nice! But why does it work?

    Well remember how sending a signal to the rightmost block can be seen as decrementing the counter? Actually sending a signal the middle block can also be seen as decrementing the counter but by 10 (binary) instead of 1, and sending a signal to the leftmost can be seen as decrementing the counter by 100.
    So what we're really doing here is decrementing the counter by 111 (7 in decimal) and obviously:
    5 - 7 = 6
    Wait, let me correct that:
    5 - 76 [8]
    Remember that our little counter can only store numbers from 0 (000) to 7 (111), if you try to get a number outside of these bounds, the counter just wraps around (by adding or substracting 8 until you have a valid number if you want, in french we say that "5-7" and "6" are "congrus modulo 8", i don't know how it's called in english).
    In general if you have N Flip-flop you make computations modulo 2^N and sending a signal to each Flip-flop can be seen as decrementing by (2^N - 1), here N=3 so 2^3=8 and 2^3-1=7.
    [...]

    (Edit: also, chained and-gates can be converted in a single and-gate, but i understand if it's for clarity)
     
    Joined
    Jun 16, 2015
    Messages
    26
    Reaction score
    4
    Yes I'm reviving this as I was thinking of posting the updated version. Been out of starmade for a while.
    This version was extended to make it easier to read. If your not familiar iwth binary AND your not familiar with circuits its a lot to take in. I have a version of this which is much more efficient and counts to a high number and is 3 layers deep. You cant really see whats going on.

    I lost the file for it but now I'm on a new server I'm gonna rebuild the efficient version and post it here