The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Aug 16th, 2024, 4:22am
Pages: 1
Send Topic Print
digital output signal generation (Read 2881 times)
kanan
Junior Member
**
Offline



Posts: 17

digital output signal generation
Apr 16th, 2009, 2:10am
 
Hi,

I am trying to generate some digital output signals depending on the voltage at a node. This is how I do it :

real avalid, bvalid, cvalid;
reg avalid_out, bvalid_out, cvalid_out;
output avalid_out, bvalid_out, cvalid_out;

analog
   begin
       if(V(n) < 0.5)
           avalid = 2;
       else
           avalid = 0;
       if(V(n) > 1.5)
           bvalid = 2;
       else
           bvalid = 0;
       if(V(n) > 3)
           cvalid = 2;
       else
           cvalid = 0;
  end


always @(above (avalid - 1))  
   begin
       avalid_out = 1'b1;
   end

   always @(above (1 - avalid))
   begin
       avalid_out = 1'b0;
   end  

   always @(above (bvalid - 1))  
   begin
       bvalid_out = 1'b1;
   end

   always @(above (1 - bvalid))
   begin
       bvalid_out = 1'b0;
   end  

   always @(above (cvalid - 1))  
   begin
       cvalid = 1'b1;
   end

   always @(above (1 - cvalid))
   begin
       cvalid = 1'b0;
   end  

I have 2 qns:
1. There seems to be a finite time taken for the real valude signals to go from 0 to 2, when the V(n) crosses the particular threshold. What drives this rise time? How can I change it to make it lesser?
2. The rise time seems to be different for avalid, bvalid, cvalid. How is that? Also as a result of this rise time, my digital signal output goes high only a little later than desired. For e.g I want bvalid_out = 1'b1 when V(n) > 1.5V, but it eventually becomes high only at around 1.6/1.7V bcos of the finite rise time of bvalid.

Is this the best way to code such a requirement, or is there a better way to do this. Any help would be useful.
Thanks
K
Back to top
 
 
View Profile   IP Logged
Peruzzi
Community Member
***
Offline



Posts: 71

Re: digital output signal generation
Reply #1 - Apr 16th, 2009, 8:02am
 
K,

Here's my suggestion.  In www.DesignersGuide.org, go to the Verilog-AMS Model Library tab and look at the Verilog-AMS model for a comparator. Take that approach in your model.  I think you are using two steps to get your digital output and you only need one.

That is, you can use something like.

always @(above (V(n) - 0.5))  
  begin
      avalid_out = 1'b1;
      avalid = 2;
  end

(Beware, the code above doesn't accomplish your intended function and only serves as an example comparison.)

Also, see the comparator model I refer to above for some timing and voltage resolution options.

If you have further questions you may contact me directly.

Best of luck.

Bob P.

Peruzzi@RPeruzzi.com
www.RPeruzzi.com


Back to top
 
 
View Profile   IP Logged
kanan
Junior Member
**
Offline



Posts: 17

Re: digital output signal generation
Reply #2 - Apr 16th, 2009, 8:08pm
 
Hi Bob,

Yes, this seems to be a better way to do it. Thanks. One step instead my two and removes the problems of the finite rise time I was seeing. However, it still baffles me as to why when we assign a value to a real number, it takes a finite time to rise to the value. For Voltage I understand, but I thought real was in the discrete world like the logic data type.

-K
Back to top
 
 
View Profile   IP Logged
Peruzzi
Community Member
***
Offline



Posts: 71

Re: digital output signal generation
Reply #3 - Apr 17th, 2009, 7:46am
 
K,

I think there are a couple of things going on with your unexpected delay and apparent finite rise time.

This first one is just my guess.  SimVision, if you are using it, might be "connecting the dots" and what is actually a step appears as a ramp.  (One of my friends and colleagues calls this "Lying Mode".) Setting the waveform format of the signal to "Analog Sample and Hold" is a better way to view discrete-time analog signals.

But the major discrepancy you are seeing is because the analog solver works differently than the digital solver.  The analog solver chooses solution time-points using rel-tol, max-tol and max-timestep parameters. The analog solver is in control of this part of your code:

analog
  begin
      if(V(n) < 0.5)
          avalid = 2;
      else
...


On the other hand, your

always @(above...

code creates a more direct link between the analog and digital engines. It forces a nearly simultaneous solution point in both the digital and analog worlds.

This loose linkage between the two solvers can drive you absolutely crazy.  The same circuit, with the same stimulus, can produce different results depending on the simulation stop-time.  Or, again with the same stimulus and the same stop time, adding further but unrelated circuitry with its own stimuli can change the output of the original circuitry.  You must be very conscious of this analog/digital solver relationship as you develop your system and its testbench.  Or you'll get burned and waste weeks debugging!

I may not be putting this exactly right.  It's kind of difficult to distill the concept into a couple of sentences in the time I'm willing to give, so once again I'll give you a reference:

Designers Guide to Verilog-AMS by Kenneth S. Kundert & Olaf Zinke

Use the Designers-Guide.org link to Amazon.com to buy this book. So this community gets a little kick back. You might be able to google up an explanation of how the analog versus digital solver works, but since you are asking this kind of question I think you are in need of reading Ken's book.


If you have further questions you may contact me directly.

Best of luck.

Bob P.

Peruzzi@RPeruzzi.com
www.RPeruzzi.com


Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.