Languages

CommunityCategory: XMODELReplaying waveforms stored in a CSV file during XMODEL simulation.

XMODEL

Replaying waveforms stored in a CSV file during XMODEL simulation.

SA Support Team Staff 2019-08-12

I have a waveform stored in a CSV file in the following format:

time1, value1
time2, value2
…

Is there a way I can replay this waveform in XMODEL simulations?

1 Answers
Best Answer
SA Support Team Staff 2019-08-12

I think the simplest way is to convert the waveform information stored in the CSV file to a parameter file for a 'pwl_gen' primitive using the MODELFIT library. Then, you can replay the waveform in XMODEL simulations using a 'pwl_gen' primitive.
The following Python script example reads a CSV file named 'waves.csv' and converts its information to a parameter file named 'pwl_gen.dat'. The modelfit() function is used to fit the waveform in a piecewise-linear (PWL) format. For more information, please refer to the MODELFIT tutorial included in the 'modelzen_basic' tutorial package.

#!/usr/bin/env xmodelpy

import numpy as np
import modelfit

data = np.loadtxt('waves.csv', delimiter=',')
t, v = data[:,0], data[:,1]

modelfit.modelfit(model='pwl_gen', in_=t, out=v, 
                  abstol=1e-4, reltol=1e-2, filename='pwl_gen.dat')

You can replay the waveform in any XMODEL simulation by including a 'pwl_gen' primitive that reads this parameter file 'pwl_gen.dat'. For instance,

xreal signal;
pwl_gen #(.filename("/<PATH>/pwl_gen.dat")) I0 (signal);

replays the waveform to a signal named "signal". Here, '<PATH>' indicates the absolute path location of the 'pwl_gen.dat' file.
If your testbench is in a schematic form using GLISTER, you can instantiate the 'pwl_gen' primitive as shown below: