16bit to bcd conversion
<p>I'm trying to make a 16bit to BCD conversion.
I have found this link for a 8 bit and I'm trying to convert it to 16 bits.
<a href="http://vhdlguru.blogspot.nl/2010/04/8-bit-binary-to-bcd-converter-double.html" rel="nofollow">http://vhdlguru.blogspot.nl/2010/04/8-bit-binary-to-bcd-converter-double.html</a></p>

<p>I don't know what im doing wrong the rpm_1000 keeps changing and the rpm_100 stays at 4. Does anyone have a idea what i did wrong?</p>

<pre><code>process (Hex_Display_Data)
        variable i : integer:=0;
        variable bcd : std_logic_vector(19 downto 0) := (others =&gt; '0');
        variable bint : std_logic_vector(15 downto 0) := Hex_Display_Data;

    begin
        for i in 0 to 15 loop  -- repeating 16 times.
        bcd(19 downto 1) := bcd(18 downto 0);  --shifting the bits.
        bcd(0) := bint(15); -- shift bit in
        bint(15 downto 1) := bint(14 downto 0); --removing msb
        bint(0) :='0'; -- adding a '0'


        if(i &lt; 15 and bcd(3 downto 0) &gt; "0100") then --add 3 if BCD digit is greater than 4.
        bcd(3 downto 0) := bcd(3 downto 0) + "0011";
        end if;

        if(i &lt; 15 and bcd(7 downto 4) &gt; "0100") then --add 3 if BCD digit is greater than 4.
        bcd(7 downto 4) := bcd(7 downto 4) + "0011";
        end if;

        if(i &lt; 15 and bcd(11 downto 8) &gt; "0100") then  --add 3 if BCD digit is greater than 4.
        bcd(11 downto 8) := bcd(11 downto 8) + "0011";
        end if;

        if(i &lt; 15 and bcd(15 downto 12) &gt; "0100") then  --add 3 if BCD digit is greater than 4.
        bcd(15 downto 12) := bcd(15 downto 12) + "0011";
        end if;

    end loop;

    rpm_1000    &lt;= bcd(15 downto 12);
    rpm_100     &lt;= bcd(11 downto 8);
    rpm_10      &lt;= bcd(7 downto 4);
    rpm_1       &lt;= bcd(3 downto 0);


end process ;
</code></pre>