ASCII

M

Matt North

Guest
I need to decode ASCII characters into their binary format to use an ouput.
I was writing a 2D array with two integer type pointers for x,y which when
decoded into binary would give the ascii for that symbol.

I noticed however that standard.vhd has a character array which holds all of
the ascii characters, Leonardo decodes this into binary.
Is there anyway of getting to this conversion so that my code would convert
ascii characters into their decoded vector form?

P.S. This is for a project which drives a VFD, (traditionally done using a
micro) - if anyone has any experience of running VFD or Dot Matrix Displays
using VHDL, tips would be grately received.

Matt
 
"Matt North" <m.r.w.north@rl.ac.uk> writes:

I need to decode ASCII characters into their binary format to use an ouput.
I was writing a 2D array with two integer type pointers for x,y which when
decoded into binary would give the ascii for that symbol.

I noticed however that standard.vhd has a character array which holds all of
the ascii characters, Leonardo decodes this into binary.
Is there anyway of getting to this conversion so that my code would convert
ascii characters into their decoded vector form?
I assume what you want to do is convert ASCII A -> dec 65 -> bin
0100_0001?

The 'pos attribute tells you where something appears within the
character "array", then you can use numeric_std's functions to turn
that integer into a std_logic_vector.

<untested code to give the idea>
signal ch : character := 'A';
signal intch : integer;
signal binch : std_logic_vector(7 downto 0);

intch <= ch'pos;
binch <= std_logic_vector(to_unsigned(intch, 8));

or something.



Does that help?

Martin

--
martin.j.thompson@trw.com
TRW Conekt, Solihull, UK
http://www.trw.com/conekt
 
Martin,

using the predefined type attribute T'POS(X) the prefix T cannot be of type
character or string.
so ch'pos in the code below would cause an error.

However i think this may work;

type ch is (
nul, soh, stx, etx, eot, enq, ack, bel,
bs, ht, lf, vt, ff, cr, so, si,
dle, dc1, dc2, dc3, dc4, nak, syn, etb,
can, em, sub, esc, fsp, gsp, rsp, usp,

' ', '!', '"', '#', '$', '%', '&', ''',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',

'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\', ']', '^', '_',

'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', del,

c128, c129, c130, c131, c132, c133, c134, c135,
c136, c137, c138, c139, c140, c141, c142, c143,
c144, c145, c146, c147, c148, c149, c150, c151,
c152, c153, c154, c155, c156, c157, c158, c159,

-- the character code for 160 is there (NBSP),
-- but prints as no char

' ', 'Ą', '˘', 'Ł', '¤', 'Ľ', 'Ś', '§',
'¨', 'Š', 'Ş', 'Ť', 'Ź', '­', 'Ž', 'Ż',
'°', 'ą', '˛', 'ł', '´', 'ľ', 'ś', 'ˇ',
'¸', 'š', 'ş', 'ť', 'ź', '˝', 'ž', 'ż',

'Ŕ', 'Á', 'Â', 'Ă', 'Ä', 'Ĺ', 'Ć', 'Ç',
'Č', 'É', 'Ę', 'Ë', 'Ě', 'Í', 'Î', 'Ď',
'Đ', 'Ń', 'Ň', 'Ó', 'Ô', 'Ő', 'Ö', '×',
'Ř', 'Ů', 'Ú', 'Ű', 'Ü', 'Ý', 'Ţ', 'ß',

'ŕ', 'á', 'â', 'ă', 'ä', 'ĺ', 'ć', 'ç',
'č', 'é', 'ę', 'ë', 'ě', 'í', 'î', 'ď',
'đ', 'ń', 'ň', 'ó', 'ô', 'ő', 'ö', '÷',
'ř', 'ů', 'ú', 'ű', 'ü', 'ý', 'ţ', '˙' );

intch <= ch'pos('A');

--then conversion form integer to 8 bit vector

ch is then an enumerated type which is a correct prefix for the T'POS
prefix.

A quick test in Modelsim outputs the correct results, the next step is to
pick out each char from a string and convert to bin.
Thanks for your help.

Matt

"Martin Thompson" <martin.j.thompson@trw.com> wrote in message
news:ubrshtux3.fsf@trw.com...
"Matt North" <m.r.w.north@rl.ac.uk> writes:

I need to decode ASCII characters into their binary format to use an
ouput.
I was writing a 2D array with two integer type pointers for x,y which
when
decoded into binary would give the ascii for that symbol.

I noticed however that standard.vhd has a character array which holds
all of
the ascii characters, Leonardo decodes this into binary.
Is there anyway of getting to this conversion so that my code would
convert
ascii characters into their decoded vector form?


I assume what you want to do is convert ASCII A -> dec 65 -> bin
0100_0001?

The 'pos attribute tells you where something appears within the
character "array", then you can use numeric_std's functions to turn
that integer into a std_logic_vector.

untested code to give the idea
signal ch : character := 'A';
signal intch : integer;
signal binch : std_logic_vector(7 downto 0);

intch <= ch'pos;
binch <= std_logic_vector(to_unsigned(intch, 8));

or something.



Does that help?

Martin

--
martin.j.thompson@trw.com
TRW Conekt, Solihull, UK
http://www.trw.com/conekt
 
Matt,

A couple of quick clarifications:
using the predefined type attribute T'POS(X) the prefix T cannot be of type
character or string.
-- not entirely true: T'POS(X) works for prefix which is 'any discrete or
physical type or subtype T', which means that it works for CHARACTER, but
not for STRING. [FYI: 'discrete'=integer or enumeration]

type ch is (
nul, soh, stx, etx, eot, enq, ack, bel,
-- you are creating EXACT copy of standard type CHARACTER; no reason to do it!

And finally, Martin's idea was good, but some errors sneaked into the sample
code. Here's correct, working version:

signal ch : character := 'A';
signal intch : integer;
signal binch : std_logic_vector(7 downto 0);

intch <= character'pos(ch);
binch <= std_logic_vector(to_unsigned(intch, 8));

Remember to add
use IEEE.numeric_std.all;
to get access to conversion function to_unsigned

Good luck!

Jerry
 
Jerry,

I realised this during yesterday and was able to get the code simulated and
working well.
The next step was to pick a character out of a string on each rising edge
and pass the selected character to the position attribute, thus outputing
bin for a ASCII string.
The code is shown below;

subtype int_r is integer range 0 to 40;
signal n : int_r;
signal str : string(0 to 39);
signal ch_index : character;

string<="etc, etc";

process(clk, rst, n)
begin
if rising_edge(clk) then
if (rst='0' or n=40) then
n <= 1;
else
n <= n+1;
end if;
end if;
end process;

ch_index<=str(n);
intch<=character'POS(ch_index);

etc.................etc

Modelsim generates an error when this code is compiled (something to do with
indexed values)!
I suppose the POS attribute wants to see ch_index in its table, and cant see
the character value that ch_index holds.

Anyway, this part of the project is in the background at the moment as i am
having difficulty driving the VFD at the moment, if i cant get the ascii
conversion to work i will write the data to the
VFD in HEX form, but even that isnt working at the moment - its hard to send
data once when the whole thing is clocked!!

Thanks,
Matt.

"Jerry" <jaroslawk@hotmail.com> wrote in message
news:711e889f.0310160804.6d167f7a@posting.google.com...
Matt,

A couple of quick clarifications:
using the predefined type attribute T'POS(X) the prefix T cannot be of
type
character or string.
-- not entirely true: T'POS(X) works for prefix which is 'any discrete or
physical type or subtype T', which means that it works for CHARACTER, but
not for STRING. [FYI: 'discrete'=integer or enumeration]

type ch is (
nul, soh, stx, etx, eot, enq, ack, bel,
-- you are creating EXACT copy of standard type CHARACTER; no reason to do
it!

And finally, Martin's idea was good, but some errors sneaked into the
sample
code. Here's correct, working version:

signal ch : character := 'A';
signal intch : integer;
signal binch : std_logic_vector(7 downto 0);

intch <= character'pos(ch);
binch <= std_logic_vector(to_unsigned(intch, 8));

Remember to add
use IEEE.numeric_std.all;
to get access to conversion function to_unsigned

Good luck!

Jerry
 
jaroslawk@hotmail.com (Jerry) writes:

<snip>
And finally, Martin's idea was good, but some errors sneaked into the sample
code. Here's correct, working version:
Doh - I knew I should have tested it first :) Sorry for any confusion!

signal ch : character := 'A';
signal intch : integer;
signal binch : std_logic_vector(7 downto 0);

intch <= character'pos(ch);
binch <= std_logic_vector(to_unsigned(intch, 8));
Cheers,
Martin

--
martin.j.thompson@trw.com
TRW Conekt, Solihull, UK
http://www.trw.com/conekt
 
Matt North a écrit :
Jerry,

I realised this during yesterday and was able to get the code simulated and
working well.
The next step was to pick a character out of a string on each rising edge
and pass the selected character to the position attribute, thus outputing
bin for a ASCII string.
The code is shown below;

subtype int_r is integer range 0 to 40;
signal n : int_r;
signal str : string(0 to 39);
The string type is defined in STANDARD package of STD library as:
type STRING is array (POSITIVE range <>) of CHARACTER;
So you can't have a 0 index in your string.

signal ch_index : character;

string<="etc, etc";

process(clk, rst, n)
rst and n should not be in your sensivity list.

begin
if rising_edge(clk) then
if (rst='0' or n=40) then
n <= 1;
else
n <= n+1;
end if;
end if;
end process;

ch_index<=str(n);
intch<=character'POS(ch_index);
Sugestion:

signal N: POSITIVE range 1 to 40;
....
N <= 1 when RISING_EDGE(CLK) and (RST = '0' or N = 40) else
N+1 when RISING_EDGE(CLK);
INTCH <= CHARACTER'POS(STR(N));

Regards,
--
Renaud Pacalet, GET/ENST/COMELEC/LabSoC
Institut Eurecom BP 193, 2229 route des Cretes
F-06904 Sophia-Antipolis Cedex
Tel : +33 (0) 4 9300 2770
Fax : +33 (0) 4 9300 2627
Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/
 

Welcome to EDABoard.com

Sponsor

Back
Top