And.hdl file error

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

And.hdl file error

Jonathan
Hi, I am just beginning project 1, after figuring out the JRE problem that I was having. I have added some lines to the "Parts" section of the And.hdl file, and when I load it, the Hardware Simulator hangs.    Before I modify the file, it loads fine, and you can see the file in the lower left window, (which still says "// add code here".) but, as I mentioned, after modifiying the file, it causes errors to be generated in the cmd window. I would like to post a .png screen capture so that you can see the error that is generated in the command window after attempting to load a modified .hdl file, but I don't think that's possible, right?  The following lines are shown in the cmd window after a few attempts to load a modified .hdl file:

at Hack.Gates.CompositeGateClass.readParts(Unkown Source)
at Hack.Gates.CompositeGateClass.<init>(Unknown Source)
at Hack.Gates.GateClass.readHDL(Unknown Source)
at Hack.Gates.GateClass.getGateClass(Unknown Source)
at Hack.Gates.CompositeGateClass.readParts(Unknown Source)..... >> repeats <<

I am using TextPad to add my 'input' to the .hdl file, which are:

PARTS:
And(a=a, b=notb, out=w1);
And(a=nota, b=b, out=w2);


If anyone can help with this, I would appreciate it.
Reply | Threaded
Open this post in threaded view
|

Re: And.hdl file error

cadet1620
Administrator
Jonathan wrote
Hi, I am just beginning project 1, after figuring out the JRE problem that I was having. I have added some lines to the "Parts" section of the And.hdl file, and when I load it, the Hardware Simulator hangs....

I am using TextPad to add my 'input' to the .hdl file, which are:

PARTS:
And(a=a, b=notb, out=w1);
And(a=nota, b=b, out=w2);


If anyone can help with this, I would appreciate it.
The problem is that you are trying to use your And chip as a part in your And chip and it appears that this is not detected and is resulting in a stack overflow in the simulator.

Build the chips in the order listed in the book section 1.2
The first chip you build will be the Not chip. The only line in the Parts: section will be a Nand part.

Then build the And chip. The only lines in its Parts: section will be some combination of Nand and Not.

Then build the Or chip. The only lines in its Parts: section will be some combination of Nand, Not and And.

Everything builds upon what you have already designed and tested.

If you haven't read it yet, read the Hardware Construction Survival Kit, especially the implementation order section.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: And.hdl file error

Jonathan
This post was updated on .
Mark,

Thanks for the help in getting me started.  After your explanation, the errors I was getting made sense, I reread chapter 1, and printed out the Boolean Algebra slides then read them thoroughly and started the project.  I have a working not "chip" and a working and "chip" using Nand. My Xor "chip" is not functioning, and I don't understand what I'm doing wrong with it. Here is my Parts description:
 
....

Xor is opposite of Or, right? so shouldn't this be correct?  I am getting comparison failure at line 3, so it isn't correct, but I don't understand why.
Reply | Threaded
Open this post in threaded view
|

Re: And.hdl file error

cadet1620
Administrator
The inverse of OR is NOR which means "not or." XOR is "exclusive or." See figure 1.5.

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

Re: And.hdl file error

cadet1620
Administrator
In reply to this post by Jonathan
The next chip you should be working on after And is Or.

The HDL you posted is actually quite close to Or.  Draw a truth table of what you are calculating.

Once you have your Or working, please edit your post to remove the HDL. We want people to fine their own solutions.

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

Re: And.hdl file error

Jonathan
This post was updated on .
I edited the initial post to remove the code, after trying out your suggestions.  I now have a working not, and and or.  I am stuck at xor.  From the boolean algebra lesson, slide 6:

Xor(a, b) = Or(And(a, Not(b)), And(Not(a),b)))

The way I interpret this is "xor(a,b) is equivalent to Or * Nand(a) * Nand(b)"

Is this correct?

Also, to implement Xor.hdl, I used a modified form of the example from the Hardware Simulator slides, (#8). When I test it, I get 'comparison failure at line 5', the output of the truth table is:

| a | b | out |
| 0 | 0 |  0   |  
| 0 | 1 |  1   |
| 1 | 0 |  1   |
| 1 | 1 |  0   |

I am not sure why I'm getting an error, here.

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

Re: And.hdl file error

cadet1620
Administrator
Jonathan wrote
I edited the initial post to remove the code, after trying out your suggestions.  I now have a working not, and and or.  I am stuck at xor.  From the boolean algebra lesson, slide 6:

Xor(a, b) = Or(And(a, Not(b)), And(Not(a),b)))

The way I interpret this is "xor(a,b) is equivalent to Or * Nand(a) * Nand(b)"

Is this correct?
In infix notation:
    a XOR b = (a & ~b) | ((~a) & b)

Figure 1.6 shows the hardware implementation of Xor.

If you haven't seen this notation for Boolean arithmetic yet, '&' is And, '|' is Or and '~' is Not.

Note that And (a, Not(b)) is not equivalent to Nand (a, b).  

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

Re: And.hdl file error

Jonathan
Infix notation helped, prefix notation is difficult for me to work out, and something I have to work on.  I think my biggest problem thus far is thinking of HDL as a programming language like C++ or Java and I have been viewing the inputs and outputs as variables.  I used the parts from the hardware simulator lesson (which I hadn't seen till today, because the slide it is on follows the mux slides. I had stopped there previously because I was working on the book incrementally, and I wasn't ready to tackle the mux yet, and was intent on completing the first parts of project 1 and build to the mux part.

After using the xor description from the slides, and getting a successful comparison, I stepped through the parts to emulate the test script, and I now have a better understanding of what is going on.

After stepping through the xor description, it came to me that even though HDL isn't a programming language, it is similar to python in that you can create variables on the fly, no need to declare them before hand, so for example, you can call 'out' whatever you want (out = a, out = nota, etc), then use it later. This line of thinking helps me understand what I need to do to complete the project.

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

Re: And.hdl file error

ybakos
Jonathan wrote
After stepping through the xor description, it came to me that even though HDL isn't a programming language, it is similar to python in that you can create variables on the fly, no need to declare them before hand, so for example, you can call 'out' whatever you want (out = a, out = nota, etc), then use it later. This line of thinking helps me understand what I need to do to complete the project.
I'm glad you found a way of thinking that helped you solve the implementation. But, instead of comparing it to Python (which I fear may mislead you), try to imagine it as the names of wires or in/out pins that you would actually be physically wiring.

"I'll take the output of this chip and connect it to a wire called a, and I'll also connect the output of the chip to another wire called nota."

Reply | Threaded
Open this post in threaded view
|

Re: And.hdl file error

Jonathan
I can see what you mean by that, and the wiring analogy fits much better.  I will use that pattern of thinking to get out of the programming mindset.

As I'm going through the "Elements" book/projects, I am also reading through "Shaum's essential computer math",  which has a pretty in depth chapter on boolean algebra, which even though it seems should be simple, I find it somewhat confusing, but I think I am developing an understanding of it.  If it wouldn't be too much trouble, could you tell me if the below truth table is correct?

Boolean Expression = A * (B + A) * C, Truth table =

ABC (B+A)(A and B or A) ((AandBorA)And C)
111     1            1                      1
110     1            1                      0
101     1            1                      1
100     1            1                      0
011     1            0                      0
001     0            0                      0
000     0            0                      0

In case you're unfamiliar with this book (schaum's), this boolean expression is an answer to a solved question from the book (the question was 'state the boolean expression from the given switching circuit').  The truth table wasn't given for this particular question/answer, so I went through it and constructed it on my own, but would like to make sure that it is correct.

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

Re: And.hdl file error

cadet1620
Administrator
Jonathan wrote
ABC (B+A) (A and B or A) ((AandBorA)And C)
ABC (B+A) (A and (B or A)) ((A and (B or A)) and C)

You should keep the () in (A and (B or A)); and has precedence over or, like multiplication has precedence over addition.

Otherwise, it looks correct other than missing the 010 line...

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: And.hdl file error

Jonathan
Doh! I thought I had 8 lines there, :D

I have a grip on this now, after going through the chips in order up till Xor, I had "cheated" and used the example from the lessons, but I just got a successful test of a Xor that I "designed" using only Nand (four nands to be exact). I drew myself a logic circuit, and wrote out the truth table, then wrote the description out.  The truth table looks a little wonky, because I wrote it as such...

A B And-Not  A & And-Not  B & And-Not  And-Not
0 0    0   1            0     1           0     1     1      0 (this last one being the output)


I will spare you the complete truth table, but I wanted to share what feels like a small triumph to me in getting this far (I couldn't have done it without the help and support of this forum).

- Jonathan