Main Content

N-Sample Enable

Output ones or zeros for specified number of sample times

  • N-Sample Enable block

Libraries:
DSP System Toolbox / Sources
DSP System Toolbox / Signal Management / Switches and Counters

Description

The N-Sample Enable block outputs the inactive value (0 or 1, whichever is not selected in the Active level parameter) during the first N sample times, where N is the Trigger count value. Beginning with output sample N+1, the block outputs the active value (1 or 0, whichever you select in the Active level parameter) until a reset event occurs or the simulation terminates.

The output of the block is always a scalar.

The Reset input check box enables the Rst input port. At any time during the count, a trigger event at the input port resets the counter to its initial state. You specify the type of trigger event using the Trigger type parameter. This block supports triggered subsystems when you select the Reset input check box.

Examples

expand all

This example shows how to use the Counter block to count down through a range of numbers. The Pulse Generator block drives the Dec port of the Counter block, and the N-Sample Enable block triggers the Rst port. All inputs to and outputs from the Counter block are multiplexed into a single To Workspace block using a 4-port Mux block.

The following figure shows the first 22 samples of the four-column output, dsp_examples_yout.

You can see that the seventh input sample to both the Dec and Rst ports of the Counter block represent trigger events (rising edges). When this occurs, the block first resets the counter to its initial value of 5, and then immediately decrements the counter to 4. When the counter reaches its minimum value of 0, the block restarts the counter at its maximum value of 20 the next time a trigger event occurs at the Dec port.

Ports

Input

expand all

Reset input signal, specified as a scalar. At any time during the count, a trigger event at the input port resets the counter to its initial state.

Tip

The N-Sample Enable block supports triggered subsystems when you select the Reset input check box to enable the Rst input port.

Dependencies

To enable this input port, select the Reset input check box.

Data Types: Boolean

Output

expand all

Scalar output containing the inactive value (0 or 1, whichever is not selected in the Active level parameter) during the first N sample times, where N is the Trigger count value. Beginning with output sample N+1, the block outputs the active value (1 or 0, whichever you select in the Active level parameter) until a reset event occurs or the simulation terminates.

Data Types: Boolean

Parameters

expand all

Specify the number of samples for which the block outputs the active value as a scalar integer, greater than or equal to zero.

Tunable: Yes

Specify the value to output after the first N sample times as 0 or 1.

Tunable: Yes

To enable the reset (Rst) input port, select this check box. When you clear this check box, the Rst input port is disabled.

Tip

When you select the Reset input check box, the N-Sample Enable block supports triggered subsystems.

Select type of event that triggers a reset when the Rst port is enabled.

You can specify the triggering event as:

  • Rising edge — Triggers a reset operation when the Rst input does one of the following:

    • Rises from a negative value to a positive value or zero

    • Rises from zero to a positive value, where the rise is not a continuation of a rise from a negative value to zero (see the following figure)

  • Falling edge — Triggers a reset operation when the Rst input does one of the following:

    • Falls from a positive value to a negative value or zero

    • Falls from zero to a negative value, where the fall is not a continuation of a fall from a positive value to zero (see the following figure)

  • Either edge — Triggers a reset operation when the Rst input is a Rising edge or Falling edge.

  • Non-zero sample — Triggers a reset operation at each sample time that the Rst input is not zero.

Dependencies

To enable this parameter, select the Reset input check box.

Specify the sample period, Ts, for the block's counter as a positive finite scalar. The block switches from the active value to the inactive value at t=Ts(N+1).

Specify the output data type as Logical or Boolean.

Block Characteristics

Data Types

Boolean | double

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a

See Also

Blocks