Basics

Comments

Reference

// single line comment

/*
 * multi-line comment
 */

Identifiers

Reference

Simple:

clk
out_p
n$12

Escaped:

\out+

Compiler Directives

Reference

`define size 8

`include "disciplines.vams"

`ifdef __VAMS_ENABLE__
    ...
`else
    ...
`endif

`ifndef ...

`resetall

`timescale 1s/1ns

Integers

Reference

63         // simple 32-bit integer 63
'b11_1001  // unsized unsigned integer specified as binary number 11_1001
'o77       // unsized unsigned integer specified as octal number 0o77
'h3F       // unsized unsigned integer specified as hexadecimal number 0x3F
'd63       // unsized unsigned integer specified as decimal number 63
12'h3f     // 12-bit unsigned integer specified as hexadecimal number 0x3F
6'sd0      // 6-bit signed integer specified as decimal number
64'o0      // 64-bit unsigned integer octal 0 (0 padded)
8'hX       // 8-bit unsigned integer 8'bXXXX_XXXX (X padded)
8'hFFFX    // 8-bit unsigned integer 8'b1111_XXXX (truncated)

Reals

Reference

3.14
0.1
1.2e12
236.123_763e-12
1.3u
5.45K

SI scale factors: T, G, M, K, k, m, u, n, p, f, a

Constants

Reference

include "constants.vams

Mathematical constants:

`M_PI         // pi
`M_TWO_PI     // 2*pi
`M_PI_2       // pi/2
`M_PI_4       // pi/4
`M_1_PI       // 1/pi
`M_2_PI       // 2/pi
`M_2_SQRTPI   // 2/rt(pi)
`M_E          // e
`M_LOG2E      // log2(e)
`M_LOG10E     // log10(e)
`M_LN2        // ln(2)
`M_LN10       // ln(10)
`M_SQRT2      // rt(2)
`M_SQRT1_2    // rt(1/2)

Physical constants:

`P_Q          // charge of an electron (1.602176462e-19 C)
`P_C          // speed of light (2.99792458e8 m/s)
`P_K          // Boltzmann's constant (1.3806503e-23 J/K)
`P_H          // Planck's constant (6.626076e-34 J-s)
`P_EPS0       // permittivity of a vacuum (8.854187817e-12 F/m)
`P_U0         // permeability of a vacuum (4*pi*1e-7 H/m)
`P_CELSIUS0   // 0 Celsius (273.15 K)

Strings

Reference

Example:

"Hello world!\n"

Special characters:

\n    newline
\t    tab
\\    backslash
\ddd  character represented by 3 digit octal code ddd

Arrays

Reference

Packed Literals:

'{4, 8, 12, 16, 20}
'{0, {2{1, 2}}}  -->  '{0, 1, 2, 1, 2}

Unpacked Literals:

{4, 8, 12, 16, 20}
{0, {2{1, 2}}}  -->  {0, 1, 2, 1, 2}

Wires

Reference

Declaration:

wire enable;               // simple scalar wire
wire [15:0] gain;          // 16-bit unsigned bus
wire signed [11:0] offset; // 12-bit signed bus
wire out = ~(in1 & in2);   // declaration combined with assignment

Discrete Wire Types

wire, tri

resolves to x if conflicting drivers

wand, triand

resolves to 0 is any driver is 0

wor, trior

resolves to 1 is any driver is 1

trireg

output retains value if undriven

tri0

resolves to 0 if undriven

tri1

resolves to 1 if undriven

supply0

resolves to 0

supply1

resolves to 1

wreal

real valued

Default wire type is ‘wire’.

Assigning values to discrete wires:

assign out = ~(in1 & in2);

Continuous Wire Types

Declaration:

wire out;
electrical out;
wire [3:0] in;
electrical [3:0] in;

or simply:

electrical out;
electrical [3:0] in;

Ground

Declaration:

electrical gnd;
ground gnd;

Branches

Reference

Declaration:

branch (p, n) res;
branch (out, gnd) rload, cload;

Access:

V(res)     // access voltage on named branch *res*
I(rload)   // access current on named branch *rload*
V(out)     // create unnamed branch from out to ground, access voltage
I(out)     // create unnamed branch from out to ground, access current
V(out,gnd) // create unnamed branch from out to gnd, access voltage
I(out,gnd) // create unnamed branch from out to gnd, access current

Variables

Reference

Declaration:

reg enable;               // single bit value (0, 1, x, or z)
reg [15:0] in;            // 16-bit unsigned value
reg signed [11:0] offset; // 12-bit signed value

integer in;               // 32-bit integer
integer [3:0] counts;     // integer array

genvar i;                 // integer with restricted semantics for generators

real midpoint;            // real value
real [7:0] calib;         // real array

reg en1, en2;
reg [7:0] off1, off2      // both are 8-bit buses

With initialization (discrete variables):

reg enable = 0;
reg [15:0] in = 16'hFFFF;
integer size = 8;
integer [3:0] counts = {0,0,0,0};
real midpoint = 2.5;

See analog initial process to see how to initialize analog variables.