Re: peak to peak jitter
Use this veriloga file, just connect your clock to this clock
// VerilogA for bmslib, Sig2FreqJitter, veriloga
// last revised: 7/21/03 (ronv)
//
// DESCRIPTION:
// Measures the frequency and Jitter of the input signal by detecting
// the times at which the last two zero crossings occured. This method
// will only work accurately on single tone signals.
//
// LIMITATIONS:
// This only measures instantaneous Freq and Delta Period
// no measurement until after 2nd clock edge
//
// INCLUDE FILES:
`include "constants.h"
`include "discipline.h"
// Frequency in Hertz, nature and signal-flow discipline:
nature Freq_Hz
units = "Hz";
access = FF;
abstol = 1m;
blowup = 1G;
endnature
discipline freq_hz
potential Freq_Hz;
enddiscipline
// Time in Seconds, nature and signal-flow discipline:
nature Time_Sec
abstol = 1f;
access = TT;
units = "s";
blowup = 1G;
endnature
discipline time_sec
potential Time_Sec;
enddiscipline
//==========================================================================
module Sig2FreqJitter(IN, Fout, Jitter);
// PINS
input IN; // input node
electrical IN;
output Fout; // cycle/cycle Frequency in Hz
freq_hz Fout;
output Jitter; // delta period in sec
time_sec Jitter;
// INTERNAL NODES
// {none}
// INSTANCE PARAMETERS:
parameter real Vtrig = 0.9; // Threshold voltage for edge detection
parameter integer dir = 1 from [-1:1] exclude 0;
parameter real ttol = 1p from (0:inf);
// LOCAL VARIABLES: (Comment each one)
real tlastx, x1,x2,x3 ; // crossing times
real period, lastperiod, delper, fout_val;
// FUNCTIONS
// {none}
//---------------------------------------------------------------------------
analog begin
// unless you want different values this is not needed
/**********************
@(initial_step) begin
period = 0;
lastperiod = 0;
delper = 0;
fout_val = 0;
end
*********************/
@ ( cross (V(IN)-Vtrig,dir,ttol) ) begin
x3 = x2;
x2 = x1;
x1 = tlastx;
end
tlastx = last_crossing(V(IN)-Vtrig,dir);
if (x3>0) begin // enough edges to start
period = tlastx - x1;
lastperiod = x1 - x2;
delper = (period - lastperiod)*1e12;
fout_val = 1/period;
end
FF(Fout) <+ fout_val;
TT(Jitter) <+ delper;
end
endmodule