build and simulate a simple circuit -凯发k8网页登录

main content

build and simulate a simple circuit

in this example, you model a triangle wave generator using simscape™ electrical™ blocks and custom simscape 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 .

to see the completed model, open the example.

select 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. 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 whose function 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 electrical 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

scope

displays the triangular output wave

simulink-ps converterconverts the sinusoidal simulink signal to a physical signal
solver configuration

defines solver settings that apply to all physical modeling blocks

ps-simulink converterconverts the output physical signal to a simulink signal
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

electrical reference

provides the electrical ground

band-limited op-ampworks with the capacitor and resistor to create an integrator and a noninverting amplifier
diodelimits the output of the band-limited op-amp block, to make the output waveform independent of supply voltage

build 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 this table. the library path column of the table specifies the hierarchical path to each block.

    block

    library path

    quantity

    sine wavesimulink > sources

    1

    scopesimulink > commonly used blocks

    1

    simulink-ps convertersimscape > utilities

    1

    solver configurationsimscape > utilities

    1

    ps-simulink converter simscape > utilities

    1

    capacitorsimscape > foundation library > electrical > electrical elements

    1

    resistorsimscape > foundation library > electrical > electrical elements

    3

    variable resistorsimscape > foundation library > electrical > electrical elements

    1

    electrical referencesimscape > foundation library > electrical > electrical elements

    2

    dc voltage sourcesimscape > foundation library > electrical > electrical sources

    1

    voltage sensorsimscape > foundation library > electrical > electrical sensors

    1

    band-limited op-amp

    simscape > electrical > integrated circuits

    2

    diode

    simscape > electrical > semiconductor & converters

    2

    note

    you can use the simscape function with a domain type of electrical to create a simscape model that contains these blocks:

    • simulink-ps converter

    • ps-simulink converter

    • scope

    • solver configuration

    • electrical reference

  3. rename and connect the blocks as shown in the diagram. the blocks in the triangle wave generator circuit are organized in two stages. the comparator stage contains a comparator constructed from a band-limited op-amp block and two resistor blocks. the integrator stage contains an integrator constructed from another band-limited op-amp block, a resistor, a capacitor, and electrical reference.

specify model parameters

specify these parameters to represent the behavior of the system components:

model setup parameters

these 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 simscape electrical 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:

  • amplitude0.5e4

  • bias1e4

  • frequencypi/5e-4

triangle wave generator parameters

configure the blocks modeling 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

  • variable resistor

  • 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 datasheet gives the gain as 97 db, which is equivalent to 10 ^ ( 97 / 20 ) = 7.1e4. set the gain, a parameter to 7.1e4.

    • the datasheet gives input resistance as 39 mohms. set input resistance, rin to 39e6.

    • set output resistance, rout to 0 ohms. the datasheet 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 v and 20 v, respectively.

    • the datasheet gives the maximum slew rate as 1.25 v/μs. set the maximum slew rate, vdot parameter to 1.25e6 v/s.

    • set the bandwidth to 4e6.

  3. set the two diode block parameters for a 4.3 v zener diode. to model a bzx384-b4v3, set block parameters as follows:

    • on the main tab, set diode model to piecewise linear. 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.6 v — this is a typical value for most diodes.

    • the datasheet gives the forward current as 250 ma when the forward voltage is 1v. so that the diode block matches this, set the on resistance to (1 v – 0.6 v) / 250 ma = 1.6 ohms.

    • the datasheet gives the reverse leakage current as 3 μa at a reverse voltage of 1 v. therefore, set the off conductance to 3 μa / 1 v = 3e-6 s.

    • the datasheet gives the reverse voltage as 4.3 v. on the breakdown tab, set the reverse breakdown voltage vz to 4.3 v.

    • set the zener resistance rz to a suitably small number. the datasheet quotes the zener voltage for a reverse current of 5 ma. 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 tends 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.01 v error on the zener voltage at 5 ma, then rz is 0.01 v / 5 ma = 2 ohms. set the zener resistance 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:

    • capacitance2.5e-9

    • capacitor voltage0.08

      this value starts the oscillation in the feedback loop. it is found in the variables tab.

    • series resistance0

  7. set the dc voltage source block constant voltageparameter to 0.

  8. set the resistor r3 block resistance parameter to 10000.

  9. set the resistor r1 block resistance parameter to 1000.

  10. set the resistor r2 block resistance parameter to 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 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

configure the solver parameters to use a continuous-time solver.simscape electrical models only run with a continuous-time solver when the simscape solver configuration block has its local solver parameter cleared. 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 modeling > model settings to open the configuration parameters dialog box.

  2. in the solver category in the 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 .

simulate model and analyze 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

网站地图