Eqntott: Truth Table Generator from Boolean Equations

0
175

This tutorial demonstrates the use of eqntott software with some code examples

Shakthi Kannan


eqntott (short for ‘equation to truth table’) is a software tool that can generate truth tables from Boolean equations, which can be used for programmable logic array (PLA) programming. It was initially written at Berkeley, and ported to work on GNU/Linux. It is released under the new BSD licence.

Explore Circuits and Projects Explore Videos and Tutorials

Consider a simple AND example:

NAME = and;
INORDER = a b;
OUTORDER = c;
c = a & b;

Here NAME refers to the name of the PLA, and is called ‘and’. INORDER lists the input order of elements, while OUTORDER has the list of outputs in the truth table. Copy this example in a text editor and save it as ‘and.eqn.’

To run the above example, use ‘cd’ command in order to go to the directory where the example is saved. Now run the following command:

$ eqntott and.eqn

You will get the output as:

.i 2
.o 1
.p 1
11 1
.e

’.i’ in the output refers to the number of inputs defined, which refers to ‘a’ and ‘b’ in the above example. ’.o’ corresponds to the number of output variables, which is ‘c.’ ’.p’ is the number of product terms. The truth table generated shows that the output is ‘1’ when both the inputs are ‘1’.

You can use ‘-l’ option with eqntott to output the PLA name, input and output elements:

$ eqntott -l and.eqn

The output will be:

.i 2
.o 1
.na and
.ilb a b
.ob c
.p 1
11 1
.e

The name of the PLA is mentioned next to ’.na’ in the output. The order of inputs and outputs in the truth table is also listed.

READ
Keep Away NI-CD From Memory Effect

The following expressions are allowed in the equations for eqntott:

ExpressionMeaning
&Logical AND operation
|Logical OR operation
!Logical NOT operation
ZERO or 0False or the value zero
ONE or 1True or the value one
( )To enclose any expression
?Don’t care condition
nameAny input/output in the expression

The half adder circuit adds two binary digits, and produces a sum and a carry. It can be implemented as follows:

NAME = half_adder;
INORDER = a b;
OUTORDER = s c;
c = a & b;
s = (!a & b) | (a & !b);

When the above equation is run with eqntott:

$ eqntott -l half_adder.eqn

The output will be:

.i 2
.o 2
.na half_adder
.ilb a b
.ob s c
.p 3
01 1 0
10 1 0
11 0 1
.e

The sum is represented by ’s’ and carry with ‘c.’ When either the sum or carry is ‘1,’ the sum is ‘1’ and carry is ‘0.’ When both the sum and carry are ‘1,’ the sum is ‘0’ and carry is ‘1.’

The output of eqntott can be customised using ‘-.key’ argument. The default option is the string ‘iopte.’ A few key code options with their output meaning are given below:

CharacterOutput
e.e
f.f output-number input-number
hHuman readable format
i.i number of inputs
lTruth table with PLA name, inputs and outputs
o.o number of outputs
p.p number-of-product-terms
veqntott version number
SPLA connectivity summary

If the half adder example is run with the following key options:

$ eqntott -.lhptv half_adder.eqn

The output will be:

 

.na half_adder
.ilb a b
.ob s c
2 inputs, 2 outputs, 3 product terms.
s !a b
s a !b
c a b
.p 3
01 1 0
10 1 0
11 0 1
eqntott 9.0

The PLA connectivity summary can be displayed using ’-.S’ key code option. When used with ‘and.eqn’ example as:

READ
AC-Powered Led Lamps Without rectifiers

$ eqntott -.S and.eqn

The output will be:

PLA Connectivity Summary
#pterms input
1 b
1 a
#pterms output
1 c
#out #in product term expression
1 2 a & b

‘-s’ option allows you to use an output variable in another expression. Consider, for example:

NAME = s;
INORDER = a b;
OUTORDER = d;
c = a | b;
d = !c;

When you run the above example with ‘-s’ option as:

$ eqntott -l -s s.eqn

The output will be:

.i 3
.o 2
.na s
.ilb a b c
.ob d c
.p 3
00- 1 0
-1- 0 1
1– 0 1
.e

When both the inputs ‘a’ and ‘b’ are zero, the output ‘c’ is zero and ‘d’ is ‘1.’ If either ‘a’ or ‘b’ is ‘1,’ ‘c’ is ‘1’ and ‘d’ is ‘0.’

‘-f’ option allows an input to also be present in the output, and used as though the value was observed at different times. Consider, for example:

NAME = f;
INORDER = a;
OUTORDER = a;
a = !a;

When you execute the above example as:

$ eqntott -l -f f.eqn

The output will be:

.i 1
.o 1
.na f
.ilb a
.ob a
.p 1
.f 1 1
0 1
.e

The truth table output is ‘1’ only when the input is ‘0.’ The ‘-s’ and ‘-f’ options are mutually exclusive.

eqntott can attempt to minimise the logic terms in equations. ‘-r’ option will try to reduce the minterms in the output. Consider the example:

NAME = reduce;
INORDER = x y;
OUTORDER = z;
z = x & y | x;

When you use the above example with ‘-l’ option as:

$ eqntott -l reduce.eqn

The output will be:

.i 2
.o 1
.na reduce
.ilb x y
.ob z
.p 2
1- 1
11 1
.e

Using ‘-r’ option, eqntott will try to minimise the truth table output:

$ eqntott -l -r reduce.eqn

The output will be:

 

.i 2
.o 1
.na reduce
.ilb x y
.ob z
.p 1
1- 1
.e

The output ‘z’ is ‘1’ whenever ‘x’ is ‘1.’

READ
Micro-Power Flasher

You can define expressions using ‘define’ keyword. The XOR logic takes two binary inputs, and returns ‘1’ only when either input is ‘1’ but not both. It can be expressed as:

#define xor(a,b) (a&!b | !a&b)
NAME = xor;
INORDER = a b;
OUTORDER = c;
c = xor (a,b);

On running the example as:

$ eqntott -l xor.eqn

The output will be:

.i 2
.o 1
.na xor
.ilb a b
.ob c
.p 2
01 1
10 1
.e

As a final example, consider generating an odd parity bit for three inputs. The parity bit is set to ‘1’ when the number of ‘1’s’ in the input is even, so as to make the total number of ‘1’s’ odd. We can define the logic using:

 

#define xor(a,b) (a&!b | !a&b)
NAME = parity;
INORDER = x y z;
OUTORDER = p;
p = !( xor (xor(x,y), z) );

When you run the above example with ‘-l’ and ‘-s’ options as:

 

$ eqntott -l -s parity.eqn

The output will be:

 

.i 3
.o 1
.na parity
.ilb x y z
.ob p
.p 4
000 1
011 1
101 1
110 1
.e

You can refer the manual page of eqntott for more documentation. Sources are available from the eqntott webpage.


The author is a free software developer at the Fedora project, and also a blogger. He also
co-maintains the Fedora Electronic Lab project

LEAVE A REPLY