Binary to BCD

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

formatting link
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;

Reply to
NA
Loading thread data ...

formatting link

Please do your own homework, thank you.

Reply to
Kryten

This is not a homework and I NEVER asked "you" to write this for me. All I asked is what is wrong like people ask in 90% other posts. So you're reply is very rude, but you already know that.

Anyway I found my problem. That piece of code was in a process sensitive to clock (50MHz) and it would execute many times instead of one. If you sll something "many" times you get zeros.

Reply to
NA

Hey, the basic ida looks good, but it's not very adaptable...

I was just wondering whether you'd taken a look at

formatting link

from this i made a generic converter, which takes two generic integers to define its length in terms of SB and BCD outputs.

It's a nice little project following from your starting point, you might recognise the name of one of the authors from this group.

Anyways - good luck! Ben

Reply to
Benjamin Todd

This can't be the problem of the code you've posted, because "temp" is redefined every time and the rest of the steps are executed serially, because that's the way "variable" works, so you'll have the right "temp" value at the end. The problem with your code is the "unit := digit" line at the end, because "digit" is 0 at the first loop iteration and then "unit" becomes 0, too.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

Madid, don't get angry. Your question smelled like a typical homework assignment, and that's not what this newsgroup is meant to solve. I take your word for it, that it was NOT homework.

Recently we have been flooded with trivial questi> On Thu, 24 May 2007 02:38:49 +0200, Kryten

Reply to
Peter Alfke

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.