• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. Verilog-A module for calculation of average 100 MHz continuous...

Stats

  • Replies 0
  • Subscribers 125
  • Views 1225
  • Members are here 0

Verilog-A module for calculation of average 100 MHz continuous input signal (unaccurate results when analyzing in WaveView; transient sim in spectre)

FC202502053712
FC202502053712 5 months ago

Verilog-A calculation of average 100 MHz continuous input signal (unaccurate results when analyzing in WaveView)


Hi everyone,


I created a module in Verilog-A to measure the average voltage of a 100MHz continuous input signal.
The idea is to make the calculations inside the time window given by "start_meas" and "stop_meas", and
when "stop_meas" is triggered, the calculated value must be sent to "output_meas". Just to be clear, this means
that during the forementioned time window, the average calculation result is saved in an internal variable "avg",
and only when "stop_meas" is triggered, this value is sent to "output_meas".
I ran the transient simulation in spectre and exported the transient waveform to be analyzed in WaveView; so i
created 3 equidistant cursors, and created 2 monitors to check for the average voltage of the "sense" signal (input signal)
and the "output_meas" signal.

as you can see in the picture:

cursor 1-2: start_meas and stop_meas (this is the "sense" signal,average is -6.416212266503737E-01 mV)
cursor 2-3: stop_meas and another equidistant point (this is the "output_meas" signal, average is -6.417229679210713E-01 mV)


Mismatch value is = -0.1017412706979990E-06

The averages between cursors 1-2 and 2-3 shall be the same, but clearle the value of cursors 2-3 (which shows results of my code)
is bigger, reason why i am thinking how may i improve my code to get more accuracy, or in case it is not possible with
this method i am using, find the reason why and try another method like moving window averaging (or any other method which could be yet better).


Any hint or advice on this inquiry will be greatly appreciated.

Thank you!!

WaveView screenshot: WaveView screen

Code:

`include "constants.vams"
`include "disciplines.vams"

module verilogA_test1(input start_meas, input stop_meas, input sense, output output_meas);
parameter real input_tol = 10m;
parameter real ttol = 100p;
parameter real vtol = 10m;

electrical start_meas, stop_meas, sense, output_meas;

real integral_window; // Integral accumulated only during the measurement window
real t_start; // Start time of the measurement window
real output_value; // Output average value
real meas_active; // Flag: 1 during measurement, 0 otherwise

analog begin
// Initialize variables at the start of simulation
@(initial_step) begin
output_value = 0;
meas_active = 0;
end

// Integrate V(sense) only when meas_active is 1
integral_window = idt(meas_active * V(sense), 0);

// When start_meas crosses threshold, begin measurement
@(cross(V(start_meas) - input_tol, +1, ttol, vtol)) begin
t_start = $abstime; // Capture start time
meas_active = 1; // Enable integration
// Note: integral_window starts accumulating from 0 due to meas_active transition
end

// When stop_meas crosses threshold, end measurement and compute average
@(cross(V(stop_meas) - input_tol, +1, ttol, vtol)) begin : stop_meas_block
real time_integral;
real avg;

time_integral = $abstime - t_start; // Duration of the window

// Compute average if time_integral is positive, otherwise set to 0
if (time_integral > 0) begin
avg = integral_window / time_integral;
end else begin
avg = 0;
end

output_value = avg; // Update output
meas_active = 0; // Disable integration
end

// Drive the output with the computed average
V(output_meas) <+ output_value;

$display("output_value=3.9%E", output_value) ;
end
endmodule

  • Sign in to reply
  • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information