|
Switch ( Coord, OutputSignal, Key, InitState )
Coord = coordinate of the component
OutputSignal = output signal of the switch
Key = key on keyboard used to toggle the switch
InitState = initial state (One or Zero)
A switch does not have any inpiy signals
You can change the state of a switch by toggling the key
|
#include "Sim.h"
void simnet()
{
Sig(x,1); // Define x as a signal
Sig(y,1); // Define x as a signal
Switch ( "aa", x, 'a', Zero ); // Initial value: Zero
Probe ( "ac", x ); // Probe x
Switch ( "ca", y, 'b', One ); // Initial value: One
Probe ( "cc", y ); // Probe y
}
|
How to run the program:
|
|
Probe ( Coord, InputSignal )
Coord = coordinate of the component
InputSignal = input signal of the probe
A probe does not have any output signals
The output of a probe is the light of the probe...
|
#include "Sim.h"
void simnet()
{
Sig(x,1); // Define x as a signal
Sig(y,1); // Define x as a signal
Switch ( "aa", x, 'a', Zero ); // Initial value: Zero
Probe ( "ac", x ); // Probe x
Switch ( "ca", y, 'b', One ); // Initial value: One
Probe ( "cc", y ); // Probe y
}
|
How to run the program:
|
|
|
Note:
|
void simnet()
{
Sig(x,1); // Define x as a signal
Sig(y,1); // Define x as a signal
Switch ( "aa", x, 'a', Zero ); // Initial value: Zero
Probe ( "ac", x ); // Probe x
Switch ( "ca", y, 'b', One ); // Initial value: One
Probe ( "cc", y ); // Probe y
}
|
The Probe component can use signal group as input:
void simnet()
{
Sig(x,1); // Define x as a signal
Sig(y,1); // Define x as a signal
Switch ( "aa", x, 'a', Zero ); // Signal 1
Switch ( "ca", y, 'b', One ); // Signal 2
Probe ( "ac", (x,y) ); // Probe using signal group as input
}
|
How to run the program:
|
ProbeH ( Coord, Signals ) ;
|
Example:
void simnet()
{
Sig(x,1); // Define x as a signal
Sig(y,1); // Define y as a signal
Sig(z,1); // Define z as a signal
Switch ( "aa", x, 'a', Zero ); // Signal 1
Switch ( "ba", y, 'b', One ); // Signal 2
Switch ( "ca", z, 'c', One ); // Signal 3
ProbeH( "ac", (x,y,z) ); // HORIZONTAL probe
}
|
How to run the program:
|
|
And ( Coord, InputSignal, OutputSignal )
Coord = coordinate of the component
InputSignal = input signal of the And-gate
OutputSignal = output signal of the And-gate
|
#include "Sim.h"
void simnet()
{
Sig(sw0,1); // Define sw0 as a signal
Sig(sw1,1); // Define sw1 as a signal
Sig(out,1); // Define out as a signal
Switch ( "aa", sw0, 'a', Zero ); // Location = "aa", name = sw0, key = 'a'
Switch ( "ca", sw1, 'b', One ); // Initial value: Zero or One
And ( "bb", (sw0,sw1), out ); // And: inputs = (sw0,sw1), output = out
// Note: ( .., .. ) group signals into 1 signal
// Note: sw0 is equivalent to sw0[0]
Probe ( "bc", out ); // Probe out
}
|
How to run the program:
|
And ( .... ) And gate
Or ( .... ) Or gate
Not ( .... ) Not gate
Nand( .... ) Nand gate
Nor ( .... ) Nor gate
Xor ( .... ) Exclusive Or gate
Xnor( .... ) Exclusive Nor gate
|
|
Decoder ( Coord, enable, controls, outputs );
Coord = coordinate of the component
enable = the enable signal of the Decoder
controls = the control signals
outputs = the output signals
Reqirement:
# output signals = 2# control signals
|
#include "Sim.h"
void simnet()
{
Sig(c0,1); Sig(c1,1); // Control signals
Sig(o0,1); Sig(o1,1); Sig(o2,1); Sig(o3,1); // Output signals
Sig(enable,1);
Switch( "fa", c1, 'b', Zero );
Switch( "ga", c0, 'a', Zero );
Switch( "ia", enable, 'z', Zero );
/* ============================================================
c1 c0 Output
----------------------------------------------------
0 0 o0 = 1, all other outputs = 0
0 1 o1 = 1, all other outputs = 0
1 0 o2 = 1, all other outputs = 0
1 1 o3 = 1, all other outputs = 0
============================================================ */
Decoder ( "ab-db", enable, (c1,c0), (o3,o2,o1,o0) ); // Decoder
Probe ( "ac", o3 ); // Probe output
Probe ( "bc", o2 ); // Probe output
Probe ( "cc", o1 ); // Probe output
Probe ( "dc", o0 ); // Probe output
}
|
How to run the program:
|
|
Dff ( Coord, (set, D, clock, reset), Q );
Coord = coordinate of the component
set = the set signal
D = the input (1 bit) of the D-flipflop
clock = the clock used to write the D-flipflop
reset = the reset signal
Q = the output of the D-flipflop
|
void simnet()
{
Sig(set,1); Sig(reset,1); // Special control signals
Sig(D,1); Sig(Q,1); // D = Dff input, Q = Dff output
Sig(clock,1); // Clock signal
Switch( "aa", D, '0', Zero );
Switch( "fa", set, 'b', Zero );
Switch( "ga", reset, 'a', Zero );
Switch( "ia", clock, 'z', Zero );
/* ============================================================
reset (a) = 1 ==> force Dff output to 0
set (b) = 1 ==> force Dff output to 1
reset = 0 AND set = 0 ==> Operate like a normal Dff
D = data in
Clock = write signal for Dff
Q = output of Dff
============================================================ */
Dff ( "ab-hb", (set,D,clock,reset), Q ); // D-flipflop
Probe ( "ac", Q ); // Probe output
}
|
How to run the program:
|
|
|
Register ( Coord, enable, wr, inputs, outputs );
Coord = coordinate of the component
enable = enable signal
wr = write signal
inputs = the input signals of the register
outputs = the output signals of the register
|
void simnet()
{
Sig(d,8); // Input (data) signals for register
Sig(o,8); // Output signals of register
Sig(enable,1); // Enable signal
Sig(wr,1); // Write signal
Switch( "aa", d[7], '7', Zero );
Switch( "ba", d[6], '6', One );
Switch( "ca", d[5], '5', Zero );
Switch( "da", d[4], '4', Zero );
Switch( "ea", d[3], '3', One );
Switch( "fa", d[2], '2', Zero );
Switch( "ga", d[1], '1', Zero );
Switch( "ha", d[0], '0', One );
Switch( "jb", enable, 'a', Zero );
Switch( "jc", wr, 'b', Zero );
/* ============================================================
Register
Write with wr = 1
Write only happens when enable = 1
============================================================ */
Register ( "ab-hb", enable, wr,
(d[7],d[6],d[5],d[4],d[3],d[2],d[1],d[0]),
(o[7],o[6],o[5],o[4],o[3],o[2],o[1],o[0])
);
Probe( "ad-hd", o); // Probe output
}
|
How to run the program:
|
|
( x[i]-x[j] ) is equavalent to:
( x[i], x[i+1], ... , x[j] ) if i ≤ j
or: ( x[i], x[i-1], ... , x[j] ) if i ≥ j
|
Example:
|
How to run the program:
|
Suppose we define an array of N signals:
Sig( x, N );
|
Example:
|
How to run the program:
|
|
Example: if we want to always enable a register
Register ( "ab-hb", One, wr, d, o ); |
How to run the program:
|
|
Mux ( Coord, Controls, Inputs, Outputs )
Coord = coordinate of the component
Controls = k control signals of the Mux
Inputs = 2k groups of input signals of the Mux
Outputs = one group of the input groups is selected
as output group
|
Requirement:
|
void simnet()
{
Sig(i0,1); Sig(i1,1); Sig(i2,1); Sig(i3,1); // Input signals
Sig(c0,1); Sig(c1,1); // Control signals
Sig(out,1); // Output signal
Switch( "aa", i3, '3', Zero );
Switch( "ba", i2, '2', Zero );
Switch( "ca", i1, '1', Zero);
Switch( "da", i0, '0', One );
Switch( "fa", c1, 'b', Zero );
Switch( "ga", c0, 'a', Zero );
/* ==========================================
c1 c0 Output
--------------------------
0 0 i0
0 1 i1
1 0 i2
1 1 i3
========================================== */
Mux ( "ab-db", (c1,c0), (i3,i2,i1,i0), out ); // Mux !!!
Probe ( "bc", out ); // Probe out
}
|
Notice that:
|
Sample output:
|
How to run the program:
|
|
How to run the program:
|
|
|
ROM ( Coord, addrs, outputs, #entries, #bits, RomContent );
Coord = coordinate of the component
addrs = address signals
outputs = the output signals of the ROM
#entries = # entries stored in the ROM
Must equal to 2#addrs
#bits = # bits in the output signals of the ROM
RomContent = Byte array used to store the values of the ROM entries
|
|
Example:
|
void simnet()
{
/* ==============================================
ROM contains 8 words, each word has 16 bits
============================================== */
unsigned char RomContent[] = {
0b10101010, 0b10101010, // Word 0
0b11110000, 0b11110000, // Word 1
0b00110011, 0b00110011, // Word 2
0b11001100, 0b11001100, // Word 3
0b00001111, 0b00001111, // Word 4
0b11111111, 0b11111111, // Word 5
0b00000000, 0b00000001, // Word 6
0b10000000, 0b00000000}; // Word 7
Sig(addr,3); // Address signals
Sig(out,16); // Output signals
Switch( "fa", addr[2], '2', Zero );
Switch( "fb", addr[1], '1', Zero );
Switch( "fc", addr[0], '0', Zero );
/* ============================================================
Rom with 3 address bits and 8 data bits
Requirement:
1. # words = 2^(size of addr)
2. # bits = size of out
============================================================ */
Rom ( "bb-db", addr, out, 8 /* # words */, 16 /* # bits in a word */,
RomContent );
ProbeH( "aa-ad", out); // Probe output
}
|
How to run the program:
|
Example: using Hexadecimal notation
void simnet()
{
/* ==============================================
ROM contains 8 words, each word has 16 bits
============================================== */
unsigned char RomContent[] = {
0xAA, 0xAA, // Word 0
0xF0, 0xF0, // Word 1
0x33, 0x33, // Word 2
0xCC, 0xCC, // Word 3
0x0F, 0x0F, // Word 4
0xFF, 0xFF, // Word 5
0x00, 0x01, // Word 6
0x80, 0x00}; // Word 7
Sig(addr,3); // Address signals
Sig(out,16); // Output signals
Switch( "fa", addr[2], '2', Zero );
Switch( "fb", addr[1], '1', Zero );
Switch( "fc", addr[0], '0', Zero );
/* ============================================================
Rom with 3 address bits and 8 data bits
Requirement:
1. # words = 2^(size of addr)
2. # bits = size of out
============================================================ */
Rom ( "bb-db", addr, out, 8 /* # words */, 16 /* # bits in a word */,
RomContent );
// Rom
ProbeH( "aa-ad", out); // Probe output
}
|
How to run the program:
|