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.

[SOLVED] How to convert ufixed to ASCII characters or STRING - VHDL

Status
Not open for further replies.

Akanimo

Advanced Member level 3
Advanced Member level 3
Joined
Aug 30, 2016
Messages
866
Helped
146
Reputation
292
Reaction score
169
Trophy points
1,323
Activity points
7,282
Hi,

Please what are the possible ways to convert a numerical value in fixed-point to ASCII characters or string in VHDL? I intend to send the characters for display on a screen.
 
Last edited:

I’m not quite sure what you’re trying to do. VHDL is not intended to ”display characters on a screen”. If you’re trying to convert an 8bit value to ASCII you could use a lookup table.
 
I'm working on some real-time control system. So part of it's task is to compute certain process parameters and some of the computed parameters have fractional parts and the fractional part is significant. So it demands the use of fixed-point representation. I need to send some of these parameters out for display on a screen.

Any alternative way to accomplish this is also welcome.
 

Hi,

There may be solutions to use some floating point data processing via VHDL. But it is the hard way and not necessary.
I recommend to do it as integers and treat them as fixed point.

Example:
You get a 10 bit ADC value representing 0...5V and you want to show it as "0.00" to "5.00" volts.
Then simply do an integer multiplication with 500 (the displayed dynamic range) and shift the result 10 bits (input range) right.
(Instead of shift in VHDL you'd just use bits 10...16).
With inputs 0...1024 (1023) you get output of 0...500.
Do the BCD conversion and show the three digits. "000" to "500". Then add a decimal point after the second digit from right.
--> "0.00" ... "5.00".

Klaus
 
@KLAUS at no point was floating point mentioned - Akanimo mentions ufixed with the a VHDL fixed point representation type. It is a type that does fixed point mathematics in a convenient type. It is simply integer arithmatics as suggested.

Using integer maths (like signed/unsigned) requires the user to track the integer fraction separations in words. With fixed point types, this is all handled for you in the type and no bit selection needed.

@Akanimo
To display on a screen, you'll need some form of display driver. Or are you simply trying to display the value on a console during simulation?
 
@KLAUS at no point was floating point mentioned - Akanimo mentions ufixed with the a VHDL fixed point representation type. It is a type that does fixed point mathematics in a convenient type. It is simply integer arithmatics as suggested.

Using integer maths (like signed/unsigned) requires the user to track the integer fraction separations in words. With fixed point types, this is all handled for you in the type and no bit selection needed.

@Akanimo
To display on a screen, you'll need some form of display driver. Or are you simply trying to display the value on a console during simulation?

No, not about simulation. It's really about converting a fixed point value to equivalent ASCII format. Say '123.45' would be 'ASCII for 1''ASCII for 2''ASCII for 3''ASCII for 4''ASCII for 5' the decimal point can be inserted while storing the ASCII (result) or while sending out the result.

I got a hold of what Klaus recommended and I checked it out with decimal number system and its a good solution because it's easier than the idea I had in mind. Klaus's solution just requires the fixed point value to be multiplied by an appropriate power of 10 based on the significant decimal places and then convert it to straight binary convert to ASCII through BCD and then insert the decimal point (i.e. its ASCII equivalent) at the appropriate place (which depends on the powers of 10 that the fixed point value was multiplied with). That is what I pictured from Klaus's recommendation.

My idea would require a function to extract the fractional part of the fixed-poi nt number, add the decimal equivalents for each place value up to the number of decimal places required for all bits that are '1', convert the result to a vector and then to ASCII through BCD and pad it to the ASCII equivalent of the whole number part of the fixed point number with the decimal point inserted.

Other possible solutions are welcome please.
 

Double dabble algorithm the usual method for binary to BCD conversion.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top