Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > signal and variable assignment problems

Thread Tools

signal and variable assignment problems

wagnerrv wagnerrv is offline
Junior Member
Join Date: Jul 2012
Posts: 1
I have written the following code to turn any integer into a string which I manipulate later.

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
      variable subtractor, counter: integer := 0;
      variable num_tmp2 : integer;
      variable str_tmp : string (1 to 8);
      variable str_one : string(1 to 1);
      -- num_tmp2: 8675309;
      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);
              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.)
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assignment to output signal from internal signal not istantaneous dibacco73 VHDL 1 02-12-2009 11:28 PM
Assignment (variable or signal)? Amal VHDL 7 11-26-2007 08:51 PM
"Target of signal assignment is not a signal" Nicolas Moreau VHDL 9 07-25-2007 04:21 PM
Differfence in the assignment of a variable to a signal with and without condition filmil VHDL 11 05-25-2007 05:26 PM
Variable to signal assignment Nicolas Matringe VHDL 2 04-29-2005 02:26 PM