The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Detecting "immediately" if pulse period is larger than tmax
https://designers-guide.org/forum/YaBB.pl?num=1472205255

Message started by Zorro on Aug 26th, 2016, 2:54am

Title: Detecting "immediately" if pulse period is larger than tmax
Post by Zorro on Aug 26th, 2016, 2:54am

Hi All,

I have a question and I hope somebody can give me a hint to solve the problem.

I need to generate a reset signal "b" if the period of input signal xcn is larger than tmax.

The signal xcn is actually electrical but using "Digital Sensitivity to Analog Events" the signal is discretized inside the model. This is done like this:


`timescale 1ns/1ps      // `timescale (time unit)/(time precision)
`define tick 1e9      // `define tick 1/(time unit)
...
reg                  xcn_dig;
...

     always @(above(V(xcn, vss)-thr_high)) begin
           xcn_dig = 1;
     end

     always @(above(thr_low-V(xcn, vss))) begin
           xcn_dig = 0;
     end      
     
From now on the code continues working with the digital signal xcn_dig.

Below the code that I am trying to use for pulse width detection.

     parameter real        tmax                  = 210n;

     always @(posedge xcn_dig) begin

           b <= 1'b0;
           b <= #(tmax*`tick) 1'b1;  
           
     end
     
Scenario 1
Lets assume that xcn_dig has a period which is larger than tmax=210ns.
In this case a reset signal must be generated.
In this example the period of xcn_dig is 216.931ns, larger than tmax=210ns and therefore a reset pulse should be generated 210ns after the rising edge of xcn_dig.
See picture 1.
-> The code is working well to detect pulses that are bigger than tmax.


Scenario 2
Lets assume that xcn_dig has a period which is smaller than tmax=210ns.
In this case the reset signal should remain low.
In this example the period of xcn_dig is 171.414ns, smaller than tmax=210ns and therefore no reset pulse should be generated 210ns after the rising edge of xcn_dig.
See picture 2.
However, with this code, the reset pulse is being generated.
-> The code is not working well to detect pulses that are smaller than tmax.
Can somebody helpe me to improve this?
I actually need that if the second positive edge of xcn_dig occurs in the expected time <tmax then the generation of the reset should be canceled.

Thank you very much!
Zorro.

Title: Re: Detecting "immediately" if pulse period is larger than tmax
Post by Zorro on Aug 26th, 2016, 3:01am

picture 1

Title: Re: Detecting "immediately" if pulse period is larger than tmax
Post by Zorro on Aug 26th, 2016, 3:01am

picture 2

Title: Re: Detecting "immediately" if pulse period is larger than tmax
Post by Narasimhan on Aug 26th, 2016, 4:14am

The code for detection will always assign 1 to b whenever posedge of xcn_dig occurs irrespective of the period. You can make use of the inbuilt function $abstime or $realtime to get the time stamp when the posedge of xcd_dig occurs and compare it with the next posedge timestamp.



Code:
real curr_timestamp, prev_timestamp;

always @(posedge xcn_dig)
begin
curr_timestamp = $abstime;
b = (curr_timestamp > (prev_timestamp + tmax));
prev_timestamp = curr_timestamp;
end


note that you need to use blocking assignments(=) for the above code to work

Title: Re: Detecting "immediately" if pulse period is larger than tmax
Post by Zorro on Aug 26th, 2016, 5:02am

Hi Narasimhan,

thank you for your reply. I had tried something similar using the frequency/period measurement code.

The problem is that the code that you posted  and the code of the "frequency/period measurement block" have to wait for the next positive edge of xcn_dig to generate (or not) the reset signal.

As I wrote in the subject the detection must be "immediate".

Example
Imagine that xcn_dig goes high and if tmax time after this event occur we don't have a new rising edge of xcn_dig then reset should go high immediately and not wait until the next positive edge of xcn_dig to go high.
What if there is no new positive edge of xcn_dig (let's say xcn_dig remains high or low)? then no reset would be generated at all.

The output using your code is reset1.
See picture 3 below.
Thank you.

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.