|On this page…|
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.
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.
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.
|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 > SimElectronics > Integrated Circuits
Simscape > SimElectronics > Semiconductor Devices
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:
This function also selects the Simulink ode15s solver.
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 SimElectronics network. This block does not have any parameters.
Generate the sinusoidal control signal using the Sine Wave block.
Amplitude = 0.5e4
Bias = 1e4
Frequency = pi/5e-4
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
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.080e4. Set the Gain, A parameter to 7e4.
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.
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.
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.
Capacitance = 2.5e-9
Initial voltage = 0.08
This value starts the oscillation in the feedback loop.
Series resistance = 0
Constant voltage = 0
Resistance = 10000
Resistance = 1000
Resistance = 10000
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 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.
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.
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:
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.
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