Mux/DMux Syntax

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

Mux/DMux Syntax

Andrew
Sorry if this has been answered elsewhere, I haven't found it yet.

What is the syntax format for using Mux, Dmux, and their descendents in constructing other chips?

For instance, and this didn't work for me, but one thing I tried was Mux(in=in, a=sel[1], b=sel[0], out=out);

Or DMux4Way(a=a,b=b,c=c,d=d,in=sel[3],out=out);

I've been playing with it but not really finding a working syntax yet. And I haven't really considered adding bit arrays even.

Also, is there a way to create hdl files so I can make my own custom chips?

Thanks for any help.
Reply | Threaded
Open this post in threaded view
|

Re: Mux/DMux Syntax

cadet1620
Administrator
Andrew wrote
What is the syntax format for using Mux, Dmux, and their descendents in constructing other chips?

For instance, and this didn't work for me, but one thing I tried was Mux(in=in, a=sel[1], b=sel[0], out=out);

Or DMux4Way(a=a,b=b,c=c,d=d,in=sel[3],out=out);
If you haven't, you need to read the Hardware Construction Survival Guide and Appendix A (pdf).

You can look at the HDL file for a part to see its interface. For instance, Mux.hdl declares its interface as
    CHIP Mux {
        IN  a, b, sel;
        OUT out;
To use it you need to write
    Mux(a=..., b=..., sel=..., out=...);
DMux4Way declares its interface as
    CHIP DMux4Way {
        IN  in, sel[2];
        OUT a, b, c, d;
"sel[2]" means that the sel input is a 2-bit bus. Think of an N-bit bus as a bundle of wires, not an array of bits. You need to connect sel to a 2-bit bus, or you can individually connect the two wires to individual wires using
    DMux4Way(..., sel[0]=aWire, sel[1]=anotherWire,...);
Sometimes you need to connect a part of a wide bus to a narrower input. To do this write something like
    DMux4Way(..., sel=wideBus[11..12], ...);
This would connect bits 11 and 12 of wideBus to bits 0 and 1 of sel.
Also, is there a way to create hdl files so I can make my own custom chips?
All you need to do is create an HDL file just like the ones you have been writing, with the name of your part and the HDL that implements it. As long as your custom HDL file is in the same directory as the part that uses it, your custom part will be used. An easy way to start a custom part is to copy an existing part that has the same interface as the part you want to make. Don't forget to change the name on the CHIP line to match the new file name.

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

Re: Mux/DMux Syntax

Andrew
Thank you, that is very helpful.