Looking for something others

Discussion in 'VHDL' started by Brad Smallridge, May 12, 2005.

  1. Hi folks,

    How does one write this code cleanly?

    if( segment_pointer_count="111111111" ) then
    segment_pointer_count <= "000000001"; -- skip zero
    else
    segment_pointer_count <= segment_pointer_count+1;
    end if;


    That is, with something that is length independent.

    Thanks,

    Brad Smallridge
    b r a d @ a i v i s i o n . c o m
     
    Brad Smallridge, May 12, 2005
    #1
    1. Advertising

  2. Brad Smallridge wrote:
    > Hi folks,
    >
    > How does one write this code cleanly?
    >
    > if( segment_pointer_count="111111111" ) then
    > segment_pointer_count <= "000000001"; -- skip zero
    > else
    > segment_pointer_count <= segment_pointer_count+1;
    > end if;
    >
    >
    > That is, with something that is length independent.


    Length independent _IF_ segment_pointer_count is 31 bits or less:

    use numeric_std.all;
    ....
    signal segment_pointer_count : unsigned(...);
    ....
    if( segment_pointer_count=(2**segment_pointer_count'length)-1 ) then
    segment_pointer_count <= 1; -- skip zero
    else
    segment_pointer_count <= segment_pointer_count+1;
    end if;
    --
    Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
    Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
    Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com
     
    Tim Hubberstey, May 13, 2005
    #2
    1. Advertising

  3. Hello

    Brad Smallridge wrote:
    > Hi folks,
    >
    > How does one write this code cleanly?
    >
    > if( segment_pointer_count="111111111" ) then
    > segment_pointer_count <= "000000001"; -- skip zero
    > else
    > segment_pointer_count <= segment_pointer_count+1;
    > end if;
    >
    > That is, with something that is length independent.


    You can write this:

    if segment_pointer_count = (segment_pointer_count'range => '1') then
    segment_pointer_count <= (0 => '1', others => '0');
    else
    ....

    Nicolas
     
    Nicolas Matringe, May 13, 2005
    #3
  4. Brad Smallridge

    sps Guest

    if( segment_pointer_count= X"FF" ) then
    segment_pointer_count <= X"01"; -- skip zero
    else
    segment_pointer_count <= segment_pointer_count+1;
    end if;
     
    sps, May 13, 2005
    #4
  5. Thanks Nicolas. That seems the best.

    > if segment_pointer_count = (segment_pointer_count'range => '1') then
    > segment_pointer_count <= (0 => '1', others => '0');
    > else
    > Nicolas
    >
     
    Brad Smallridge, May 20, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard
    Replies:
    8
    Views:
    409
    Richard
    Apr 9, 2004
  2. Guest
    Replies:
    4
    Views:
    510
    Guest
    Oct 13, 2004
  3. Pekka Järvinen
    Replies:
    2
    Views:
    697
    Richard Tobin
    Apr 29, 2008
  4. Replies:
    4
    Views:
    239
    Tad McClellan
    Jun 1, 2007
  5. Travis
    Replies:
    3
    Views:
    408
Loading...

Share This Page