Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| intro_example:gates [2020/04/30 12:50] – created rajit | intro_example:gates [2022/05/13 13:18] (current) – rajit | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| The following specifies a number of combinational gates, where the process names correspond to the commonly used names for the gates. | The following specifies a number of combinational gates, where the process names correspond to the commonly used names for the gates. | ||
| - | < | + | < |
| defproc inverter (bool? i; bool! o) | defproc inverter (bool? i; bool! o) | ||
| { | { | ||
| Line 26: | Line 26: | ||
| </ | </ | ||
| + | While all the syntax should be familiar, this example also uses '','' | ||
| + | |||
| + | If we wanted to create a two-input and gate, we could simply write: | ||
| + | |||
| + | <code act> | ||
| + | defproc and2 (bool? a, b; bool! c) | ||
| + | { | ||
| + | prs { | ||
| + | a & b => c+ | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | This would be accepted by ACT, and the production rule simulator [[tools: | ||
| + | |||
| + | <code act> | ||
| + | defproc and2 (bool? a, b; bool! c) | ||
| + | { | ||
| + | bool _c; | ||
| + | prs { | ||
| + | a & b => _c- | ||
| + | _c => c- | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | In this example, we have introduced a local variable '' | ||
| + | |||
| + | Since we already have defined '' | ||
| + | |||
| + | <code act> | ||
| + | defproc and2 (bool? a, b; bool! c) | ||
| + | { | ||
| + | bool _c; | ||
| + | nand2 n(a,b,_c); | ||
| + | inverter i(_c,c); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Here, the body of '' | ||
| + | |||
| + | In terms of naming, the ports of '' | ||
| + | |||
| + | ACT provides a very flexible mechanism for connecting signals. The following are variants that correspond to the same connections. | ||
| + | |||
| + | <code act> | ||
| + | defproc and2 (bool? a, b; bool! c) | ||
| + | { | ||
| + | bool _c; | ||
| + | nand2 n; | ||
| + | inverter i; | ||
| + | n.a = a; | ||
| + | n.b = b; | ||
| + | n.c = _c; | ||
| + | i.i = _c; | ||
| + | i.o = c; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| + | |||
| + | <code act> | ||
| + | defproc and2 (bool? a, b; bool! c) | ||
| + | { | ||
| + | bool _c; | ||
| + | nand2 n(.a=a, .b=b, .c=_c); | ||
| + | inverter i(.i=_c, .o=c); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Simulation with irsim ===== | ||
| + | |||
| + | '' | ||
| + | |||
| + | To simulate a circuit, you need a top-level instance. Here is a small self-contained example. | ||
| + | |||
| + | <code act> | ||
| + | defproc inverter (bool? i; bool! o) | ||
| + | { | ||
| + | prs { | ||
| + | i => o- | ||
| + | } | ||
| + | } | ||
| + | |||
| + | defproc nand2 (bool? a, b; bool! c) | ||
| + | { | ||
| + | prs { | ||
| + | a & b => c- | ||
| + | } | ||
| + | } | ||
| + | |||
| + | defproc and2 (bool? a, b; bool! c) | ||
| + | { | ||
| + | nand2 n(.a=a, .b=b); | ||
| + | inverter i(.i=n.c, .o=c); | ||
| + | } | ||
| + | |||
| + | and2 a; | ||
| + | </ | ||
| + | |||
| + | If this is saved in '' | ||
| + | |||
| + | < | ||
| + | % prs2sim test_and.act test | ||
| + | </ | ||
| + | |||
| + | Note that '' | ||
| + | |||
| + | A simple '' | ||
| + | |||
| + | < | ||
| + | % irsim scmos30 test.sim test.al | ||
| + | </ | ||
| + | |||
| + | (Note that you can run irsim from the terminal window as well as from the magic window. Please run irsim from the terminal window.) This starts the simulation environment, | ||
| + | |||
| + | There are irsim tutorials online. For the and gate, you can run a simple simulation by the following sequence of irsim commands: | ||
| + | |||
| + | < | ||
| + | % ana a/a | ||
| + | % ana a/b | ||
| + | % ana a/c | ||
| + | </ | ||
| + | |||
| + | This opens a waveform window, and displays the signals '' | ||
| + | |||
| + | < | ||
| + | % h Vdd! | ||
| + | % l GND! | ||
| + | </ | ||
| + | |||
| + | This says that Vdd! is high, and GND! is low. You need these commands to setup the power supplies. | ||
| + | |||
| + | < | ||
| + | % s | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | < | ||
| + | % h a/a | ||
| + | % h a/b | ||
| + | % s | ||
| + | % l a/a | ||
| + | % s | ||
| + | </ | ||
| + | |||
| + | You can also create a text file of irsim commands (highly recommended as a general practice), and then read it in to irsim with the '' | ||