A Design Example - 2-bit Counter

-- Notes Page --


In this example, we show a model for a simple 2-bit counter which counts clock pulses. The component has clock as an input, and two outputs which represent the LSB and MSB of a two-bit unsigned number.

There are several constructs that you may not have seen before. bit'val(count_value mod 2) is a function which returns a value of type bit. count_value is a natural number (i.e. an integer greater than, or equal to, zero). count_value mod 2 returns the LSB value of the counter value, but the LSB value is of type natural. Since we want the LSB to be of type bit instead, we cast it by using the 'val (read as "tic val") attribute on the type bit.

Another possibly new concept shown here is generic. A generic is like a port except it is treated as a constant in the architecture. Thus, prop_delay is a constant which can be set by the modeler when the entity count2 is instantiated as a component. If the modeler decides not to explicitly set the value of prop_delay, its value defaults to 10 nanoseconds.