1lytics

Designing 8-to-3 Priority Encoder using Lua

What is a priority encoder you can find in the 4-to-2 encoder article.

Gorgeous Karnaugh Versions with Lua Support

Note: Not all versions of Gorgeous Karnaugh software supports Lua scripting. Check you version features here.

Writing the Lua Script to Build Truth Table

Because the truth table for 8 input variables contains 256 rows and required too much hand job, we will use the “Lua scripting” feature to define the truth table for 8-to-3 priority encoder. Launch Gorgeous Karnaugh, select “File” — “New” — “Empty set for scripting” menu item and enter the script listed below:

gkAddInputVar('x', 8)
gkAddFunction('v')
gkAddFunction('y', 3)
MaxInput = gkGetMaxInputVector()
for InputVector = 0, MaxInput do
    if InputVector>127 then
       gkSetOutput(InputVector, 7)
    elseif InputVector>63 then
       gkSetOutput(InputVector, 6)
    elseif InputVector>31 then
       gkSetOutput(InputVector, 5)
    elseif InputVector>15 then
       gkSetOutput(InputVector, 4)
    elseif InputVector>7 then
       gkSetOutput(InputVector, 3)
    elseif InputVector>3 then
       gkSetOutput(InputVector, 2)
    elseif InputVector>1 then
       gkSetOutput(InputVector, 1)
    elseif InputVector>0 then
       gkSetOutput(InputVector, 0)
    else
       gkSetOutputUndefined(InputVector)
    end
    if InputVector>0 then
       gkSetFunctionValue( InputVector, 'v', 1 )
    else
       gkSetFunctionValue( InputVector, 'v', 0 )
    end
end

K-Maps for Minimization

After Lua script was executed, the next K-Maps for minimization will be produced:

8-to-3 Priority Encoder V  function K-Map 8-to-3 Priority Encoder Y1 function K-Map
8-to-3 Priority Encoder Y2 function K-Map 8-to-3 Priority Encoder Y3 function K-Map

Minimizing the K-Maps

Let minimize the K-Maps for Product-of-Sums (by 0):

Minimized for PoS 8-to-3 priority encoder V  K-Map Minimized for PoS 8-to-3 priority encoder Y1 K-Map
Minimized for PoS 8-to-3 priority encoder Y2 K-Map Minimized for PoS 8-to-3 priority encoder Y3 K-Map

and get the functions minimal form:

v = (x1|x2|x3|x4|x5|x6|x7|x8);
y1 = (x1|x2|x3|x4);
y2 = (x1|x2|x5|x6) (x1|x2|!x3) (x1|x2|x3|!x4);
y3 = (x1|x3|x5|!x6) (x1|x3|x5|x7) (x1|x2|x3|!x4) (x1|!x2);

Let minimize the K-Maps for Sum-of-Products (by 1):

Minimized for SoP 8-to-3 priority encoder V  K-Map Minimized for SoP 8-to-3 priority encoder Y1 K-Map
Minimized for SoP 8-to-3 priority encoder Y2 K-Map Minimized for SoP 8-to-3 priority encoder Y3 K-Map

and get the functions minimal form:

v = !x2 !x3 !x4 x5 | !x2 !x4 !x6 x7 | !x2 x3 | !x3 !x4 x6 | x2 | x4 | x8 | x1;
y1 = !x2 x3 | x2 | x4 | x1;
y2 = !x2 !x3 !x4 x5 | !x3 !x4 x6 | x2 | x1;
y3 = !x2 !x3 !x4 x5 | !x2 !x4 !x6 x7 | !x2 x3 | x1;

Building the Logic Gate Diagrams

In the “Coverage sets” pane select the needed coverage set. Next, select the “Coverages” — “Open Schematic”. In the appeared dialog window select appropriate diagram generation options, and press “Ok” button. After this, you got the logic gate diagram.

Logic gate diagrams for PoS and SoP:

Logic gate diagram for PoS minimized 8-to-3 priority encoder Logic gate diagram for SoP minimized 8-to-3 priority encoder

Checking Logic Gate Diagram in a Simulator

You can use “CEDAR Logic Simulator” program to check how your logic gate diagram works. For this, choose menu item “File” — “Save for CedarLogic” in the Gorgeous Schematic, save the “.CDL” file and open it in the “CEDAR Logic Simulator”.

Note: Not all versions of Gorgeous Karnaugh software supports export logic gate diagrams to CedarLogic. Check you version features here.

Gorgeous Karnaugh Versions

You can learn about Gorgeous Karnaugh features and compare diferences between Gorgeous Karnaugh versions on the Gorgeous Karnaugh features page.