is my DMux4Way solution inelegant?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

is my DMux4Way solution inelegant?

Loafers
This post was updated on .
After an embarrassingly long time, I finally managed to "solve" DMux4Way, but was wondering if it could be simplified?

Here is what I currently have:
//case a
Or(a=sel[1], b=sel[0], out=or1);
Not(in=or1, out=not1);
And(a=in, b=not1, out=a);

//case b
Xor(a=sel[1], b=sel[0], out=xor1);
And(a=sel[0], b=xor1, out=and1);
And(a=in, b=and1, out=b);

//case c
And(a=sel[1], b=xor1, out=and2);
And(a=in, b=and2, out=c);

//case d
And(a=sel[1], b=sel[0], out=and3);
And(a=in, b=and3, out=d);
Initially, an attempt to incorporate DMux was made, but the 2 bit sel made it mind boggling. Is it even possible?
Reply | Threaded
Open this post in threaded view
|

Re: is my DMux4Way solution inelegant?

ybakos
Don't get too hung up on this, but yes, you should be able to come up with an implementation that uses DMux. Step away from the problem, then come back and look at the specs for the DMux and the DMux4Way. How does the DMux behave based on sel? And how does the DMux4Way behave based on its sel bits?
Reply | Threaded
Open this post in threaded view
|

Re: is my DMux4Way solution inelegant?

krakerjak
In reply to this post by Loafers
As you progress you will be implementing new gates and systems that use previously built, simpler chips. You made a dmux, there is likely a way to do dmux4way using multiple dmux's. I found it very helpful to draw it out so you can visualize what you have to code out in the hdl file
Reply | Threaded
Open this post in threaded view
|

Re: is my DMux4Way solution inelegant?

Loafers
Welp, I incorporated DMux in the implementation this time and it works, but I'm not quite sure if it was the cleanest solution possible:

Xor(a=sel[1], b=sel[0], out=xor1);
Not(in=xor1, out=not1);
And(a=true, b=sel[0], out=and1);
	
And(a=not1, b=in, out=and2);
DMux(in=and2, sel=and1, a=a, b=d);
	
And(a=xor1, b=in, out=and3);
DMux(in=and3, sel=and1, a=c, b=b);

I think I'll take ybakos advice to not get too hung up on this :)
Reply | Threaded
Open this post in threaded view
|

Re: is my DMux4Way solution inelegant?

ybakos
It feels to me like you're thinking about the if/else nature of the specification like a programmer. Instead, let the internal DMuxes do the logic for you, instead of trying to do it with your Xor, etc.
Reply | Threaded
Open this post in threaded view
|

Re: is my DMux4Way solution inelegant?

cadet1620
Administrator
In reply to this post by Loafers
Think about a railroad switching yard. There is one incoming track and 4 yard tracks. Each switch is a DMux.
    ====+=======+======
         \       \
          \       \====
           \
            ====+======
                 \
                  \====
There are 2 switch levers that control this yard, one for the leftmost switch, and one for the pair of switches on the right.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: is my DMux4Way solution inelegant?

Loafers
This post was updated on .
Got it. Was embarrassingly much simpler once I began to get out of that kind of mindset. Thanks!