Truth Table
You can build truth table of your sub circuit if it has input and output pins and does not contain any states holding elements like flip-flops and RAM. In other words you circuit is a pure function.
For more details on pure functions see: http://en.wikipedia.org/wiki/Pure_function
For more details on truth table see: http://en.wikipedia.org/wiki/Truth_table
To build truth table click menu Circuit/Truth Table.
In the popped up dialog you'll see a table which columns are named like input and output pins.
All the rows of the table are all the permutations of input and result of the outputs.
Here is another example of truth table of full adder.
So as you can imagine number of rows should be equal to two in power of sum of number of bits on all inputs. For example if you circuit like the one above has 3 input pins of one bit each then 2 ^ 3 = 8 the truth table will be 8 rows long. Therefore it is fairly easy to build very big truth table by just increasing bit width of input pins. The dialog however will not show more than 4096 rows because it is unmanageable number of rows. But you can use filter to ensure correctness of you circuit.
Filter is just an expression that applied to each row in the truth table to determine if the row needs to be included in the resulting truth table. In these expressions you can use names of input and output pins and check if their values are satisfy some conditions. For example for the first truth table which is just AND gate the filter expression can be: q = x & y. Please note the invert check box right next to Filter text box in the top of the dialog. If this box is checked then the result of the expression is inverted and hence the above expression been inverted will result in empty table. This is indicating correct behavior of the circuit. If you uncheck it then all the rows will be visible in the table. Please note that there is two numbers in the bottom of the dialog showing total number of rows in the truth table and number displayed in the dialog.
Expression syntax
You should know a few things about the syntax of the expressions.
If name of the pin is starting from letter and contains only letters and digits (like: a, x21, Pin190) than you can just use the name in the expression. In all other cases you need to take it in the double quote.
For example: "q+" character + is not a letter or digit, so enclose it in quotes. "a f" there is a space between letters. "1s" - the name starts from digit.
If pin name contains double quote than you need to prepend it with back slash: "a\"" for pin a". Same with the back slash itself if it is in the name use two of them in expression: "a\\" will represent name of a\ pin.
If you need to specify a number in the expression you have 4 options:
- Decimal number: 0, 1, 10, 42, etc.
- Hexadecimal number: 0x1a3, 0X34F (prepend 0x to string of hexadecimal digits: 0-9, a-f).
- Octal number: 056, 027, and 013 (prepend 0 to string of octal digits: 0-7).
- Binary number: 0b1010, 0B0001, 0b1101 (prepend 0b to string of binary digits: 0, 1).
There are two types of expressions you can use: arithmetic and logical. Arithmetic expressions evaluated on 32 bit numbers and include addition, multiplications and bit operations. Logical operation evaluated to either 0 or 1 - both are also 32 bit numbers. For example result of arithmetic operation 3 + 4 will be number 7, but result of logical operation comparison 3 < 5 will be 1.
You can use the following operations in the expressions:
Priority | Operation | Meaning |
1 | (E) | Enclose expression in the parentheses |
1 | -E | Unary negation - change sign of the expression |
1 | ~E | Bitwise not inverts all bits in the expression |
1 | !E | Logical Not - results in 0 if expression is not equal to 0 and to 1 if it is |
2 | E1 << E2 | Bitwise left shift. Shifts e1 to number of bits provide in e2 |
2 | E1 >> E2 | Bitwise right shift. Shifts e1 to number of bits provide in e2 |
3 | E1 & E2 | Bitwise AND of expressions E1 and E2 |
4 | E1 | E2 | Bitwise OR of expressions E1 and E2 |
4 | E1 ^ E2 | Bitwise EXCLUSIVE OR of expressions E1 and E2 |
5 | E1 * E2 | Multiplication of E1 and E2 |
5 | E1 / E2 | Division of E1 by E2 |
5 | E1 % E2 | Remainder of division E1 by E2 |
6 | E1 + E2 | Additions of E1 and E2 |
6 | E1 - E2 | Subtraction of E2 from E1 |
7 | E1 = E2 | You can use == also. Logical operation: equality of E1 and E2 |
7 | E1 <> E2 | You can use != instead of <>. Logical operation: not equality |
7 | E1 @ E2 | @ one of: < <= >= > Logical operation: comparison of E1 and E2 |
8 | E1 && E2 | Logical AND: results in 1 if E1 is not 0 and E2 is not 0 otherwise 0 |
9 | E1 || E2 | Logical OR: result in 1 ifE1 is not 0 or E2 is not 0 otherwise 0 |
The fact that logical operations produce numbers 0 or 1 lets you use them in arithmetic expressions. For example if you have 4 inputs multiplexer and hence 2 bit selector input you can use the following expressions to validate it. Let's assume data inputs named X0, X1, X2, X3, selector is called N, and output is Q.
(N = 0) * X0 + (N = 1) * X1 + (N = 2) * X2 + (N = 3) * X3 = Q
Here each of comparison of N will produce either 0 or 1 and 0 been multiplied to input value will results in 0 so the result will be equal to selected input.
When writing expression you need to be careful to suppress extra bits not needed in other parts like comparison. For example if you checking only s output of full adder in the above image you'll need to suppress carry in the expression. So instead of:
s = inC + a + b
You will need to have
s = (inC + a + b) & 1
Finally expression result is just a number. This number is treated as logical value "true" for any number that is not equal to 0 and "false" if it is zero.