Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > convert a String to stdt_logic_vector

Reply
Thread Tools

convert a String to stdt_logic_vector

 
 
Klaus Sandner
Guest
Posts: n/a
 
      08-10-2007
I want to send a textstring to a display.To do this I have to transform
each charakters of the string to 8 bit values.

here my Vhdl solution

constant LCD_display_lenositive:=16;
subtype LCD_display_string is string(1 to LCD_display_len);
subtype LCD_display_bit is std_logic_vector(1 to LCD_display_len*;


process (clk)
variable data_string :LCD_display_string := "test string for ";
variable data_bit :LCD_display_bit;

now I have problems to write the right instruction

data_bit <= conv ????????????????????????????

has somebody a solution?


klaus


end process;
 
Reply With Quote
 
 
 
 
Tricky
Guest
Posts: n/a
 
      08-10-2007
On Aug 10, 4:38 pm, Klaus Sandner <(E-Mail Removed)> wrote:
> I want to send a textstring to a display.To do this I have to transform
> each charakters of the string to 8 bit values.
>
> here my Vhdl solution
>
> constant LCD_display_lenositive:=16;
> subtype LCD_display_string is string(1 to LCD_display_len);
> subtype LCD_display_bit is std_logic_vector(1 to LCD_display_len*;
>
> process (clk)
> variable data_string :LCD_display_string := "test string for ";
> variable data_bit :LCD_display_bit;
>
> now I have problems to write the right instruction
>
> data_bit <= conv ????????????????????????????
>
> has somebody a solution?
>
> klaus
>
> end process;


you need a function that goes something like this.

--converts a std_logic_vector into a string.
function slv_to_string(slv : std_logic_vector) return string is
variable retString : string(1 to slv'length);
begin
for i in 0 to slv'length-1 loop
if slv(i) = '1' then

--ensure we dont write the string back to front!
if slv'ASCENDING then
retString(i+1) := '1'; --always +1 as the string range is 1 to
slv'length
else
retString(retString'high-i) := '1';
end if;
else
if slv'ASCENDING then
retString(i+1) := '0'; --always +1 as the string range is 1 to
slv'length
else
retString(retString'high-i) := '0';
end if;
end if;
end loop;

return retString;
end function slv_to_string;




 
Reply With Quote
 
 
 
 
Tricky
Guest
Posts: n/a
 
      08-10-2007
Whoops I did that the wrong way round.

The IEEE.std_logic_textio package has the ability to read/write
std_logic_vectors from/to strings. These are procedures though. If you
need a function:

function string_to_slv(s : string) return std_logic_vector is
variable ret_slv : std_logic_vector(s'length-1 downto 0);
begin
for i in 1 to s'length loop
if s(i) = '0' then
ret_slv(i-1) := '0';
elsif s(i) = '1' then
ret_slv(i-1) := '1';
else
--catch bad characters
ret_slv(i-1) := 'X';
end if;

return ret_slv;
end loop;
end function;



 
Reply With Quote
 
Tricky
Guest
Posts: n/a
 
      08-10-2007
OMG. Im having a bad day:

try 0 to s'length-1 as the ret_slv demensions, otherwise your bus
will be returned back to front (and in your case not work at all)

 
Reply With Quote
 
Klaus Sandner
Guest
Posts: n/a
 
      08-10-2007
i think your proposal is not right for my problem

if s(i) = '0' then
> ret_slv(i-1) := '0';
> elsif s(i) = '1' then
> ret_slv(i-1) := '1';



I don't understand the conversion s(i) ='0'
s(i) ='1'
s is a string and the position if i is an aski byte








Tricky schrieb:
> Whoops I did that the wrong way round.
>
> The IEEE.std_logic_textio package has the ability to read/write
> std_logic_vectors from/to strings. These are procedures though. If you
> need a function:
>
> function string_to_slv(s : string) return std_logic_vector is
> variable ret_slv : std_logic_vector(s'length-1 downto 0);
> begin
> for i in 1 to s'length loop
> if s(i) = '0' then
> ret_slv(i-1) := '0';
> elsif s(i) = '1' then
> ret_slv(i-1) := '1';
> else
> --catch bad characters
> ret_slv(i-1) := 'X';
> end if;
>
> return ret_slv;
> end loop;
> end function;
>
>
>


 
Reply With Quote
 
Klaus Sandner
Guest
Posts: n/a
 
      08-10-2007
i think your proposal is not right for my problem

if s(i) = '0' then
> ret_slv(i-1) := '0';
> elsif s(i) = '1' then
> ret_slv(i-1) := '1';



I don't understand the conversion s(i) ='0'
s(i) ='1'
s is a string and the position if i is an aski byte








Tricky schrieb:
> Whoops I did that the wrong way round.
>
> The IEEE.std_logic_textio package has the ability to read/write
> std_logic_vectors from/to strings. These are procedures though. If you
> need a function:
>
> function string_to_slv(s : string) return std_logic_vector is
> variable ret_slv : std_logic_vector(s'length-1 downto 0);
> begin
> for i in 1 to s'length loop
> if s(i) = '0' then
> ret_slv(i-1) := '0';
> elsif s(i) = '1' then
> ret_slv(i-1) := '1';
> else
> --catch bad characters
> ret_slv(i-1) := 'X';
> end if;
>
> return ret_slv;
> end loop;
> end function;
>
>
>


 
Reply With Quote
 
Klaus Sandner
Guest
Posts: n/a
 
      08-10-2007
i think your proposal is not right for my problem

if s(i) = '0' then
> ret_slv(i-1) := '0';
> elsif s(i) = '1' then
> ret_slv(i-1) := '1';



I don't understand the conversion s(i) ='0'
s(i) ='1'
s is a string and the position if i is an aski byte








Tricky schrieb:
> Whoops I did that the wrong way round.
>
> The IEEE.std_logic_textio package has the ability to read/write
> std_logic_vectors from/to strings. These are procedures though. If you
> need a function:
>
> function string_to_slv(s : string) return std_logic_vector is
> variable ret_slv : std_logic_vector(s'length-1 downto 0);
> begin
> for i in 1 to s'length loop
> if s(i) = '0' then
> ret_slv(i-1) := '0';
> elsif s(i) = '1' then
> ret_slv(i-1) := '1';
> else
> --catch bad characters
> ret_slv(i-1) := 'X';
> end if;
>
> return ret_slv;
> end loop;
> end function;
>
>
>


 
Reply With Quote
 
Tricky
Guest
Posts: n/a
 
      08-13-2007
Ahh, Now I think I get the problem.

You cannot synthesize type STRING. You will have to make it a constant
or generic, and then have a function something like this to generate
the SLV you want to use:

function string_to_slvString(s : string) : return std_logic_vector
variable ret_slv : std_logic_vector(1 to s'length*;
begin

for i in 0 to s'length-1 loop
--unfortunatly you will have to do every single character conversion
manually:
case s(i) is
when 'a' => ret_slv( (i* + 1 to (i+1)*8 ) <= x"00";
when 'b' => ret_slv( (i* + 1 to (i+1)*8 ) <= x"01";
--
--
--
--etc
end case
end loop;

return ret_slv;

end function;


and then call it like this:

constant data_string :LCD_display_string := "test string for ";
constant LCD_display_bit is std_logic_vector(1 to
LCD_display_len* := string_to_slvString(data_string);

 
Reply With Quote
 
Russell Russell is offline
Junior Member
Join Date: Aug 2007
Posts: 6
 
      08-17-2007
the following will convert a character to an 8 bit ascii vector:

function ch2vec (
Data : character)
return std_logic_vector is
variable ch : std_logic_vector(7 downto 0);
begin
ch := conv_std_logic_vector(character'pos(Data),;
return ch;
end ch2vec;
the 'pos attribute will give the 'position' of a character in the ascii table
example usage:
data <= ch2vec(char); where char is say, a signal of type character eg. "A"
 
Reply With Quote
 
 
 
Reply

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
Convert formatted string to string? rockdale ASP .Net 3 04-12-2006 03:01 PM
convert string to the "escaped string" Petr Jakes Python 3 11-12-2005 05:32 PM
convert string to raw string? Phd Python 3 12-06-2004 04:36 PM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= ASP .Net 2 10-26-2004 02:43 PM
Convert string to a string array Andrew Banks ASP .Net 2 04-19-2004 04:45 PM



Advertisments