What's wrong with my DMux 4 way?
Asked Answered
E

2

11

It's seemingly close to working, it just is messing up at line 7 apparently?

/**
 * 4-way demultiplexor.
 * {a,b,c,d} = {in,0,0,0} if sel==00
 *             {0,in,0,0} if sel==01
 *             {0,0,in,0} if sel==10
 *             {0,0,0,in} if sel==11
 */


CHIP DMux4Way {
    IN in, sel[2];
    OUT a, b, c, d;

    PARTS:
    DMux(in = in, sel = sel[0], a = out1, b = out2);

    DMux(in = out1, sel = sel[1], a = a, b = b);
    DMux(in = out2, sel = sel[1], a = c, b = d);
}

I've implemented my DMux as follows, and I'm just using that as if it were a tree:

/**
 * Dmultiplexor.
 * {a,b} = {in,0} if sel==0
 *         {0,in} if sel==1
 */


CHIP DMux {
    IN in, sel;
    OUT a, b;

    PARTS:
    Not(in = sel, out = notsel);
    And(a = in, b = notsel, out = a);
    And(a = in, b = sel, out = b);
}
Eldridgeeldritch answered 23/1, 2013 at 19:43 Comment(3)
Which HDL are you trying to write your stuff in? It doesn't look either like VHDL or Verilog...Maure
It seems the one used in nand2tetris course: nand2tetris.orgTonneau
Wow, I wrote the exact same code as yours. It seems we both misunderstood the sel[0] and sel[1]. In [0, 1], sel[0] = 1, sel[1] = 0.Rolfe
U
14

You've got the right idea! But you've started by narrowing down sel[0] as opposed to sel[1], which corresponds to the left column.

PS: I know I'm late

Edit: Added the fixed code as per the request below. Thanks for the feedback

CHIP DMux4Way {
    IN in, sel[2];
    OUT a, b, c, d;

    PARTS:
    DMux(in = in, sel = sel[1], a = out1, b = out2);

    DMux(in = out1, sel = sel[0], a = a, b = b);
    DMux(in = out2, sel = sel[0], a = c, b = d);
}

In narrowing down what would refer to the left column in a truth table (That is, sel[1]; remember to start from the right when counting), you'd be effectively splitting the options right in the middle

Unplaced answered 10/9, 2013 at 12:54 Comment(3)
Nothing wrong with being late if nobody else has answered! You may also want to consider (partially) posting the corrected code, to make it as clear as possible.Edmea
In this particular situation you should really not post the solution. I'm not sure if you're aware, but the authors specifically request that you do not do so.Manger
@AdrianWragg: I totally agree with you, but even if somebody has answered, there is nothing wrong in answering late. Anything that adds value to the q/a is okay, whether it is late or early.Hear
L
3

Another approach which matches closer to what OP was trying to do (and part where he missed being correct):

Swap b and c in the output to different lines like below:

CHIP DMux4Way {

IN in, sel[2];
OUT a, b, c, d;

PARTS:
// Put your code here:
DMux(in=in, sel=sel[0], a=dOut1, b=dOut2);

DMux(in=dOut1, sel=sel[1], a=a, b=c);

DMux(in=dOut2, sel=sel[1], a=b, b=d);

}

You can see from the truth table that that make sense as well, given that you are narrowing down sel[0]

Lenka answered 28/5, 2019 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.