Tutorial 2: Pin-bundling and LEDs

A Plug-in Tutorial
...     Tutorial 2: Pin-bundling and LEDs

Our second plug-in extends the first by demonstrating 2 new functionalities: pin-bundling and LED use.

package plugins.tutorial;

import dlsim.document.DLPlugIn;

/**
 * Plugin01: sample plugin using default view
 * 5 inputs, 5 outputs
 * copies input to corresponding output
 * bundles pins and uses leds
 * 
 * @author rms
 *
 */
public class Plugin01 extends DLPlugIn {
    public static PluginInfo info = 
	new PluginInfo("My Second PlugIn", "Writes input to output", "5 bits", 
		       "Illustrates in/out maps and led use");
    /**
     * Constructor must specify input and output size (default is 0)
     * Constructor may specify pin bundling with inMap and outMap
     */
    public Plugin01() {
	super();
	setInputSize(5);
	setOutputSize(5);
	setInMap(2,1,2);
	setOutMap(1,2,2);
	setLedSize(5);
    }
    /**
     * evalState is called when an input state changes
     * Parameters:
     *   source - pin number of input source that changed
     *   val - new state value (0 or 1)
     *   
     * Output changes are propagated using putState(dest, val),
     * where dest is the output pin number and val is the new state.
     * 
     * Leds show current pin state
     */
    public void evalState(int source, int val) {
	putState(source+getInputSize(), val);
	setLed(source, val);
    }
}

Pin-bundling
Pin-bundling refers to creating single input and/or output pins that act as multi-bit (i.e. bus) connectors. The pins created through bundling are analogous to the bank pins that appear on cards and chips when bank pins are used in those subcircuits. Bundled pins simplify circuit connections and facilitate integer value I/O.

Bundling patterns are specified using void setInMap(int... inMap) and void setOutMap(int... outMap). These methods must be called during object construction. In our example we create 3 input and 3 output pins. The first and last input pin is a 2-pin multipin, as are the second and third output pins.

LEDs
The default view supports a simple display tools consisting of a row of "leds" displaying numerical values. The user controls the number of LEDs displayed using setLed (default 0). The initial LED size is usually specified in the constructor (or in a method called by the constructor), but may be changed later. LEDs are numbered from left to right starting with 0.

Each LED will display a single digit from the set defined by the current led radix (default 16); use void setLedRadix(int radix) to change the led radix. The method void setLed(int ledno, long value) sets the specified LED with value % ledRadix. There are other methods to set a range of LEDs with numerical values.

Run DLSim 3 (using "ant run") and build the circuit shown below using Plugin01.

The circuit shows the pin bundling specified by setInMap and setOutMap, and the LED displays.

Exercise

  1. Change the pin mapping. Add pins and LEDs.