The Designer's Guide Community Forum https://designers-guide.org/forum/YaBB.pl Modeling >> Behavioral Models >> finding voltage peaks and size varying array https://designers-guide.org/forum/YaBB.pl?num=1504791794 Message started by jjnkxb on Sep 7th, 2017, 6:43am

 Title: finding voltage peaks and size varying array Post by jjnkxb on Sep 7th, 2017, 6:43am I am implementing a history dependent model in verilog a. I had some problems which I hope you could provide help.I need to locate the input voltage peaks and store them in an array. Since the input voltage waveform is arbitrary, the array size is also varying. Is there any way to implement such array?In addition, to find the peak, I am considering to use d/dt function. When the time derivative changes sign, the peak is found. But right at the peak (for a linear voltage waveform), the time derivative is not defined. I am not clear how that is handled in circuit simulation. Or do you have any other idea to find the peak?Would you please provide me some insight? Thanks.Kai

Title: Re: finding voltage peaks and size varying array
Post by Ken Kundert on Sep 7th, 2017, 8:34am

Quote:
 I need to locate the input voltage peaks and store them in an array. Since the input voltage waveform is arbitrary, the array size is also varying. Is there any way to implement such array?

No, not that I know of, not within Verilog-A. You could write the peaks to a file.

Quote:
 In addition, to find the peak, I am considering to use d/dt function. When the time derivative changes sign, the peak is found. But right at the peak (for a linear voltage waveform), the time derivative is not defined. I am not clear how that is handled in circuit simulation. Or do you have any other idea to find the peak?

Try it and see.

If you don't like the result, consider simply saving two points back and determine the peaks that way.

-Ken

 Title: Re: finding voltage peaks and size varying array Post by jjnkxb on Sep 7th, 2017, 8:51am Thanks Ken. About your last sentence, I am not sure how I can save the previous voltage value. To my knowledge, the voltage is instantaneous. Would you please elaborate on that?Best,Kai

Title: Re: finding voltage peaks and size varying array
Post by Ken Kundert on Sep 7th, 2017, 11:09pm

Code:
 real vprev, vprev2;analog begin    if ((vprev2 < vprev) && (vprev > V(in)) begin         # vprev is peak         ...    end    vprev2 = vprev;    vprev = V(in);end

-Ken

 Title: Re: finding voltage peaks and size varying array Post by jjnkxb on Sep 8th, 2017, 1:14pm Ken, Thanks a lot. I will try this method and see how it works.Best,Kai

 Title: Re: finding voltage peaks and size varying array Post by jjnkxb on Sep 13th, 2017, 8:58am Ken, I tried to use the d/dt approach and also save the previous voltage and compare. Both approaches worked fine. Thank you very much for your help.Best,Kai