Variables | Functions
CONFIGURE_COUNTER

Overview

General purpose counters are the most widely used hardware resource in the framework module. The CONFIGURE_COUNTER procedure call configures a general purpose counter to either:

  1. Increment every clock cycle (when the type of the enable signal is std_logic and equal to '1').
  2. Count signal edges (when the enable parameter is a boolean expression that evaluates to TRUE).
  3. Count the number of state transitions when the enable parameter is give as a tuple of the form of (<last_state>, <current_state>)

General purpose counters are enabled by default (meaning, the optional enable signal is set to '1') and will begin incrementing upon system reset if no optional parameter is given. For any configuration, the counter will count upward until the count value reaches terminal_count - 1, where at that point, state_reg_rec(M).counter(N).done will be asserted logic '1', and the counter will rollover. In addition, if the caller specifies a transition_state other than -1, then the counter will schedule a state machine transition to the specified state one clock cycle after the state_reg_rec(M).counter(N).done signal is asserted.

Because there can be multiple counters on the same resource domain, each individual counter is identified by a counter_index. Counters on the same resource domain can also be chained together with a counter on the previous index by specifying chain for the enable of the counter with the higher index. When counters are configured for chaining, the counter on the lower index (typically counter_index 0) can accept an enable signal of type std_logic or boolean expression, whereas all counters that are chained on higher indexes must specify the value 'chain' for the enable parameter.

Usage Examples

Chaining General Purpose Counters
Multiple Clock Domain Counters

Example API Call(s):

CONFIGURE_COUNTER( 0, 128, -1, next_state_rec, state_reg_rec );
CONFIGURE_COUNTER( 0, 128, -1, next_state_rec, state_reg_rec );
CONFIGURE_COUNTER( 0, 10, st_data, next_state_rec, state_reg_rec, (st_init, st_start) );
CONFIGURE_COUNTER( 1, 10, -1, next_state_rec, state_reg_rec, sig_input(1) = '1' );
CONFIGURE_COUNTER( 1, 10, 3, next_state_rec, state_reg_rec, chain );

Call Data [ 6 parameters (5 mandatory, 1 optional) ]

Parameters
[in]counter_index[1] 0 to NUM_COUNTERS - 1
[in]terminal_count[2] integer final value (minus one) before rollover occurs
[in]transition_state[3] integer state to transition to when rollover occurs
[out]next_state_rec[4]
[in]state_reg_rec[5]
[in]enable*[6] (optional) input to enable the counter
Remarks
The enable* parameter could be of type std_logic, boolean, state_tuple, or 'chain'

Return Data

Parameters
[in]state_reg_rec(M).counter(N).value[1] [integer] count value returned from framework
[in]state_reg_rec(M).counter(N).done[2] [std_logic] value asserted before rollover (generally a strobe)
Remarks
'M' represents the resource index and 'N' represents the counter index.

Command Reference

Voice and Hotkey Commands:

See also
Configure Counter Commands

Command Parameter Mapping

Parameters
[in]counter_index[1] "index <integer>"
[in]terminal_count[2] "count <integer>"
[in]transition_state[3] "go to [state] (<state>|<integer>)"
[in]enable*[6] "enable [when] (<std_logic>|<boolean>|<state tuple>|chain)"

Command Return Data

Parameters
[in]state_reg_rec(M).counter(N).value[1] [integer] "count [<array_index>]"
[in]state_reg_rec(M).counter(N).done[2] [std_logic] "count (done|strobe)"

Notes and Warnings

Note
1) Each resource index '(M)' supports an array of general purpose counters. Thus, each individual counter must be indexed by its own array index '(N)' when making the CONFIGURE_COUNTER procedure call.
2) If a high number of counters are needed (greater than four) within a single application module, it is recommended to place some counters on another resource index.
3) General purpose counters are very useful for sending test data to other application modules when using the WRITE_FIFO_DATA API call.
4) If the enable parameter is configured with a boolean expression, the counter is configured with an internal edge detection circuit and increments each time expression evaluates to TRUE. Counters with edge detection enabled will increment on the second rising edge after the boolean expression becomes TRUE.
5) The boolean expression must not contain 'and' or 'or' expression. If a compound operation is necessary, first create a signal assigment then create a boolean expression using that signal.

See also
RESET_COUNTER
TIME_COUNTER
TRANSITION
WRITE_FIFO_DATA

Types

GENERAL_PURPOSE_COUNT_ARRAY  ( 0 to NUM_GENERAL_PURPOSE_COUNTERS- 1 ) COUNT_REC
 array of counters (field of state_reg_rec that needs to be indexed)

Records

COUNT_REC 
value natural
 count value returned from the framework by the API Call
done std_logic
 signal indicating terminal_count - 1 (typically a strobe)

Procedures

  CONFIGURE_COUNTER(
counter_index: natural
terminal_count: integer
transition_state: STATE_INTEGER
signal next_state_rec: out NSR
state_reg_rec: in SRR
enable: std_logic ' 1 '
)
  CONFIGURE_COUNTER(
counter_index: natural
terminal_count: integer
transition_state: STATE_INTEGER
signal next_state_rec: out NSR_ARRAY
state_reg_rec: in SRR_ARRAY
enable: std_logic ' 1 '
)
 0verloaded for array next_state_rec and state_reg_rec. Optional std_logic, boolean, and state_tuple enable signal.