• 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. VerilogA $abstime limitation to 2pi

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 125
  • Views 10111
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

VerilogA $abstime limitation to 2pi

Ajmal Hussian
Ajmal Hussian over 3 years ago

Hi,

I am developing a VeriolA module from which I want to get continuous angle in radian.

I am using the following code to get the angle

angle_in_rad = (current_velocity*$abstime + phi);

But I am facing a problem while limiting the value of abstime to 2pi.

Is it possible to limit $abstime to 2Pi? like the idt_mod operation.

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    Create an analog function fmod like this (similar to the C function, but not part of the Verilog-A language):

    analog function real fmod;
        input num,den;
        real num,den;
        fmod=num-floor(num/den)*den;
    endfunction 
    
    analog begin
      angle_in_rad = fmod((current_velocity*$abstime + phi),`M_TWO_PI);
      $strobe(angle_in_rad);
    end
    

    That will do what you want, I think. I'm not sure it's the $abstime you want to limit to 2 pi, but the angle_in_rad (I assume)?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Ajmal Hussian
    Ajmal Hussian over 3 years ago in reply to Andrew Beckett

    Yes, You are right I want to limit the angle in rad to 2 pi, but the $abstime is always increasing,
    But I did not get your answer fully, how can I create the analog function?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Ajmal Hussian
    Ajmal Hussian over 3 years ago in reply to Andrew Beckett

    Yes, You are right I want to limit the angle in rad to 2 pi, but the $abstime is always increasing,
    But I did not get your answer fully, how can I create the analog function?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to Ajmal Hussian
    Ajmal Hussian said:
    But I did not get your answer fully, how can I create the analog function?

    Include the function definition within your module - here's a complete (simple) made up example to show it in use:

    //
    
    `include "disciplines.vams"
    `include "constants.vams"
    module testfmod(sigout);
    electrical sigout;
    output sigout;
    
    parameter real current_velocity=1e6;
    parameter real phi=0.1;
    real angle_in_rad;
    
    analog function real fmod;
        input num,den;
        real num,den;
        fmod=num-floor(num/den)*den;
    endfunction 
    
    analog begin
      angle_in_rad = fmod((current_velocity*$abstime + phi),`M_TWO_PI);
      $strobe(angle_in_rad);
    end
    
    endmodule
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Ajmal Hussian
    Ajmal Hussian over 3 years ago in reply to Andrew Beckett

    I have tried both of the following ways and it works. But the problem is that during the tansition from 360 to 0 there is always an intermediate value at 180 degree which creates errors. Do you have any idea why it behaves like this?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to Ajmal Hussian

    I can't see a good reason why that would happen - I don't see that with my example above. There's a risk with your implementation that the argument to the function might increase by more than one cycle in one step and so it's not truly limiting it to the modulo - I don't see any benefit in your approach compared with mine (it only seems to have a disadvantage that it might go wrong at times). In either case though, I can't see why it would have a value at 180 degrees - unless the input stepped from just below 360 to 360+180 to 720. Perhaps getting your Verilog-A model to $strobe or $debug the input to the function before it's called (and the return value too).

    • Cancel
    • Vote Up 0 Vote Down
    • 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