signal and variable assignment problems

Discussion in 'VHDL' started by wagnerrv, Jul 20, 2012.

  1. wagnerrv

    wagnerrv

    Joined:
    Jul 20, 2012
    Messages:
    1
    I have written the following code to turn any integer into a string which I manipulate later.

    Code:
    LIBRARY ieee;
    USE ieee.std_logic_1164.all;
    
    ENTITY int2str IS
         PORT (number: IN integer;
                     str : OUT string(1 to 8)
                    );
    END int2str;
    
    ARCHITECTURE Behavior of int2str IS
    BEGIN
        process(number)
          variable subtractor, counter: integer := 0;
          variable num_tmp2 : integer;
          variable str_tmp : string (1 to 8);
          variable str_one : string(1 to 1);
        BEGIN
          num_tmp2:=number;
          [COLOR="Red"]-- num_tmp2: 8675309;[/COLOR]
          for j in 8 DOWNTO 1 loop
              subtractor := 10**(j-1);
              counter :=-1;
              poschk : for k in 0 to 9 loop
                  num_tmp2 := num_tmp2 - subtractor;
                  counter := k;
                  exit poschk when num_tmp2 < 0;
              end loop poschkl
              num_tmp2 := num_tmp2 + subtractor;
              if (counter >-1) then
                  str_one := integer'image(counter);
                  str_tmp(9-j) := str_one(1);
              else
                  str_tmp(9-j) := 'A';
              end if;
          end loop;
       str <= str_tmp;
       end process;
    
    END Behavior;
    
    Ignore general coding mistakes. I retyped the code rather than copy/paste, so I might have missed some things. But the code compiles fine.

    The code works if I remove the comment tag for the red line. That is, if I force num_tmp2 to be a certain value in the code, that value is returned as a string. However, when I try to feed in a number by calling the code from another vhdl file, the only string that ever gets output is "00000000". What am I doing wrong?

    (If you are interested/if it matters, the overall project is to use a DE2 board to read in TTL pulses, count the number of pulses received and display them via the HEX displays on the DE2 board. I can read in the pulses and count how many there are and I can write a string to the HEX displays, but I can't turn the number of pulses received into a string in order to write it out the HEX displays. So this code is to fill in the missing part in the middle.)
     
    wagnerrv, Jul 20, 2012
    #1
    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. Nicolas Matringe

    Variable to signal assignment

    Nicolas Matringe, Apr 29, 2005, in forum: VHDL
    Replies:
    2
    Views:
    7,320
    Mike Treseler
    Apr 29, 2005
  2. filmil
    Replies:
    11
    Views:
    1,252
    Mike Treseler
    May 25, 2007
  3. Nicolas Moreau
    Replies:
    9
    Views:
    3,183
  4. dibacco73
    Replies:
    1
    Views:
    656
    joris
    Feb 12, 2009
  5. ramy
    Replies:
    7
    Views:
    292
Loading...

Share This Page