Talk About Network

Google





Electronic Equipment > VHDL > Re: String to s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 11 Topic 6055 of 6445
Post > Topic >>

Re: String to std_logic_vector

by KJ <kkjennings@[EMAIL PROTECTED] > May 30, 2008 at 09:47 AM

On May 30, 12:16=A0pm, Shannon <sgo...@[EMAIL PROTECTED]
> wrote:
> I've been searching here but all the hits were for converting SLV to
> string for testbenches.
>
> I'm looking to convert a string to an array of 8bit SLVs. =A0The idea is
> I have a revision string of fixed length- something like:
>
> ver <=3D "005-0805300908x2"'
>
> and I have an array of registers declared as such:
>
> SUBTYPE hwid_type is STD_LOGIC_VECTOR(7 DOWNTO 0);
> TYPE reg_type IS ARRAY (0 TO NUM_REGS-1) OF hwid_type;
> SIGNAL =A0regs : reg_type;
>
> What I'm looking for is a loop shown here in psuedo code:
>
> for i in 1 to 16 loop
> =A0 =A0 regs(i) <=3D to_slv(ver(mid$(i,1)))
> end loop
>
> Note this is for synthesis so I don't know if any of this is even
> legal. =A0I am trying to create a version register that the
> microprocessor can read. =A0An ascii string is prefered - let's pretend
> for a moment it is a requirement. =A0This is also a learning exercise
> for me to deal with strings in VHDL.
>
> Any ideas?
>
> Shannon

Since your input string has some non-numeric characters in it that you
presumably want to keep in the string, then the best approach would be
to simply write a function that parses the string however you'd like.

Below is an example that simply adds the 'value' of each input
character to produce an integer output.  You should be able to easily
modify this to select out whichever characters you want and perform
whatever calculations you'd like.

function Version_String_To_integer(Some_String: STRING) return integer
is
variable Return_Value: integer :=3D 0;
begin
for i in Some_String'range loop
  Some_Char :=3D Some_String(i)
  case Some_Char is
     when "0" =3D> Return_Value :=3D Return_Value + 0;
     when "1" =3D> Return_Value :=3D Return_Value + 1;
     ...
     when others =3D> null;
  end case;
end loop;
return(Return_Value);
end function Version_String_To_integer;

KJ
 




 11 Posts in Topic:
String to std_logic_vector
Shannon <sgomes@[EMAIL  2008-05-30 09:16:54 
Re: String to std_logic_vector
KJ <kkjennings@[EMAIL   2008-05-30 09:47:43 
Re: String to std_logic_vector
Shannon <sgomes@[EMAIL  2008-05-30 10:03:12 
Re: String to std_logic_vector
Mike Treseler <mike_tr  2008-05-30 10:24:50 
Re: String to std_logic_vector
KJ <kkjennings@[EMAIL   2008-05-30 10:31:50 
Re: String to std_logic_vector
Shannon <sgomes@[EMAIL  2008-05-30 11:09:46 
Re: String to std_logic_vector
Mike Treseler <mike_tr  2008-05-30 11:40:44 
Re: String to std_logic_vector
Shannon <sgomes@[EMAIL  2008-05-30 12:59:27 
Re: String to std_logic_vector
"KJ" <kkjenn  2008-05-30 16:55:55 
Re: String to std_logic_vector
"KJ" <kkjenn  2008-05-30 17:06:25 
Re: String to std_logic_vector
Shannon <sgomes@[EMAIL  2008-05-30 15:49:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Thu Jan 8 19:19:04 PST 2009.