FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-07-2004, 10:56 PM
weizbox
Guest
 
Posts: n/a
Default bin to bcd for same number

Hello,

I was wondering if there is a way to easily change a bin number to a
bcd without a lookup table or anyhting else like that if the numbers
do not need to convert.

Example: I have a decimal value of 1234 in a 12-bit binary reg. I
would like to transfer those values to a 16-bit bcd. No conversions
needed, I still want 1234, just in bcd. Is there an easy way to do
this?

-Mark
Reply With Quote
  #2 (permalink)  
Old 10-07-2004, 11:27 PM
glen herrmannsfeldt
Guest
 
Posts: n/a
Default Re: bin to bcd for same number



weizbox wrote:

> I was wondering if there is a way to easily change a bin number to a
> bcd without a lookup table or anyhting else like that if the numbers
> do not need to convert.


For small numbers of digits, the amount of logic is
pretty small. It can easily be done in combinatorial
logic.

The work toward a decimal based floating point standard
uses 10 bits to store three digits. It is supposed to take
only a small amount of logic to convert between that and BCD.

Write out the Karnaugh maps and see how much logic it takes.

(There are also logic minimization programs around to do it.)

-- glen

Reply With Quote
  #3 (permalink)  
Old 10-07-2004, 11:46 PM
John_H
Guest
 
Posts: n/a
Default Re: bin to bcd for same number

"weizbox" <[email protected]> wrote in message
news:[email protected] om...
> Hello,
>
> I was wondering if there is a way to easily change a bin number to a
> bcd without a lookup table or anyhting else like that if the numbers
> do not need to convert.
>
> Example: I have a decimal value of 1234 in a 12-bit binary reg. I
> would like to transfer those values to a 16-bit bcd. No conversions
> needed, I still want 1234, just in bcd. Is there an easy way to do
> this?
>
> -Mark


How about this for 4 digits: (some of the LSbits can be truncated - I just
haven't done an error analysis or testbench)
wire [22:0] res3;
wire [21:0] res2;
wire [20:0] res1;
wire [19:0] res2;
wore [3:0] bcd3, bcd2, bcd1, bcd0;
assign {bcd3,res3} = bin[12:0] * 14'h20c5; // 5 adds, 4 adders in a tree
assign {bcd2,res2} = res3 * 3'h5;
assign {bcd1,res1} = res2 * 3'h5;
assign {bcd0,res0} = res1 * 3'h5;

The idea here is use a fixed/flaoting-point hybrid. The first thing you'd
like is to "effectively" divide by 1000 which - though close at 131/131072
(131/2^17) provides better results at 8389/8388608 (8389/2^23). The first
BCD digit is the multiplied result shifted 23 bits. The fractional part is
effectively multiplied by 10 ("fractional" multiplied by 5 and shifted 1)
to get the next digit 22 bits out.

The implementation looks better in code and can be manipulated further for a
smaller implementation with the appropriate error analysis.

The idea is the same in software: find the first digit by dividing by 1000
(or 10000, whatever) then get successive digits from 10x the fractional
part.


Reply With Quote
  #4 (permalink)  
Old 10-08-2004, 01:31 PM
Thomas Womack
Guest
 
Posts: n/a
Default Re: bin to bcd for same number

In article <LOi9d.24$[email protected]>,
John_H <[email protected]> wrote:

>How about this for 4 digits: (some of the LSbits can be truncated - I just
>haven't done an error analysis or testbench)
>wire [22:0] res3;
>wire [21:0] res2;
>wire [20:0] res1;
>wire [19:0] res2;
>wore [3:0] bcd3, bcd2, bcd1, bcd0;
>assign {bcd3,res3} = bin[12:0] * 14'h20c5; // 5 adds, 4 adders in a tree
>assign {bcd2,res2} = res3 * 3'h5;
>assign {bcd1,res1} = res2 * 3'h5;
>assign {bcd0,res0} = res1 * 3'h5;


That's lovely, makes me realise I ought to study _Hacker's Delight_
(by Henry S Warren, for those unfortunates who haven't read it yet)
more. Its tricks no longer seem quite so relevant on CPUs with
two-cycle 64x64->128 multipliers, but they're going to be really handy
on FPGA.

Tom
Reply With Quote
  #5 (permalink)  
Old 10-08-2004, 11:17 PM
John_H
Guest
 
Posts: n/a
Default Re: bin to bcd for same number

"weizbox" <[email protected]> wrote in message
news:[email protected] om...
> Hello,
>
> I was wondering if there is a way to easily change a bin number to a
> bcd without a lookup table or anyhting else like that if the numbers
> do not need to convert.
>
> Example: I have a decimal value of 1234 in a 12-bit binary reg. I
> would like to transfer those values to a 16-bit bcd. No conversions
> needed, I still want 1234, just in bcd. Is there an easy way to do
> this?
>
> -Mark


I just did a quick google - always nice to do *first* - and found
http://www.opencores.org/projects.cg...o_bcd/overview

Check it out for your needs. (it took me a moment to find the "Downloads"
in the top right corner).


Reply With Quote
  #6 (permalink)  
Old 10-12-2004, 04:02 PM
weizbox
Guest
 
Posts: n/a
Default Re: bin to bcd for same number

"John_H" <[email protected]> wrote in message news:<PtD9d.33$[email protected]>...
> "weizbox" <[email protected]> wrote in message
> news:[email protected] om...
> > Hello,
> >
> > I was wondering if there is a way to easily change a bin number to a
> > bcd without a lookup table or anyhting else like that if the numbers
> > do not need to convert.
> >
> > Example: I have a decimal value of 1234 in a 12-bit binary reg. I
> > would like to transfer those values to a 16-bit bcd. No conversions
> > needed, I still want 1234, just in bcd. Is there an easy way to do
> > this?
> >
> > -Mark

>
> I just did a quick google - always nice to do *first* - and found
> http://www.opencores.org/projects.cg...o_bcd/overview
>
> Check it out for your needs. (it took me a moment to find the "Downloads"
> in the top right corner).



Thanks for pointing out the download link! I was actually there but
didnt see the downloads, all I saw was no files in CVS thing and since
the dev status was in "planning" that the file wasnt available! Thanks
a lot!

-Mark
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test of Random Number for Icarus Verilog Stephen Williams Verilog 1 06-10-2004 04:23 PM
How to vary the number and width of ports? Steven Alexander Verilog 3 05-14-2004 03:33 PM
psedo random number generator krs Verilog 15 05-02-2004 09:57 AM
Negative number representation in verilog endmodule Verilog 0 03-06-2004 10:26 AM


All times are GMT +1. The time now is 03:20 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved