Binary to BCD in VHDL - vhdl

This is a discussion on Binary to BCD in VHDL - vhdl ; 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 add3 algoritam http://www.engr.udayton.edu/faculty/...in_to_BCD.html After this code executes I always get "0000" in digit and unit ...

+ Reply to Thread
Results 1 to 6 of 6

Binary to BCD in VHDL

  1. Default Binary to BCD in VHDL

    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 add3
    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 ****yze 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;

  2. Default Re: Binary to BCD in VHDL

    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.



  3. Default Re: Binary to BCD in VHDL

    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, fb@frank-buss.de
    http://www.frank-buss.de, http://www.it4-systems.de

  4. Default Re: Binary to BCD in VHDL

    Thank you both !

  5. Default Re: Binary to BCD in VHDL

    Hello, I was wondering if you could run the code.
    Sorry if my English is bad, I am using machine translation.
    Thanks!

  6. Default Re: Binary to BCD in VHDL

    pls I need a vhdl code for 16 bit binary to bcd converter urgently.

    thanks and regards
    gigs

+ Reply to Thread

Similar Threads

  1. Re: convert binary string into binary array
    By Application Development in forum labview
    Replies: 3
    Last Post: 10-31-2007, 11:40 AM
  2. Replies: 7
    Last Post: 10-22-2007, 05:27 AM
  3. VHDL-2002 vs VHDL-93 vs VHDL-87?
    By Application Development in forum vhdl
    Replies: 1
    Last Post: 03-23-2007, 04:33 AM
  4. VHDL Standards Overview of Accellera VHDL 2006 Standard 3.0
    By Application Development in forum vhdl
    Replies: 0
    Last Post: 10-13-2006, 04:24 PM
  5. Need binary comparision tool and binary parsers
    By Application Development in forum Compilers
    Replies: 1
    Last Post: 08-07-2005, 03:16 PM