Search in sources :

Example 6 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class SimplifyTest method testSimplify2.

public void testSimplify2() throws Exception, FormatterException {
    Variable a = v("a");
    Variable b = v("b");
    Expression e = and(or(a, b), a);
    Expression s = QuineMcCluskey.simplify(e);
    assertEquals("a", FormatToExpression.FORMATTER_UNICODE.format(s));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) Expression(de.neemann.digital.analyse.expression.Expression)

Example 7 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class TableReducerTest method testReduce2.

public void testReduce2() {
    List<Variable> vars = new ArrayList<>();
    vars.add(a);
    vars.add(b);
    vars.add(c);
    vars.add(d);
    Expression ex = and(a, c, d);
    ContextFiller cf = new ContextFiller(vars);
    BoolTableExpression bte = new BoolTableExpression(ex, cf);
    TableReducer tr = new TableReducer(vars, bte);
    assertTrue(tr.canReduce());
    vars = tr.getVars();
    assertEquals(3, vars.size());
    assertEquals(a, vars.get(0));
    assertEquals(c, vars.get(1));
    assertEquals(d, vars.get(2));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ArrayList(java.util.ArrayList)

Example 8 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class TableReducerTest method testReduce.

public void testReduce() {
    List<Variable> vars = new ArrayList<>();
    vars.add(a);
    vars.add(b);
    vars.add(c);
    vars.add(d);
    Expression ex = and(a, b, c);
    ContextFiller cf = new ContextFiller(vars);
    BoolTableExpression bte = new BoolTableExpression(ex, cf);
    TableReducer tr = new TableReducer(vars, bte);
    assertTrue(tr.canReduce());
    vars = tr.getVars();
    assertEquals(3, vars.size());
    assertEquals(a, vars.get(0));
    assertEquals(b, vars.get(1));
    assertEquals(c, vars.get(2));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ArrayList(java.util.ArrayList)

Example 9 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class ATF1502CuplExporterTest method testCUPLExporter.

public void testCUPLExporter() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
    ATF150xCuplExporter ce = ATFDevice.ATF1502PLCC44.getCuplExporter("user", null);
    ce.getPinMapping().parseString("Y_0=4;Y_1=5;A=6");
    ce.setProjectName("test");
    ce.getBuilder().addSequential("Y_0", y0s).addSequential("Y_1", y1s).addCombinatorial("A", and(y0, y1));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ce.writeTo(baos);
    assertEquals("Name     test ;\r\n" + "PartNo   00 ;\r\n" + "Date     unknownDate ;\r\n" + "Revision 01 ;\r\n" + "Designer user ;\r\n" + "Company  unknown ;\r\n" + "Assembly None ;\r\n" + "Location unknown ;\r\n" + "Device   f1502ispplcc44 ;\r\n" + "\r\n" + "ar = 'b'0 ;\r\n" + "\r\n" + "/* inputs */\r\n" + "PIN 43 = CLK;\r\n" + "\r\n" + "/* outputs */\r\n" + "PIN 4 = Y_0;\r\n" + "PIN 5 = Y_1;\r\n" + "PIN 6 = A;\r\n" + "\r\n" + "/* sequential logic */\r\n" + "Y_0.D = !Y_0;\r\n" + "Y_0.ck = CLK ;\r\n" + "Y_0.ar = ar ;\r\n" + "Y_1.D = (!Y_0 & Y_1) # (Y_0 & !Y_1);\r\n" + "Y_1.ck = CLK ;\r\n" + "Y_1.ar = ar ;\r\n" + "\r\n" + "/* combinatorial logic */\r\n" + "A = Y_0 & Y_1;\r\n", baos.toString());
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 10 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class Gal16V8CuplExporterTest method testCUPLBuilderInvalidVars.

public void testCUPLBuilderInvalidVars() throws Exception {
    // D is not allowed in CUPL
    Variable y0 = new Variable("D");
    Expression y0s = not(y0);
    try {
        new CuplExporter("user", new Date(0)).setProjectName("test").getBuilder().addSequential("Y_0", y0s);
        fail();
    } catch (RuntimeException e) {
        assertTrue(true);
    }
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) Date(java.util.Date)

Aggregations

Variable (de.neemann.digital.analyse.expression.Variable)51 Expression (de.neemann.digital.analyse.expression.Expression)34 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)10 NamedExpression (de.neemann.digital.analyse.expression.NamedExpression)8 ArrayList (java.util.ArrayList)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)6 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)5 TestExecuter (de.neemann.digital.TestExecuter)4 Circuit (de.neemann.digital.draw.elements.Circuit)4 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)4 ModelCreator (de.neemann.digital.draw.model.ModelCreator)4 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)4 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)3 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)3 TableReducer (de.neemann.digital.analyse.quinemc.TableReducer)3 TruthTable (de.neemann.digital.analyse.TruthTable)2 FormatterException (de.neemann.digital.analyse.expression.format.FormatterException)2 FuseMapFillerException (de.neemann.digital.builder.jedec.FuseMapFillerException)2 JedecWriter (de.neemann.digital.builder.jedec.JedecWriter)2