Dan M
New Member
Offline
Posts: 3
|
I have the following VerilogA code and it's not working so well
module sample (in);
input in; electrical in;
real minv, maxv;
analog begin @(initial_step) begin minv=V(in)-0.01; maxv=V(in)+0.01; end @(cross(V(in)-minv,-1)) minv=V(in)-0.01; @(cross(V(in)-maxv,1)) maxv=V(in)+0.01; @(timer(1n,1n)) begin $display ("%f %f",minv,maxv); minv=V(in)-0.01; maxv=V(in)+0.01; end end endmodule
So effectively I'm trying to find the minimum and maximum voltage on 'in' over 1 nanosecond blocks of time. I'm putting in the '0.01' offsets to try to provide some sort of "hysteresis" so it's not constantly triggering the @cross, with the understanding that it obviously throws in up 10mV of error.
What I'm seeing is that the @crosss statements aren't triggering consistently. If I force a lot of time steps with an @(timer(100f,100f)) it seems to work better, but that's a horrible solution. If I increase time or voltage tolerance in the @cross it seems to work better, but not much, and if I add to hysteresis it works a lot better, but to get good results I need to change the 10mV to well over 100mV, and even then it's not perfect, and I'm not comfortable with the lack of accuracy. The problem seems to come when there is a very high frequency signal (i.e. on input edges).
If anyone has some thoughts as to how to maek this work better, I'd definitely appreciate it.
Thanks!
|