Documentation

Contents

Implementing the Filter Component of an Oscillator in MATLAB®

This example shows how MATLAB® can be used to implement a filter component that is part of an HDL model; an oscillator is implemented in Verilog and a filter for the oscillator output is implemented in MATLAB.

A temporary directory is used for the compiled and elaborated HDL files. Once a snapshot is ready, we start a Cadence® Incisive® simulator session. (You must have the Incisive simulator executables on your PATH.) We use a shared memory connection between MATLAB the HDL simulator, so both must be on the same computer.

In this example, a Verilog oscillator has been designed and our job is to find a cleanup filter for the oscillator that meets our needs.

Three filters are implemented in MATLAB:

  • a 31st order (32-tap) filter with no oversampling

  • a 127th order (128-tap) filter with 4X oversampling

  • a 255th order (256-tap) filter with 8X oversampling

All three filters share the same delay line and the oversampling is implemented using the polyphase technique.

  • osc_filter.vosc_filter.v contains the MATLAB component that we are modeling. It contains an entity with an empty architecture. The matlabcp command drives the Verilog outputs and checks the Verilog inputs of the instance created from this entity.

  • osc_top.vosc_top.v contains the top-level wiring between the oscillator and the MATLAB component.

srcfile1 = fullfile(matlabroot,'toolbox','edalink','extensions','incisive','incisivedemos','Oscillator','simple_osc.v');
srcfile2 = fullfile(matlabroot,'toolbox','edalink','extensions','incisive','incisivedemos','Oscillator','osc_filter.v');
srcfile3 = fullfile(matlabroot,'toolbox','edalink','extensions','incisive','incisivedemos','Oscillator','osc_top.v');

Create Project Directory

We create a temporary working directory in which the project will be generated.

projdir = tempname;
mkdir(tempdir,strrep(projdir,tempdir,''));

Start the MATLAB Server

We start the MATLAB server, hdldaemon, such that it uses shared memory communication.

hdldaemon;
Warning: Existing HDLDaemon server shutting down (only one server is allowed per instance of MATLAB) 
HDLDaemon shared memory server is running with 0 connections

Specify Tcl Commands

Next we specify the Tcl commands to execute in the Incisive simulator before the simulation is run. The following lists of commands will execute in a Tcl shell. The commands will compile and elaborate the project and then launch ncsim through the hdlsimmatlab command. All commands preceded with -input are passed to ncsim and are executed in the ncsim Tcl shell; they force the clock and reset signals and prepare the waveform viewer.

tclcmd = {  ['cd ',projdir],...
           ['exec ncvlog ' srcfile1],...
           ['exec ncvlog ' srcfile2],...
           ['exec ncvlog ' srcfile3],...
           'exec ncelab -access +wc osc_top',...
            ['hdlsimmatlab -gui  osc_top ', ...
           ' -input "{@matlabcp osc_top.u_osc_filter -mfunc oscfilter_incisive}"',...
           ' -input "{@force osc_top.clk_enable 1 -after 0ns}"',...
           ' -input "{@force osc_top.reset 0 -after 0ns 1 -after 40ns 0 -after 120ns}"',...
           ' -input "{@force osc_top.clk 1 -after 0ns 0 -after 40ns -repeat 80ns}"',...
           ' -input "{@simvision  {set w \[waveform new\]}}"',...
           ' -input "{@simvision {waveform add -using \$w -signals osc_top.clk_enable}}"',...
           ' -input "{@simvision {waveform add -using \$w -signals osc_top.clk}}"',...
           ' -input "{@simvision {waveform add -using \$w -signals osc_top.reset}}"',...
           ' -input "{@simvision {waveform add -using \$w -signals signed(osc_top.osc_out)}}"',...
           ' -input "{@simvision {waveform add -using \$w -signals signed(osc_top.filter1x_out)}}"',...
           ' -input "{@simvision {waveform add -using \$w -signals signed(osc_top.filter4x_out)}}"',...
           ' -input "{@simvision {waveform add -using \$w -signals signed(osc_top.filter8x_out)}}"',...
           ' -input "{@simvision {waveform format -using \$w signed(osc_top.osc_out) -trace analogSampleAndHold}}"',...
           ' -input "{@simvision {waveform format -using \$w signed(osc_top.filter1x_out) -trace analogSampleAndHold}}"',...
           ' -input "{@simvision {waveform format -using \$w signed(osc_top.filter4x_out) -trace analogSampleAndHold}}"',...
           ' -input "{@simvision {waveform format -using \$w signed(osc_top.filter8x_out) -trace analogSampleAndHold}}"',...
           ' -input "{@simvision {waveform axis range -min -50000 -max 50000 -using \$w signed(osc_top.osc_out)}}"',...
           ' -input "{@simvision {waveform axis range -min -1.5e6 -max 1.5e6 -using \$w signed(osc_top.filter1x_out)}}"',...
           ' -input "{@simvision {waveform axis range -min -1.5e6 -max 1.5e6 -using \$w signed(osc_top.filter4x_out)}}"',...
           ' -input "{@simvision {waveform axis range -min -1.5e6 -max 1.5e6 -using \$w signed(osc_top.filter8x_out)}}"'
           ]};

Start the HDL Simulator

Now we start the Incisive simulator via the nclaunch command. The 'tclstart' property causes the specified Tcl commands to be run at startup.

nclaunch('tclstart',tclcmd);

After launching the HDL simulator, to run the simulation, use the run command in the ncsim console, specifying the appropriate simulation time. For example type 'run 10000' in the ncsim console.

Now check results in the Incisive simulator's waveform window. You will see that the non-oversampled filter does little good, but the 4X and 8X oversampled filters look much better.

This concludes this example.

Be sure to quit the Incisive simulator once you are done with this example as each time the example is run, a new HDL simulator instance is started. Also keep in mind that this example created some files in a temporary directory.

Was this topic helpful?