Product Documentation
Spectre Circuit Simulator and Accelerated Parallel Simulator RF Analysis in ADE Explorer User Guide
Product Version 23.1, June 2023

10


Cosimulation with MATLAB® and Simulink®

This chapter describes how to set up and use a cosimulation link between the MATLAB® and Simulink® system-level simulation environment and Spectre® circuit simulator RF analysis (SpectreRF). The sections in this chapter are:

Introduction to Cosimulation with MATLAB

Cosimulation combines the best of system-level simulation with lower-level analog and RF simulation. Simulink provides large libraries of DSP algorithms for generating complicated signals and post processing while SpectreRF supports transient and envelope analysis of common RF and communication circuits such as mixers, oscillators, sample and holds, and switched capacitor filters at both the transistor and behavioral levels.

Cosimulation makes it easier

The system-level design in Simulink serves as a golden reference. System designers can use the Simulink system-level design as a testbench for implementing and simulating the design. Unfortunately, when system-level designs are simulated by themselves, the effects originating from subsystems are often not considered. With cosimulation, system designers can create low-level models of critical analog blocks and use these models one at a time to analyze the performance impact of individual blocks on the system-level simulation.

Software Requirements

Cadence recommends that you use Cadence software version MMSIM 7.1 or later.

Setting Up and Running a Cosimulation

To prepare for and run a cosimulation,

  1. Connect the coupler block into the system-level Simulink schematic.
  2. Determine how you want to start and run the cosimulation.
  3. Generate a netlist for the lower-level block that reflects how you want to start and run the cosimulation.
  4. Run the cosimulation.

These steps are described in greater detail in the following sections.

Before you continue, however, be sure that the programs are ready to run.

Connecting the Coupler Block Into the System-Level Simulink Schematic

To prepare the Simulink part of the design for cosimulation,

  1. Start MATLAB, by typing
    matlab &
    The Simulink library opens.
    This library contains the coupler module (distinguished by the Cadence logo and labeled SpectreRF Engine). You can insert the coupler module in any Simulink design by dragging and dropping it from this library.
  2. Open your testbench or high-level design.
  3. Drag and drop the SpectreRF Engine coupler block into the testbench and place it in the design.
  4. Connect the SpectreRF Engine block into the design.
    To make a signal connection, move the mouse pointer over the module pin. The pointer changes to a cross. Press the left mouse button, move the cursor to the destination pin and release the button.
  5. Double-click the SpectreRF Engine block.
    This opens the Block Parameters: SpectreRF Engine form where you can edit the coupler block’s parameter values.
    The fields have the following meanings:
    Field Meaning

    Number of input pins

    The number of input pins to the SpectreRF Engine block (0…100). The input to the block is the input signal from the Simulink design.

    Number of output pins

    The number of output pins from the SpectreRF Engine block (0…100). The output from the block is the signal generated by the SpectreRF simulator.

    Frame size

    The number of samples per frame (any positive integer or -1; default: -1). Allows you to use the coupler in a loop where frame size inheritance does not work. Simulink automatically detects conflicting frame sizes. Set this value to -1 to inherit the frame size from the input.

    Sample time

    Sample period of the block, in seconds (default: -1). The Sample time is the frame period, not the time between the samples inside the frame. Allows the coupler to have only outputs, where the Simulink coupler acts as a source and defines a Sample time. Also allows the coupler to have only inputs. Set this value to -1 to inherit the sample period of the connected blocks. See the MATLAB and Simulink Help menu for more information on Sample time propagation.

    Socket port

    The number of the service that is identified by TCP/IP. Normally, the system reverses port numbers less than 1024, so this value can range from 1024 to 65535 (default: 38520).

    Simulation response timeout

    Maximum time, in seconds, to wait for an answer from the SpectreRF simulator during simulation. Increase this time if the simulator requires a long calculation time for each sample or frame (default: 120).

    Socket mode

    TCP or UDP. Choose UDP if frame size is less 50. TCP and UDP are two different translate protocols in TCP/IP. Without CRC, UDP is usually faster in a good net environment with small data packages and TCP is usually better for large data packages.

    Spectre command

    Used to run a SpectreRF simulation. This parameter enables a use mode where SpectreRF is called internally by the Simulink simulation.

    Show engine port labels

    If checked, the SpectreRF Engine shows label information.

  6. Set the number of input pins and output pins as well as any other parameters you need to set.
  7. Note the Spectre command field but do not change the value now.
    Depending on how you choose to run the cosimulation, you might need to return to this field and type in a spectre command.
  8. Click OK.
    The form closes and the SpectreRF Engine block is updated with the correct number of pins.
  9. (Optional) Make other necessary changes in the Simulink testbench window.
    For example,
    • Choose Format – Port/Signal Displays – Signal Dimensions.
      This switches the signal dimension display on so you can see details of framed signals.
    • Choose View – Simulink library to display the library browser. Double-click Math Operations.
      The library appears. Here you can select Simulink converters, such as a Complex to Real-Imag block. Drag and drop blocks into the schematic and connect them as necessary.

    Double-click any placed blocks and set appropriate values.
  10. Choose Simulation – Configuration Parameters.
    The Configuration Parameters form opens.
  11. In the Stop time field, set the stop time.
  12. Click OK.
    The Configuration Parameters form closes.
  13. Save the modified design by choosing file – save as.

This completes the necessary modifications to the Simulink testbench.

Determining How You Want to Start and Run the Cosimulation

There are three ways to run a cosimulation, after all the setup is finished.

  1. You can start the two applications (SpectreRF and MATLAB) separately.
    This method is appropriate if you need to be able to modify both the system-level Simulink design and the analog circuit.
  2. You can start ADE Explorer and arrange to have MATLAB start automatically.
    This method is appropriate if you are an analog design who needs to validate a circuit with system-level design input and output.
  3. You can start MATLAB and arrange to have SpectreRF start automatically.
    This method is appropriate if you are a system-level designer, because, after set up, you can use the SpectreRF Engine just like another block in Simulink.

The setup differs for each of these approaches so it is useful to decide which is most appropriate for your design before continuing.

Generating a Netlist for the Lower-Level Block

The previous section describes how to insert a coupler block into the system-level design. That defines one end of the connection but you must still establish a connection with the lower-level analog block that is simulated by SpectreRF. To do that, you insert a cosim statement into the netlist, either by hand or by using the ADE environment.

Preparing the Netlist When Using ADE Explorer

This section describes how to prepare a netlist for cosimulation using the Analog Design Environment (ADE).

  1. Start the virtuoso tool.
    virtuoso &
    The recommended version of virtuoso is release IC6.1.4 or later.
  2. Open the schematic view of the cell.
    For example,
  3. Open the Virtuoso Analog Design Environment from the schematic editor by choosing Launch – ADE Explorer.
    The Launch ADE Explorer form appears.
  4. In this form, select Open Existing View and click OK.
  5. Choose Setup – Matlab/Simulink – Setting.
    The Cosimulation Options form appears.
  6. In the Cosimulation Options form, click the Select button located beside Cosimulation inputs. Switch to the schematic viewer, where you see the following information below the schematic.
    Select source instance as cosimulation inputs. Press Esc when done.
    Select the sources (which are connected to the outputs from the Simulink level of the design), then press the Esc key.
  7. In the Cosimulation Options form, click the Select button beside Cosimulation outputs. Switch to the schematic viewer, where you see the following information below the schematic.
    Select Net/Terminal as cosimulation outputs. Press Esc when done
    Select the outputs (which are connected to the inputs at the Simulink level of the design), then press the Esc key.
    The Cosimulation Options form looks something like this:
  8. Ensure that the value of Cosimulation socket port is the same as the port value of the SpectreRF Engine block defined in “Connecting the Coupler Block Into the System-Level Simulink Schematic”.
  9. In the Cosimulation Options form, select Enabled.
  10. Examine the possible values for the Start MATLAB field.
    Value Behavior

    now

    ADE launches a MATLAB session and opens a MATLAB desktop that is no different than it would be if you launched it manually. When you use the now value, you must start the simulation in the Simulink design before starting the SpectreRF simulation.

    Using the now value is a good way to test whether ADE can start MATLAB and open the design successfully.

    before Simulation

    ADE launches an internal MATLAB session and no MATLAB desktop appears. ADE opens the specified MATLAB design and initiates the MATLAB simulation before Spectre simulation starts. ADE starts MATLAB once but cannot start it again before you close the first session.

    Cadence suggests using the now value as a test before you run with the before Simulation value.

    The now and before Simulation values share one log file, which can be opened by choosing Setup – Matlab/Simulink – Log file. You can use the log file to monitor the simulation when no MATLAB desktop is visible.

    no

    The MATLAB start command, MATLAB startup directory, and MATLAB design name fields become active. When you use the no value, you must start the simulation in the Simulink design before starting the SpectreRF simulation.

  11. Continue the process of preparing the netlist according to how you want to start the applications that run the cosimulation.
    To use this starting method... Follow the guidance in this section...

    Start the two applications (SpectreRF and MATLAB) separately.

    “Preparing to Start the Two Applications Separately”

    Start ADE and arrange to have MATLAB start automatically.

    “Preparing to Start ADE Manually and MATLAB Automatically”

    Start MATLAB and arrange to have SpectreRF start automatically.

    “Preparing to Start MATLAB Manually and SpectreRF Automatically”

Preparing to Start the Two Applications Separately

  1. Set the start MATLAB value to no.
  2. Click OK to close the Cosimulation Options form.
  3. Use the Choosing Analyses form to set up the analysis.
    The Stop Time can be any value. The SpectreRF simulator synchronizes the stop time with Simulink.
    The Choosing Analyses window looks something like this:
  4. Create a netlist and make sure the Simulink cosim statement appears in it.

Preparing to Start ADE Manually and MATLAB Automatically

  1. Set the value of the Start MATLAB field to before Simulation in the Cosimulation Options form.
  2. Type the name of the MATLAB design into the MATLAB design name field.
    Such designs have an extension of .mdl. For example, env_d.mdl. The MATLAB design must be in a location that is included in the MATLABPATH environment variable.
  3. Set the value of the Start MATLAB field to now.
    A new MATLAB application starts and helps you open the Simulink design.
  4. Double-click the SpectreRF Engine in the design and set the parameters.
    1. Set the Sample time. The Sample time can be set to -1, if you are uncertain about the appropriate time to use.
    2. Set Socket Port to the value you set in the Cosimulation Options form.
    3. Leave the Spectre Command field empty.
      This field is used when you wish to start SpectreRF automatically after starting MATLAB manually.
    4. Click OK to close the SpectreRF Engine form.
  5. In the Cosimulation Options form, set Start MATLAB to before Simulation.
  6. Click OK to close the Cosimulation Options form.
  7. Use the Choosing Analyses form to set up the analysis.
  8. Choose File - Save to save the design in MATLAB. Then exit from the MATLAB that was opened by ADE Explorer.

Preparing to Start MATLAB Manually and SpectreRF Automatically

  1. Set the value of the Start MATLAB field to now.
    A new MATLAB application starts and helps you open the Simulink design.
  2. Double-click the SpectreRF Engine in the design and set the parameters.
    1. Set the Sample time. The Sample time can be set to -1, if you are uncertain about the appropriate time to use.
    2. Set Socket Port to the value you set in the Cosimulation Options form.
    3. Type a command similar to the following into the Spectre Command field.
      spectre netlist_file =log spectre.out
      The Block Parameters: SpectreRF Engine window looks something like this:
    4. Click OK to close the Block Parameters: SpectreRF Engine form.
  3. In the Cosimulation Options form, set Start MATLAB to no.
  4. Click OK to close the Cosimulation Options form.
  5. Use the Choosing Analyses form to set up the analysis.
  6. Choose File - Save to save the design in MATLAB. Then exit from the MATLAB that was opened by ADE Explorer.

Preparing the Netlist Without Using a Graphical User Interface

The steps in this section are necessary only if SpectreRF needs to start MATLAB automatically. If you are using the “Start MATLAB and arrange to have SpectreRF start automatically” starting method, ensure that there is no cosim statement in the netlist.

  1. Edit the netlist file.
    For example,
    vi tutorial1/tutorial1.scs.
  2. Add a cosim statement to the netlist.
    For example,
    matlab cosim server="bj2lnx20"  port=38525 inputs=["VI:wave" "VQ:wave"] outputs=[TX_AFE_OUT_BB_I TX_AFE_OUT_BB_Q]
    The parameters for the cosim statement are described below:

    Parameters of the cosim Statement

    Parameter Meaning

    design

    Refers to the file Simulink associates with the netlist.

    design="env_d.mdl"

    means the testbench whose file is env_d.mdl.

    inputs

    Input vector to identify the flow from MATLAB to SpectreRF Engine. The format is

    [“instance_name:wave” “instance_name1:wave” …]

    where wave, is a key word.

    The sequence of instances in square brackets follows the same one as the SpectreRF Engine port labels. This label information can be found by double-clicking the SpectreRF Engine and then by checking the Show engine port labels at the bottom in Block Parameters of the SpectreRF Engine.

    After the inputs are set in the netlist, the sources associated with the inputs are meaningless and their parameters do not affect the simulation.

    outputs

    Output vector from SpectreRF Engine to MATLAB. This vector can be the net name or terminal name of interest. If net name is used, only voltage is given; if terminal name is used, only current is output.

    To get current in an ENVLP analysis, you must add probes in the topology.

    port

    The port on the server running MATLAB. Its value should be the same as the value in the SpectreRF Engine in your current MATLAB design.

    server

    The name of the machine that MATLAB starts. It can be set with the machine name or with the IP address of that machine. The accepted form is

    server = ”155.110.110.110”

    and

    server = “bj2lnx20”

    server=localhost means that Spectre and MATLAB use the same machine.

    silent

    Tells MATLAB whether to open the window during simulation. If silent=yes, the testbench window is opened.

    timeout

    The period of time MATLAB spends waiting for a response from the Spectre simulator.

    timeout=60

    stops MATLAB if it does not receive any response.

  3. Close and save the netlist.
    After the above steps, the netlist is ready for simulation.

Running the Cosimulation

With the coupler connected into the MATLAB design and with an appropriate netlist for the low-level design, you are ready to run the cosimulation. Note that these starting methods work only when the design is prepared as described earlier in this chapter.

To use this starting method... Follow the guidance in this section...

Start the two applications (SpectreRF and MATLAB) separately.

“Starting the Two Applications Separately”

Start SpectreRF and arrange to have MATLAB start automatically.

“Starting SpectreRF Manually and MATLAB Automatically”

Start MATLAB and arrange to have SpectreRF start automatically.

“Starting MATLAB Manually and SpectreRF Automatically”

Starting the Two Applications Separately

  1. Open the high-level design or testbench in the MATLAB design window.
  2. In the MATLAB design window, choose Simulation – Start.
    The MATLAB desktop issues the following message.
    block 'modified/SpectreRF Engine': (COSIM_OK) Waiting for incoming connection on port 38520, timeout: 60 sec ...
    Then quickly do step 3.
    The time interval between step 2 and step 3 must be within the Simulation response timeout defined as Block Parameters of the SpectreRF Engine (by double-clicking the SpectreRF Engine).
  3. In ADE Explorer, choose Simulation – Netlist and Run or enter a spectre command at the command line. For example,
    spectre tutorial1/tutorial1.scs
    The cosimulation begins. The MATLAB desktop issues a message similar to the following when simulation ends.
    block 'modified/SpectreRF Engine': (COSIM_OK) Simulation finished

Starting SpectreRF Manually and MATLAB Automatically

To run the cosimulation by starting SpectreRF,

Starting MATLAB Manually and SpectreRF Automatically

    1. Start MATLAB.
      matlab&
    2. Choose Simulation – Start.
      The MATLAB desktop issues a message similar to the following.
      block 'env_d/SpectreRF Engine': (COSIM_OK) Waiting for incoming connection on port 38525, timeout: 60 sec ...
      block 'env_d/SpectreRF Engine': (COSIM_OK) Launch Spectre with commad 'spectre tutorial2.scs =log spectre.out'”
      The cosimulation runs.
    3. After the cosimulation finishes, review the MATLAB/Simulink output, close the MATLAB desktop, and exit from MATLAB.

MATLAB Support Matrix

Table 10-1 MATLAB Toolbox

This matrix applies to SPECTRE21.1 base and subsequent ISR versions.

SPECTRE MATLAB Release Supported Platform

Linux 64

R2018a

Supported

R2018b

Supported

SPECTRE 21.1

R2019a

Supported

R2019b

Supported

R2020a

Supported

R2020b

Supported

R2021a

Supported

Table 10-2 MATLAB Cosimulation

This matrix applies to SPECTRE21.1 base and subsequent ISR versions

MATLAB versions older than MATLAB R2015a are not included in this matrix.

SPECTRE MATLAB Release Supported Platform

Linux 64

R2015a

Supported

R2015b

Supported

R2016a

Supported

R2016b

Supported

R2017a

Supported

SPECTRE 21.1

R2017b

Supported

R2018a

Supported

R2018b

Supported

R2019a

Supported

R2019b

Supported

R2020a

Supported

R2020b

Supported

R2021a

Supported


Return to top
 ⠀
X