In this example, you model a triangle wave generator using Simscape™ Electronics™ electrical blocks and custom Simscape Electronics 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.
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 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 Simscape Electronics Band-Limited Op-Amp block.
The following table describes the role of the blocks that represent the system components.
Generates a sinusoidal signal that controls the resistance of the Variable Resistor block.
|Simulink-PS Converter||Converts the sinusoidal Simulink signal to a physical signal.|
Defines solver settings that apply to all physical modeling blocks.
Provides the electrical ground.
|Capacitor||Works with an operational amplifier and resistor block to create the integrator.|
|Resistor||Works with the operational amplifier and capacitor blocks to create the integrator and noninverting amplifier.|
|Variable Resistor||Supplies 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.
Converts the electrical voltage at the output of the integrator into a physical signal proportional to the current.
|PS-Simulink Converter||Converts the output physical signal to a Simulink signal.|
Displays the triangular output wave.
|Band-Limited Op-Amp||Works with the capacitor and resistor to create an integrator and a noninverting amplifier.|
|Diode||Limit the output of the Band-Limited Op-Amp block, to make the output waveform independent of supply voltage.|
Create a Simulink model, add blocks to the model, and connect the blocks.
Create a new model.
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.
|Sine Wave||Simulink > Sources|
|Simulink-PS Converter||Simscape > Utilities|
|Solver Configuration||Simscape > Utilities|
|Electrical Reference||Simscape > Foundation Library > Electrical > Electrical Elements|
|Capacitor||Simscape > Foundation Library > Electrical > Electrical Elements|
|Resistor||Simscape > Foundation Library > Electrical > Electrical Elements|
|Variable Resistor||Simscape > Foundation Library > Electrical > Electrical Elements|
|DC Voltage Source||Simscape > Foundation Library > Electrical > Electrical Sources|
|Voltage Sensor||Simscape > Foundation Library > Electrical > Electrical Sensors|
|PS-Simulink Converter||Simscape > Utilities|
|Scope||Simulink > Commonly Used Blocks|
Simscape > Electronics > Integrated Circuits
Simscape > Electronics > Semiconductor Devices
You can use the Simscape function
This function also selects the Simulink
Rename and connect the blocks as shown in the diagram. The diagram shows that the blocks in the triangle wave generator circuit are organized in two stages. The first stage is a comparator constructed from a Band-Limited Op-Amp block and two Resistor blocks. The second stage is an integrator constructed from a second Band-Limited Op-Amp block, third Resistor, Capacitor, and Electrical Reference.
Now you are ready to specify block parameters.
Specify the following parameters to represent the behavior of the system components:
The following blocks specify model information that is not specific to a particular block:
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 Simscape Electronics network. This block does not have any parameters.
Generate the sinusoidal control signal using the Sine Wave block.
Set the Sine Wave block parameters as follows:
Configure the blocks that model the physical system that generates the triangle wave:
Integrator stage — Band-Limited Op-Amp, Capacitor, and Resistor block R3
Comparator stage — Band-Limited Op-Amp1, Resistor blocks R1 and R2
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.
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.
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
The datatsheet gives input resistance as 39Mohms.
Set Input resistance, Rin to
Set Output resistance, Rout to
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
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
Linear Zener. This selects a simplified zener diode
model that is more than adequate to test the correct operation of
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
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 =
The datatsheet gives the reverse voltage as 4.3V.
On the Reverse Breakdown tab, set the Reverse breakdown
voltage Vz to
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.
The Voltage Sensor block does not have any parameters.
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.
Set the Capacitor block parameters as follows:
Initial voltage =
This value starts the oscillation in the feedback loop.
Series resistance =
Set the DC Voltage Source block parameters as follows:
Constant voltage =
Set the Resistor R3 block parameters as follows:
Set the Resistor R1 block parameters as follows:
Set the Resistor R2 block parameters as follows:
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.
Specify the parameters of the Scope block to display the triangular output signal.
Double-click the Scope block and then click the View > Configuration Properties to open the Scope Configuration Properties dialog box. On the Logging tab, clear the Limit data points to last check box.
Configure the solver parameters to use a continuous-time solver because Simscape Electronics 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.
In the model window, select Simulation > Model Configuration Parameters to open the Configuration Parameters dialog box.
In the Solver category in the Select tree on the left side of the dialog box:
2000e-6 for the Stop
time parameter value.
ode23t (Mod. stiff/Trapezoidal) from
the Solver list.
4e-5 for the Max
step size parameter value.
1e-6 for the Relative
tolerance parameter value.
In the Data Import/Export category in the Select tree:
Clear the Limit data points to last check box.
For more information about configuring solver parameters, see Simulating an Electronic System.
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