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 3 of 11 Topic 6055 of 6445
Post > Topic >>

Re: String to std_logic_vector

by Shannon <sgomes@[EMAIL PROTECTED] > May 30, 2008 at 10:03 AM

On May 30, 9:47=A0am, KJ <kkjenni...@[EMAIL PROTECTED]
> wrote:
> 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. =A0You 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
> =A0 Some_Char :=3D Some_String(i)
> =A0 case Some_Char is
> =A0 =A0 =A0when "0" =3D> Return_Value :=3D Return_Value + 0;
> =A0 =A0 =A0when "1" =3D> Return_Value :=3D Return_Value + 1;
> =A0 =A0 =A0...
> =A0 =A0 =A0when others =3D> null;
> =A0 end case;
> end loop;
> return(Return_Value);
> end function Version_String_To_integer;
>
> KJ- Hide quoted text -
>
> - Show quoted text -

As I suspected.  So to flesh things out a bit....

function Version_Char_To_slv(Some_Char: character) return slv
is
variable Return_Value: slv(7 downto 0)  :=3D (others =3D> 0);
begin
case Some_Char is
     when "0" =3D> Return_Value :=3D STD_LOGIC_VECTOR(TO_UNSIGNED(0,8);
     when "1" =3D> Return_Value :=3D STD_LOGIC_VECTOR(TO_UNSIGNED(1,8);
     ...
     when "a" =3D> Return_Value :=3D STD_LOGIC_VECTOR(TO_UNSIGNED(97,8);
     ...
     when "-" =3D> Return_Value :=3D STD_LOGIC_VECTOR(TO_UNSIGNED(45,8);
     ...
     when others =3D> null;
end case;
return(Return_Value);
end function Version_Char_To_slv;

and then back in my main process....

for i in 1 upto 16 loop
    regs(i) <=3D Version_Char_To_slv(ver(i));
end loop;


Or something like that?
 




 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:23:46 PST 2009.