Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Binary to BCD in VHDL

Reply
Thread Tools

Binary to BCD in VHDL

 
 
NA
Guest
Posts: n/a
 
      05-23-2007
Hello all.
I'm very new to VHDL and stuck with a simple task.
This code should convert binary number to BCD number using shift and add 3
algoritam
http://www.engr.udayton.edu/faculty/...in_to_BCD.html

After this code executes I always get "0000" in digit and unit

You don't have to analyze the whole code, just tell me what is generally
wrong. Thank you people!

variable temp: bit_vector(7 downto 0) := "00011000"; --24 (10)
variable unit: bit_vector(3 downto 0) := "0000";
variable digit: bit_vector(3 downto 0):= "0000";
begin
for i in 0 to 7 loop
digit := digit sll 1;
digit(0) := unit(3);
unit := unit sll 1;
unit(0) := temp(7);
temp := temp sll 1;
--This is the part where I add 3, is there any other way? It must work
on FPGA
case digit is
when "0101" => digit := "1000";
when "0110" => digit := "1001";
when "0111" => digit := "1010";
when "1000" => digit := "1011";
when "1001" => digit := "1100";
when others => digit := digit;
end case;

case unit is
when "0101" => unit := "1000";
when "0110" => unit := "1001";
when "0111" => unit := "1010";
when "1000" => unit := "1011";
when "1001" => unit := "1100";
when others => unit := digit;
end case;
end loop;
 
Reply With Quote
 
 
 
 
Michael Jorgensen
Guest
Posts: n/a
 
      05-24-2007
I see two problems:

1) Third line from the bottom: "unit := digit" -> "unit := unit"
2) The web page talks about "hundreds" too. The line "digit := digit sll
1;" in your code seems to lose some bits.

-Michael.


 
Reply With Quote
 
 
 
 
Frank Buss
Guest
Posts: n/a
 
      05-24-2007
NA wrote:

> --This is the part where I add 3, is there any other way? It must work
> on FPGA


you could use a function to avoid code duplication, like I've used in my
adder example:

http://groups.google.com/group/comp....a9a02c2b2b838d

--
Frank Buss,
http://www.frank-buss.de, http://www.it4-systems.de
 
Reply With Quote
 
NA
Guest
Posts: n/a
 
      05-24-2007
Thank you both !
 
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
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
Re: binary to BCD assistance Paul Leventis VHDL 4 03-26-2008 09:16 PM
binary to BCD updown counter gina VHDL 0 10-08-2007 03:32 PM
8 bit binary to 2 digit BCD Yama VHDL 3 06-09-2006 07:48 PM
Re: binary to BCD assistance Glen Herrmannsfeldt VHDL 4 07-31-2003 11:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57