Main Content

Control the Duty Cycle of a PWM Signal Using Dashboard Blocks

This example shows how a simulation dashboard built using Dashboard blocks controls the duty cycle of a PWM signal generated by the model. The example is a modified version of the sfcndemo_pwm example. The PWM Generator block takes a duty cycle and period as inputs to generate a PWM output. You can control the source for the duty cycle using a switch.

Build the Dashboard Subsystem

To create the Dashboard subsystem in this example:

1. Add a Subsystem block to the model.

2. Delete the pre-populated contents of the subsystem.

3. Add the contents of the dashboard. The dashboard in this example includes a Rocker Switch block and a Knob block, which allow you to modify variables during simulation. The Dashboard Scope block displays the generated PWM signal.

Use areas in the Dashboard subsystem to group and label Dashboard blocks. For more information about creating areas, see Visually Organize Models Using Area Annotations.

Connect Blocks in the Model

In this model, the Rocker Switch block in the Dashboard subsystem provides the interface for selecting the duty cycle source. A Switch block with a Constant block as its control input replaces the Manual Switch in the sfcndemo_pwm model. Replacing the Manual Switch block requires three blocks but allows you to gather model controls and visualizations in a single view. The Rocker Switch block connects to the value of the Constant block. In this model, the Constant block value is set by the variable duty_cycle_source.

This model also uses the variable duty_cycle to set the magnitude of the duty cycle for both the duty cycle (constant) and duty cycle (varying) sources. The Knob block in the Dashboard subsystem connects to the duty_cycle variable, allowing you to modify its value during simulation.

The Dashboard Scope block displays the output of the PWM Generator block, allowing you to observe the generated PWM signal during simulation.

Interactively Simulate

This model uses simulation pacing to slow model execution so you can interact with the model during simulation. For more information, see Simulation Pacing Options.

Run the simulation. Use the Rocker Switch block to select the varying duty cycle input and observe the resulting PWM waveform on the Dashboard Scope block. Change the magnitude of the duty cycle using the Knob block and observe the effect on the generated PWM signal.

See Also

Blocks

Related Topics