problem With D-Latch

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

problem With D-Latch

sarthak
Hello,
I wrote the following code for D-Latch:
CHIP DLatch {
IN d,clk;
OUT q;
PARTS:
Mux(a=v,b=d,sel=clk,out=v);
Not(in=v,out=vn);
Not(in=vn,out=q);
}

CHIP Mux  {
IN a,b,sel;
OUT out;

BUILTIN Mux;
CLOCKED out;
}

The latch was expected to hold to the current output if the clk input is 0, else follow the d input. But even though clk is set to 0, the output of the latch changes with the input d.
What is wrong with this code?
Reply | Threaded
Open this post in threaded view
|

Re: problem With D-Latch

cadet1620
Administrator
sarthak wrote
CHIP Mux  {
IN a,b,sel;
OUT out;

BUILTIN Mux;
CLOCKED out;
}
The stubs for the built-in parts only tell the Hardware Simulator how the .class file that implements the part behaves.

Unless you change the behavior of the Mux.class file (edit and recompile the Mux.java source) it will not behave as a clocked chip.

If you want to experiment with sequential circuits, I suggest investigating Logisim. It can handle asynchronous feedback like the D Latch you are trying to build.

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

Re: problem With D-Latch

sarthak
This post was updated on .
Doesn't the CLOCKED keyword makes the pins of the BUILTIN module behave like a clocked pins? Shouldn't this be sufficient to make the Mux a clocked chip?
When clk is set to 0 (which is connected to sel pin of the mux) and I change d (which is connected to pin b of mux) from 0 to 1, why would the output, the pin v, change to 1? Shouldn't it depend on the input v (connected to pin a of mux)?
Further, in the BuiltInChips folder I can only see the Mux.class file, where can I find Mux.java file?
Reply | Threaded
Open this post in threaded view
|

Re: problem With D-Latch

cadet1620
Administrator
The source code is linked at the bottom of this page:
    http://www.nand2tetris.org/software.php

I'm not a Java programmer.  I don't know what's involved in rebuilding the built-in chips.


I've never looked at the Hardware Simulator code. If I had to gues from its external behavior, CLOCKED only prevents an output from causing downstream reevaluation and preventing the "circle in its parts" message.


The Hardware Simulator was not designed to support general sequential circuits, but I managed to use it as a sort of meta-simulator and built a DFF using Nands with DFFs on their outputs.  See this post: From NAND to DFF

--Mark