Triangle Wave Generator Model

Overview of Triangle Wave Generator Example

In this example, you model a triangle wave generator using SimElectronics® electrical blocks and custom SimElectronics electrical blocks, and then look at the voltage at the wave generator output.

You use a classic circuit configuration consisting of an integrator and a noninverting amplifier to generate the triangle wave, and use datasheets to specify block parameters. For more information, see Parameterizing Blocks from Datasheets.

To see the completed model, open the Triangle Wave Generator example.

Selecting Blocks to Represent System Components

First, you select the blocks to represent the input signal, the triangle wave generator, and the output signal display.

You model the triangle wave generator with a set of physical blocks bracketed by a Simulink-PS Converter block and a PS-Simulink Converter block. The wave generator consists of:

  • Two operational amplifier blocks

  • Resistors and a capacitor that work with the operational amplifiers to create the integrator and noninverting amplifier

  • Simulink-PS Converter and PS-Simulink Converter blocks. The function of the Simulink-PS Converter and PS-Simulink Converter blocks is to bridge the physical part of the model, which uses physical signals, and the rest of the model, which uses unitless Simulink® signals.

You have a manufacturer datasheet for the two operational amplifiers you want to model. Later in the example, you use the datasheet to parameterize the SimElectronics Band-Limited Op-Amp block.

The following table describes the role of the blocks that represent the system components.

Block

Description

Sine Wave

Generates a sinusoidal signal that controls the resistance of the Variable Resistor block.

Simulink-PS ConverterConverts the sinusoidal Simulink signal to a physical signal.
Solver Configuration

Defines solver settings that apply to all physical modeling blocks.

Electrical Reference

Provides the electrical ground.

CapacitorWorks with an operational amplifier and resistor block to create the integrator.
ResistorWorks with the operational amplifier and capacitor blocks to create the integrator and noninverting amplifier.
Variable ResistorSupplies a time-varying resistance that adjusts the gain of the integrator, which in turn varies the frequency and amplitude of the generated triangular wave.
DC Voltage Source

Generates a DC reference signal for the operational amplifier block of the noninverting amplifier.

Voltage Sensor

Converts the electrical voltage at the output of the integrator into a physical signal proportional to the current.

PS-Simulink ConverterConverts the output physical signal to a Simulink signal.
Scope

Displays the triangular output wave.

Band-Limited Op-AmpWorks with the capacitor and resistor to create an integrator and a noninverting amplifier.
DiodeLimit the output of the Band-Limited Op-Amp block, to make the output waveform independent of supply voltage.

Building the Model

Create a Simulink model, add blocks to the model, and connect the blocks.

  1. Create a new model.

  2. Add to the model the blocks listed in the following table. The Library Path column of the table specifies the hierarchical path to each block.

    Block

    Library Path

    Quantity

    Sine WaveSimulink > Sources

    1

    Simulink-PS ConverterSimscape > Utilities

    1

    Solver ConfigurationSimscape > Utilities

    1

    Electrical ReferenceSimscape > Foundation Library > Electrical > Electrical Elements

    1

    CapacitorSimscape > Foundation Library > Electrical > Electrical Elements

    1

    ResistorSimscape > Foundation Library > Electrical > Electrical Elements

    3

    Variable ResistorSimscape > Foundation Library > Electrical > Electrical Elements

    1

    DC Voltage SourceSimscape > Foundation Library > Electrical > Electrical Sources

    1

    Voltage SensorSimscape > Foundation Library > Electrical > Electrical Sensors

    1

    PS-Simulink ConverterSimscape > Utilities

    1

    ScopeSimulink > Commonly Used Blocks

    1

    Band-Limited Op-Amp

    Simscape > SimElectronics > Integrated Circuits

    2

    Diode

    Simscape > SimElectronics > Semiconductor Devices

    2

      Note:   You can use the Simscape™ function ssc_new with a domain type of electrical to create a Simscape model that contains the following blocks:

      • Simulink-PS Converter

      • PS-Simulink Converter

      • Scope

      • Solver Configuration

      • Electrical Reference

      This function also selects the Simulink ode15s solver.

  3. Connect the blocks as shown in the following figure.

Now you are ready to specify block parameters.

Specifying Model Parameters

Specify the following parameters to represent the behavior of the system components:

Model Setup Parameters

The following blocks specify model information that is not specific to a particular block:

  • Solver Configuration

  • Electrical Reference

As with Simscape models, you must include a Solver Configuration block in each topologically distinct physical network. This example has a single physical network, so use one Solver Configuration block with the default parameter values.

You must include an Electrical Reference block in each SimElectronics network. This block does not have any parameters.

Input Signal Parameters

Generate the sinusoidal control signal using the Sine Wave block.

Set the Sine Wave block parameters as follows:

  • Amplitude = 0.5e4

  • Bias = 1e4

  • Frequency = pi/5e-4

Triangle Wave Generator Parameters

Configure the blocks that model the physical system that generates the triangle wave:

  • Integrator — Band-Limited Op-Amp, Capacitor, and Resistor blocks

  • Noninverting amplifier — Band-Limited Op-Amp1, Resistor2, and Variable Resistor blocks

  • Resistor1

  • Diode and Diode1

  • Simulink-PS Converter and PS-Simulink Converter blocks that bridge the physical part of the model and the Simulink part of the model.

  1. Accept the default parameters for the Simulink-PS Converter block. These parameters establish the units of the physical signal at the block output such that they match the expected default units of the Variable Resistor block input.

  2. Set the two Band-Limited Op-Amp block parameters for the LM7301 device with a +–20V power supply:

    • The datatsheet gives the gain as 97dB, which is equivalent to 10^(97/20)=7.1e4. Set the Gain, A parameter to 71e4.

    • The datatsheet gives input resistance as 39Mohms. Set Input resistance, Rin to 39e6.

    • Set Output resistance, Rout to 0 ohms. The datatsheet does not quote a value for Rout, but the term is insignificant compared to the output resistor that it drives.

    • Set minimum and maximum output voltages to –20 and +20 volts, respectively.

    • The datatsheet gives the maximum slew rate as 1.25V/μs. Set the Maximum slew rate, Vdot parameter to 1.25e6 V/s.

  3. Set the two Diode block parameters for a 4.3V zener diode. To model a BZX384-B4V3, set block parameters as follows:

    • On the Main tab, set Diode model to Piecewise Linear Zener. This selects a simplified zener diode model that is more than adequate to test the correct operation of this circuit.

    • Leave the Forward voltage as 0.6V — this is a typical value for most diodes.

    • The datatsheet gives the forward current as 250mA when the forward voltage is 1V. So that the Diode block matches this, set the On resistance to (1V – 0.6V)/250mA = 1.6 ohms.

    • The datatsheet gives the reverse leakage current as 3μA at a reverse voltage of 1V. Therefore, set the Off conductance to 3μA/1V = 3e-6 S.

    • The datatsheet gives the reverse voltage as 4.3V. On the Reverse Breakdown tab, set the Reverse breakdown voltage Vz to 4.3 V.

    • Set the Zener resistance Rz to a suitably small number. The datatsheet quotes the zener voltage for a reverse current of 5mA. For the Diode block to be representative of the real device, the simulated reverse voltage should be close to 4.3V at 5mA. As Rz tends to zero, the reverse breakdown voltage will tend to Vz regardless of current, as the voltage-current gradient becomes infinite. However, for good numerical properties, Rz must not be made too small. If, say, you allow a 0.01V error on the zener voltage at 5mA, then Rz will be 0.01V/5mA = 2 ohms. Set the Zener resistance Rz parameter to this value.

  4. The Voltage Sensor block does not have any parameters.

  5. Accept the default parameters for the Variable Resistor block. These parameters establish the units of the physical signal at the block output such that they match the expected default units of the Variable Resistor block input.

  6. Set the Capacitor block parameters as follows:

    • Capacitance = 2.5e-9

    • Initial voltage = 0.08

      This value starts the oscillation in the feedback loop.

    • Series resistance = 0

  7. Set the DC Voltage Source block parameters as follows:

    • Constant voltage = 0

  8. Set the Resistor block parameters as follows:

    • Resistance = 10000

  9. Set the Resistor1 block parameters as follows:

    • Resistance = 1000

  10. Set the Resistor2 block parameters as follows:

    • Resistance = 10000

  11. Accept the default parameters for the PS-Simulink Converter block. These parameters establish the units of the physical signal at the block output such that they match the expected default units of the Scope block input.

Signal Display Parameters

Specify the parameters of the Scope block to display the triangular output signal.

Double-click the Scope block and then double-click the Parameters button to open the Scope parameters dialog box. On the History tab, clear the Limit data points to last check box.

Configuring the Solver Parameters

Configure the solver parameters to use a continuous-time solver because SimElectronics models only run with a continuous-time solver. You also change the simulation end time, tighten the relative tolerance for a more accurate simulation, and remove the limit on the number of simulation data points Simulink saves.

  1. In the model window, select Simulation > Model Configuration Parameters to open the Configuration Parameters dialog box.

  2. In the Solver category in the Select tree on the left side of the dialog box:

    • Enter 2000e-6 for the Stop time parameter value.

    • Select ode23t (Mod. stiff/Trapezoidal) from the Solver list.

    • Enter 4e-5 for the Max step size parameter value.

    • Enter 1e-6 for the Relative tolerance parameter value.

  3. In the Data Import/Export category in the Select tree:

    • Clear the Limit data points to last check box.

  4. Click OK.

For more information about configuring solver parameters, see Simulating an Electronic System.

Running the Simulation and Analyzing the Results

Run the simulation and plot the results.

In the model window, select Simulation > Run to run the simulation.

To view the triangle wave in the Scope window, double-click the Scope block. You can do this before or after you run the simulation.

The following plot shows the voltage waveform. As the resistance of the Variable Resistor block increases, the amplitude of the output waveform increases and the frequency decreases.

Triangle Waveform Voltage

Was this topic helpful?