Frequency Output

Generate and output a pulse-width-modulated square wave

Library

Real-Time Windows Target™

Description

The Frequency Output block generates a pulse-width-modulated square wave that alternates between low (0) and high (1) with a specified frequency and duty cycle. The frequency is specified in Hertz. The duty cycle is specified as a decimal fraction between 0 and 1 inclusive. This fraction specifies the amount of time that the output signal value is high (1). For example, a duty cycle of .7 specifies that the output is high 70% of the time, and low 30% of the time.

After you have added a Frequency Output block to your model, double-click the Frequency Output block to open the Block Parameters: Frequency Output dialog box.

If you specify a non-default value for Output signal frequency source or Output signal duty source, the appearance of the dialog box changes as shown below.

Parameters

Sample time

Enter a value representing how frequently you want the block to execute and interact with the I/O hardware. The block will also synchronize your model with the real-time clock at this sample rate.

    Tip   If you are using a fixed-step solver, you must enter the value you entered in the Fixed step size box from the Configuration Parameters dialog box, or an integer multiple of that value.

Maximum missed ticks

Enter the number of timer ticks that your model can lag behind the real-time kernel. When the model lags by more than this number, the block reports an error and simulation stops. Otherwise, simulation continues even if some ticks are missed.

Show "Missed Ticks" port

Select this check box to display the current number of missed ticks as a block output.

Yield CPU when waiting

Select this check box to grant other programs more CPU time while the kernel waits for a response from the hardware.

Output channels

Enter a vector that selects the output channels you are using on this board. The vector can be any valid MATLAB® vector form.

Output signal frequency source

From the list, select the source that specifies the frequency to output. The frequency is specified in Hertz. The Output signal frequency source can be either of the following:

external (Default)

The frequency is specified by an input signal. An input port appears on the block to accept the signal. A Frequency initial value and a Frequency final value may be required.

internal

The frequency is specified by a tunable parameter named Frequency. If you specify internal, Frequency replaces Frequency initial value, and Frequency final value is disabled.

Frequency

This tunable parameter appears when Output signal frequency source is internal. Specify the desired frequency in Hertz.

Frequency initial value

This parameter appears when Output signal frequency source is external. Optionally specify a frequency in Hertz. The specified frequency takes effect when you connect to the target, and persists until simulation starts, at which time the value of the frequency signal takes effect. You can use this parameter to specify initial conditions and give them time to stabilize. If no value appears, connecting to the target has no effect on the frequency.

Frequency final value

This parameter appears when Output signal frequency source is external. Optionally specify a frequency in Hertz. The specified frequency takes effect when simulation completes and persists indefinitely. Disconnecting from the target does not change the frequency. You can use this parameter to put a connected device into a neutral state after simulation. If no value appears, the frequency in effect at the end of simulation persists afterwards.

Output signal duty source

Specify the source that specifies the duty cycle. The specification is a decimal fraction between 0 and 1 inclusive that determines the amount of time that the output signal value is high (1). For example, a duty cycle of .7 specifies that the output is high 70% of the time, and low 30% of the time. Two duty cycle values have special significance:

0

The output signal is continuously low (0) regardless of the frequency specification currently in effect.

1

The output signal is continuously high (1) regardless of the frequency specification currently in effect.

From the list, select one of the following:

internal (Default)

The duty cycle is specified by a tunable parameter named Duty.

external

The duty cycle is specified by an input signal. An input port appears on the block to accept the signal. If you specify external, Duty initial value replaces Duty, and Duty final value is enabled.

Duty

This tunable parameter appears when Output signal duty source is internal. Specify the desired duty cycle as a decimal fraction between 0 and 1. Specifying 0 or 1 overrides the currently specified frequency and enforces a continuously low or high output signal for the duration of the specification.

Duty initial value

This parameter appears when Output signal duty source is external. Optionally specify a duty cycle. The specified duty cycle takes effect when you connect to the target, and persists until simulation starts. If no value appears, connecting to the target has no effect on the duty cycle. You can specify any duty cycle. Often the Duty initial value is 0 or 1, enforcing a continuously low or high initial output signal. Specifying 0 or 1 overrides any Frequency initial value.

Duty final value

This parameter appears when Output signal duty source is external. Optionally specify a duty cycle. The specified duty cycle takes effect when simulation completes and persists indefinitely. Disconnecting from the target does not change the duty cycle. If no value appears, the duty cycle in effect at the end of simulation persists indefinitely afterwards. You can specify any duty cycle. Often the Duty final value is 0 or 1, enforcing a continuously low or high initial output signal. Specifying 0 or 1 overrides any Frequency final value.

Was this topic helpful?