Binary to BCD in VHDL

  • Follow


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/jloomis/ece314/notes/devices/binary_=
to_BCD/bin_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) :=3D "00011000";  --24 (10)
   variable unit: bit_vector(3 downto 0) :=3D "0000";
   variable digit: bit_vector(3 downto 0):=3D "0000";
   begin
   for i in 0 to 7 loop
		digit    :=3D digit sll 1;
		digit(0) :=3D unit(3);
		unit     :=3D unit sll 1;
		unit(0)  :=3D temp(7);
		temp     :=3D 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" =3D> digit :=3D "1000";
			when "0110" =3D> digit :=3D "1001";
			when "0111" =3D> digit :=3D "1010";
			when "1000" =3D> digit :=3D "1011";
			when "1001" =3D> digit :=3D "1100";
			when others =3D> digit :=3D digit;
		end case;
	=

		case unit is
			when "0101" =3D> unit :=3D "1000";
			when "0110" =3D> unit :=3D "1001";
			when "0111" =3D> unit :=3D "1010";
			when "1000" =3D> unit :=3D "1011";
			when "1001" =3D> unit :=3D "1100";
			when others =3D> unit :=3D digit;
		end case;
	end loop;
0
Reply NA 5/23/2007 5:28:19 PM

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.


0
Reply Michael 5/24/2007 7:28:03 AM


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.lang.vhdl/msg/32a9a02c2b2b838d

-- 
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
0
Reply Frank 5/24/2007 7:50:15 AM

Thank you both !
0
Reply NA 5/24/2007 2:02:20 PM

3 Replies
846 Views

(page loaded in 0.052 seconds)

Similiar Articles:













7/21/2012 5:18:35 PM


Reply: