Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

integer to character

Status
Not open for further replies.

ya_montazar

Member level 2
Member level 2
Joined
Feb 24, 2014
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
342
Hi,

I want to convert an integer to a charecter. i.e when I give x"30" it becomes converted to '0';

Is there any correct way to do this?

I tried to use:

Code:
tmp <= character ' val( int_tmp );

but it generated an syntax error:

"Attribute is not authorized : 'val'."

Regards,
 

Is this language like BASIC? Because 'VAL' accepts a character string, looks for numerical digits, and returns the number.

The keyword 'CHR$' accepts an ASCII number and returns a string.

'ASC' accepts a character and returns its ASCII code.
 

Brad: this is VHDL. But not synthesisable
OP: I assume you're just trying to simulate it, not synthesise it.

have you tried:

tmp <= character'val( int_tmp ); --removed the whitespace

This is the correct conversion method. What is the range of int_tmp. It will only work in the range 0 to 255.
 
Brad: this is VHDL. But not synthesisable
OP: I assume you're just trying to simulate it, not synthesise it.

.

thank you, it is not synthesisable??
Is there any synthesisable way to do this??

have you tried:

tmp <= character'val( int_tmp ); --removed the whitespace

This is the correct conversion method. What is the range of int_tmp. It will only work in the range 0 to 255
no, I didn't put spaces and the range of int_tmp is correct.
 

thank you, it is not synthesisable??
Is there any synthesisable way to do this??

Why would you want to? a character has no use in synthesisable code. they are useful in debugging when printing data out to the console or to a file, but neither is possible in synthesisable code.

Why not show more of the code or tell us what you're trying to acheive.
 

well, I want to convert ASCII commands comming from inputs to integer and after some change send it as report or sth in character array output, in VHDL
 
Last edited:

All inputs will just be Binary, so they are already integers.
You need to remember you're working at the gate level, not the abstracted level. Have you thought about what hardware the code will produce? if you dont know what the hardware will be, you should draw it on a peice of paper BEFORE you code any VHDL.
 
All inputs will just be Binary, so they are already integers.
I know they must be binary. look, I recieve a command in ascii. i.e. "m0" in binary type;
Code:
command_input : in std_logic_vector(15 downto 0); -- now a command can recieve like "m0" or x"6d30"
(or could it be ??:
Code:
type character_vector is array (natural range <>) of character;
command_input : in character_vector(1 downto 0); -- now a command can recieve like "m0" or x"6d30"
)
and first I want to make it equivalent to when it comes in capital word : "M0"
and at second decode it to a meaningful command.
 
Last edited:

What you never showed us was the code. You've just shown single line ideas.
The problem is some synthesisors may not support it. And to be honest, its nothing more than a fudge around in VHDL anyway. x"6d30" is identical to "m0", so whats the big issue? you will be adding extra type casting into the code, when you could write meaningful comments around your code.
 

It seems these attributes are not authorized in new standards, while I test the code in quartus 8.1 and there wasn't any problem.
I have seen IEEE Standard VHDL 2000 while the new ones have been published and it may be changed.
 

Quartus has been stuck with VHDL 1993 for a long time, and still is. Checking the 2008 compile option doesnt mean it is fully 2008 compliant. The "authorisation" of the attributes is nothing to do with the VHDL standard.

What Quartus version are you using, and are you using VHDL 1993 or VHDL 2008? have you tried switching back to 1993?

- - - Updated - - -

And you havent even posted the code that refuses to compile.. I wouldnt make assumptions without at least getting a second look.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top