Internal pin to bus

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

Internal pin to bus

pouzzler
In order to construct the ALU, one needs (or at least that's how I did it), to AND (NOT(zx), x).
However x is a 16-bit bus, while zx is a one-bit signal.
I tried a lot of different ways to place [0..15] indexes, nothing worked.

Did I miss something, or was there absolutely no other way than creating a OneTo16 chip... or writing the indexes one by one in each and every such connection?

I chose the first solution which is incredibly ugly, being hacked with two nots, and the second solution would make someone mad after two chips. What did I miss?

Apart from this little quip, this is exactly like my Architecture 101 course,... except the final PC will work, rather than being simulated on paper, which makes it a LOT more exciting, great work!
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

cadet1620
Administrator
There is no easy way to connect a 1-bit signal to a 16-bit pin. There is an elegant way to use something other than an And to get x or 0.

FWIW you can make OneTo16 as
    Mux16(sel=in, a=false, b=true, out=out)

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

pouzzler
Thank you for your answer. I'll try elegant when Tetris runs. For the time being, I'll be content with validating each stage, even if my answers are cumbersome.

See you.

Sébastien
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

cadet1620
Administrator
pouzzler wrote
Thank you for your answer. I'll try elegant when Tetris runs. For the time being, I'll be content with validating each stage, even if my answers are cumbersome.

See you.

Sébastien
That is indeed the correct attitude. You will learn things along the way that you can use in later projects, or if you take a reflective look at this course when you finish it.

I have a client who has been polishing a product for over a year now and can't push it to release. It's going to be obsolete before they get it out the door!

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

Christer Nilsson
I'm defining Mux16 and I need to expand 1 bit to 16.

So I defined Expand16

CHIP Expand16 {
    IN in;
    OUT out[16];

    PARTS:
   
    Dummy(in=in, out=out[0]);
    Dummy(in=in, out=out[1]);
    Dummy(in=in, out=out[2]);
    Dummy(in=in, out=out[3]);

    Dummy(in=in, out=out[4]);
    Dummy(in=in, out=out[5]);
    Dummy(in=in, out=out[6]);
    Dummy(in=in, out=out[7]);

    Dummy(in=in, out=out[8]);
    Dummy(in=in, out=out[9]);
    Dummy(in=in, out=out[10]);
    Dummy(in=in, out=out[11]);

    Dummy(in=in, out=out[12]);
    Dummy(in=in, out=out[13]);
    Dummy(in=in, out=out[14]);
    Dummy(in=in, out=out[15]);

}

and Dummy:

CHIP Dummy {
    IN in;
    OUT out;

    PARTS:
   
    Not(in=in, out=x);
    Not(in=x, out=out);

}

Then I can define Mux16:

CHIP Mux16 {
    IN a[16], b[16], sel;
    OUT out[16];

    PARTS:
    Expand16(in=sel, out=sel16);
    Not16(in=sel16,  out=nsel16);

    And16(a=nsel16, b=a, out=sela);
    And16(a= sel16, b=b, out=selb);
    Or16(a=sela, b=selb, out=out);

}

Is there a way to expand copper without using expensive gates?


Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

Christer Nilsson
It would be nice to have a built in Dummy, maybe named NOP, Wire or something similar.

Chip Nop {
  IN in;
  OUT out;

  PARTS:
    BuiltIn;  // in=out;
}
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

ybakos
In reply to this post by Christer Nilsson
Christer - why not take a more direct approach and not use your "dummy16"? You're merely abstracting/duplicating the work that needs to be done in Mux16. Think about And16. How did you build it? Mux16 is similar.

For your second question, if you need a pin that represents "off" use the keyword false.
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

Christer Nilsson
I built my And16 using Nand16 and Not16. Two lines of code.

My NOP Chip is not producing Off, it is letting in pass thru. Just a copper wire.

Dummy16 is just copper wires. One input, 16 outputs. Gate Count Zero. Expansion from 1 bit to 16.
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

Christer Nilsson
I'm just trying to work around the inability of HDL to handle bit to bus expansion.
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

cadet1620
Administrator
Christer Nilsson wrote
Is there a way to expand copper without using expensive gates?
At one point I wanted to name some individual wires of a bus to make some code clearer so I wrote the equivalent of your Dummy as

    Chip Alias {
    ...
    And (a=in, b=true, out=out);
    }

Realize that since this is all simulation, it doesn't matter that there are "gates" hidden in Alias or your Expand16.

I put Alias.hdl in tools/builtInChips and it's available anywhere, just like the other built-in chips.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

Christer Nilsson
Thanks for your suggestion.
I tried making the Nand transparent, but failed...
And will do.
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

pango333
In reply to this post by cadet1620
cadet1620 wrote
FWIW you can make OneTo16 as
    Mux16(sel=in, a=false, b=true, out=out)
Could you please explain to me why this works?

(In general I don't quite get how to use the true/false syntax. Or, for that matter, how to make buses interact with internal pins, since every time I try, I get error messages and just give up and find a clunky workaround.)

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

cadet1620
Administrator
true and false can be used on the right side of any "=".  This connects the pin, or all the pins if it is a bus, to one or zero.

Examples:
    SomePart(a=true, ... );   // Single-bit input 'a' set to 1
    SomePart16(a=true, ...);  // 16-bit input 'a' all bits set to 1
    SomePart16(a[0..6]=false, a[7]=true, a[8..15]=false, ...);  // 16-bit input 'a' set to 128 decimal

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

pango333
This post was updated on .
Thanks--I figured it out.

And is there a way to do the opposite--to turn a 16-bit bus into a single bit? I keep getting an error message for zr because I'm inputting a 16-bit value and outputting a 1-bit one.

(My current approach for zr is just to plug the out into a Not gate.)
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

cadet1620
Administrator
What do you mean by "turn a 16-bit bus into a single bit"?

How would you turn 1101011100111000 into a single bit?

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

pango333
That's what I'm asking. The problem seems to be that I'm plugging the 16-bit out into a Not16 gate, but the out is zr, which is a 1-bit value, according to the hardware simulator.
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

pango333
Here's my code, if it helps:

Not16 (in=out, out=zr);
And (a=out[15], b=out[15], out=ng);

(While I'm at it, I'm getting an error message for the And gate, too: "Can't connect gate's output pin to part." Why is that?)
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

cadet1620
Administrator
pango333 wrote
Not16 (in=out, out=zr);
And (a=out[15], b=out[15], out=ng);

(While I'm at it, I'm getting an error message for the And gate, too: "Can't connect gate's output pin to part." Why is that?)
The error message would be clearer if it said "Can't connect chip's output pin to part." What it means is that pins named in the OUT line cannot be connected to inputs of parts used in the PARTS section.

Just like you can solder more than one wire to a physical pin, you can make more than one connection to a part's output pin:
    SomePart(..., out=out, out[??]=??, out[??..??]=??, ...);
To generate the zr signal you need some additional logic. What part that you made in project 1 will tell you if an 8-bit number is non-zero?

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Internal pin to bus

pango333
Aha. Got it.
Thanks so much!