0

I am currently a beginner programming to an FPGA board in VHDL using Quartus II. I need to convert an 8 bit number of type std_logic_vector to three separate 4 bit std_logic_vector variables so that i may display a decimal number on three 7 segment displays (the largest number in that will be dealt with is 254). currently i am using repeated subtraction division to handle this, however in compilation the while loop which i use is unable to resolve within 10000 iterations. the loop is shown below:

while (rmdr > "000000000") loop

                while (rmdr > "000001001") loop

                    while (rmdr > "001100011") loop
                        dig2 := dig2 + '1';
                        rmdr := rmdr - "001100100";
                    end loop;

                    dig1 := dig1 + '1';
                    rmdr := rmdr - "000001010";

                end loop;

                dig0 := dig0 + '1';
                rmdr := rmdr - "000000001";

            end loop;

Any help or insight to this matter would be greatly appreciated.

coolKoala
  • 13
  • 1
  • 4
  • 1
    Would it change anything to restructure the loops so they're sequential rather than nested? – Mark Ransom Dec 01 '15 at 05:03
  • 1
    Possible duplicate of [Convert 8bit binary number to BCD in VHDL](http://stackoverflow.com/questions/23871792/convert-8bit-binary-number-to-bcd-in-vhdl) – Morten Zilmer Dec 01 '15 at 07:04
  • 1
    StackOverflow is full of BCD and 7-segment display code ... please search the network. – Paebbels Dec 01 '15 at 07:16

1 Answers1

0

I looks like you need `BCD converter.

Have a look at this website

8 bit binary to bcd convertor

function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector is
variable i : integer:=0;
variable bcd : std_logic_vector(11 downto 0) := (others => '0');
variable bint : std_logic_vector(7 downto 0) := bin;

begin
for i in 0 to 7 loop  -- repeating 8 times.
bcd(11 downto 1) := bcd(10 downto 0);  --shifting the bits.
bcd(0) := bint(7);
bint(7 downto 1) := bint(6 downto 0);
bint(0) :='0';


if(i < 7 and bcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4.
bcd(3 downto 0) := bcd(3 downto 0) + "0011";
end if;

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

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


end loop;
return bcd;
end to_bcd;
Anonymous
  • 336
  • 3
  • 23