Digital Timing using Solutions to Ordinary Differential Equations

This example shows how to model a three stage ring oscillator using models defined by ordinary differential equations (ODE).

This example is the third of three examples that use a three stage ring oscillator model to explore the range of options for simulating the analog applications of digital circuits. The delays in each stage determine the ring oscillator's output frquency, making the accurate modeling of these delays essential to the the simulation of the circuit.

The first and second examples in the sequence contain background that will help you get the most out of this example. You should read them first, in sequence, if you haven't already done so.

This model uses blocks defined by ODEs, and depends on the services of an ODE solver. For each stage, the zero crossing detection capabilities of a Compare To Constant block are used to produce a saturated input to the inverter. The inverter output is converted from Boolean to double to drive a Transfer Function block. The Transfer Function block defines the shape of the inverter output transitions.

% Load the ODE-based model and update the model to display
% sample times.

Continuous Time Model Using Exponential Decay

In this section, use a single pole response to evaluate the ring oscillator output when the inverter output is modeled as the response of an RC circuit.

For this section, the Transfer Function blocks are configured for a single pole response. The pole for one of the logic stages is set to a slightly different value than for the other two stages so that the model will enter the correct mode of oscillation.

The solver selection is set to auto, with a Relative Tolerance of 1e-9.

% Run the ODE-based model with single pole rise/fall response.

Continuous Time Model with Nearly Constant Slew Rate

In this section, model the response of the ring oscillator stages using a continuous time Transfer Function block with a fourth order Bessel-Thompson response to approximate a constant slew rate response.

Note the slight rounding of the onset of the switching edges, similar to the waveforms produced in the Digital Timing using Fixed Step Sampling example.

% Set the configuration for the fourth order Bessel-Thompson rise/fall
% response.
den = getBesselDenominator(3e9);
set_param('OdeWaveform/Transfer Fcn','Denominator',mat2str(den));
set_param('OdeWaveform/Transfer Fcn1','Denominator',mat2str(den));
den = getBesselDenominator(3.1e9);
set_param('OdeWaveform/Transfer Fcn2','Denominator',mat2str(den));
% Run the modified ODE-based model.
Warning: Undefined variable "autosar" or class

Continuous Time with Solver in auto Mode

In this section, change the solver configuration and observe the change in results.

Maintain the model configuration of the previous section but change the solver's Relative Tolerance from 1e-9 to auto.

Observe both the change in period of oscillation and in wave shape.

For circuits which are adequately described by linear, time invariant models, the combination of fixed step and variable step discrete sample times, as described in the Combined Fixed Step and Digital Timing section may be the simplest way to get reliable results. However, for circuits which must be modeled by a nonlinear or time-varying model, the ODE-based solution is the only viable option. In such cases, you should vary the maximum error tolerance, maximum step size or choice of solver in the solver configuration dialog and compare the results to the behavior you expect.

% Change the solver's relative tolerance to 'auto'.
% Run the model with the auto solver setting.
Warning: Undefined variable "autosar" or class