In the TSTE16 course, we have started to look at the system and how to create a test-driven environment. There are – I guess – some different options that you can choose as starting point: 1) either you drive the top-level in matlab only or 2) you use matlab and cadence together.

In fact, I would suggest to start looking at the system from matlab only, since in this case we are able to quickly and swiftly change parameters such as the number of bits in the ADC and number of bits in the DAC.

Anyway, this post is about the command **ocnPrint** in cadence. This enables you to save waveform data to file, which can be read by Matlab. A good way to check intermediate nodes in Cadence inside your Matlab world.

The syntax is found by typing `help ocnPrint`

in the CIW. Let’s see:

` ocnPrint( [?output t_filename | p_port] [?precision x_precision] [?numberNotation s_numberNotation] [?numSpaces x_numSpaces] [?width x_width] [?from x_from] [?to x_to] [?step x_step] o_waveform1 [o_waveform2 ...] ) `

An example would then be:

`( ocnPrint ?output "./tste16ProjDac/m/dacOutputWaveform.txt" ?precision 16 ?from 0 ?to tStopTime ?step tSample (VT "/dacOutput") )`

Notice the two variables, `tStopTime`

and `tSample`

as well as my choice of node name, of course you need to pick what suits your test bench. `tStopTime`

is the stop time of your simulation or whatever range you want. and `tSample`

is the kind-of virtual sample frequency at which you want to observe data. For example, choose a big number, some 128 times the DAC and ADC sample frequencies. If you can, also try to maintain coherent sampling.

Paste the command into the CIW and check the file. Try out and comment, please. Possibly you want to add more waveforms to the file (see the help) or change the precision — make sure you have the required accuracy to meet your system spec!)

Also notice that you will get some “u” and “n” or “p”, etc., you might need to apply a function in matlab to clear that up for you. Possibly do a search and replace in emacs.

### Want to massproduce? Or kill a tree?

### Like this:

Like Loading...

Ok, so I got a little bit creative. There is a function called daisyReadOcnPrint now added to the daisy matlab directory. It should be included in your paths if you launch the project through the recommend scripts.

What command do you use in matlab to read the output text file?dlmread() fails as ocprint() uses mutliple spaces to separate the data columns.

Hi, thanks for your comment. It’s four years ago now, but then I used

`textscan`

. Haven’t debugged the function this morning though…function [readData, waveNames, waveUnits] = ...

daisyReadOcnPrint(fileName, numberOfSignals);

%

% function [readData, waveNames, waveUnits] = ...

% daisyReadOcnPrint(filename, numberOfSignals);

%

% Function that reads the specialized format from

% Cadence ocnPrint dump.

%

% numberOfSignals : Expected number of signals in the

% file. (this can be calculated

% automatically, but left for future

% improvement). Be precise though!

% fileName : Name of the file from the ocnPrint

% command.

%

% This is a function used for the daisy design flow.

%

% Created by J Jacob Wikner, Linköping University.

% 2009-10-07

%

fileId = fopen(fileName);

if (fileId == -1)

% File was not found

warning(['Filename ', fileName, ' was not found!']);

help readOcnPrint;

else

% First we tap of the headers, notice the +1, since the "time"

% column will be there too.

signalNamesAndUnits = textscan(fileId,'%s%s',numberOfSignals+1);

waveNames = signalNamesAndUnits{1};

waveUnits = signalNamesAndUnits{2};

% Create a string-read pattern for all the waveforms

% (number of %s = number of columns in the file)

pattern = '%s';

for m = 1:numberOfSignals

pattern = [pattern '%s'];

end;

% Now read the rest of the enchilada

dataValues = textscan(fileId, pattern);

readData = zeros(length(dataValues{1}), 1+numberOfSignals);

% "Unfortunately" we now have to run through the data vectors and

% replace the "n", "u", "m", "M", "p", "f", "a", etc., with e-9,

% e-6, and so on.

`unitVector = ['a' 'p' 'n' 'u' 'm' 'N' 'k' 'M' 'G' 'T' 'P'];`

for m = 1:(1+numberOfSignals)

dataCell = dataValues{m};

for l = 1:length(dataCell)

dataString = char(dataCell(l));

k = find(dataString(end) == unitVector);

if k

dataString = [dataString(1:(end-1)) 'e' num2str(3*(k-6))]

end;

readData(l,m) = str2num(dataString);

end;

end;

fclose(fileId);

end;

Let me know if it helps (or not).

Or you could use ocnPrint(?output “file.txt” … ?numberNotation ‘none … )

and Matlab command dataobj=importdata(‘file.txt’)

Write get(dataobj) in Matlab to see it’s structure.

Mucho easy!

/Joakim