Kepsz
Member level 1
I trying to implement this methode of binary to bcd conversation: It uses the shift 3x -> add + 3 if grather than 5 -> shift 1x methode.
This code works, grabs the 16 bit from the input, then puts them to a 20 bit long vector, after four zeros (like 000011010011....), where shifts them left by 3 bits. The next stage separates the 20 bit to 5*4bit, then put the 4 bits to a 5 bit long vector, after a zero (like 01001). This first zero will be the carry. But after that i stuckd, if i convert values to integer, it's just made simple conversations like 00110 to 110 integer, instead of 6.
So I looking for a way to manipulate the vectors, adding "00001" and "00101" to them. If this is not possible with vectors, maybe in integer or something else.
This module will be part of my Spartan3E kit's design. Now my kit shows it's ADC's output value in 7 segments display like F3E instead of 3902 decimal.
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity hex_to_bcd is
port (
CLK_in: in std_logic;
INPUT: in std_logic_vector(15 downto 0));
end hex_to_bcd;
architecture Behavioral of hex_to_bcd is
signal bcd_0 : std_logic_vector( 0 to 19);
signal bcd_1,bcd_2,bcd_3,bcd_4,bcd_5 : std_logic_vector( 0 to 4);
signal int_1,int_2,int_3,int_4,int_5 : integer range 0 to 32;
begin
Process (CLK_in, INPUT)
begin
if (rising_edge(CLK_in)) then
bcd_0 <= to_stdlogicvector(to_bitvector("0000" & INPUT) sll 3);
bcd_1 <= "0" & bcd_0(16 to 19);
bcd_2 <= "0" & bcd_0(12 to 15);
bcd_3 <= "0" & bcd_0(8 to 11);
bcd_4 <= "0" & bcd_0(4 to 7);
bcd_5 <= "0" & bcd_0(0 to 3);
int_1 <= to_integer(unsigned(bcd_1));
int_2 <= to_integer(unsigned(bcd_2));
int_3 <= to_integer(unsigned(bcd_3));
int_4 <= to_integer(unsigned(bcd_4));
int_5 <= to_integer(unsigned(bcd_5));
end if;
end process;
end Behavioral;
This code works, grabs the 16 bit from the input, then puts them to a 20 bit long vector, after four zeros (like 000011010011....), where shifts them left by 3 bits. The next stage separates the 20 bit to 5*4bit, then put the 4 bits to a 5 bit long vector, after a zero (like 01001). This first zero will be the carry. But after that i stuckd, if i convert values to integer, it's just made simple conversations like 00110 to 110 integer, instead of 6.
So I looking for a way to manipulate the vectors, adding "00001" and "00101" to them. If this is not possible with vectors, maybe in integer or something else.
This module will be part of my Spartan3E kit's design. Now my kit shows it's ADC's output value in 7 segments display like F3E instead of 3902 decimal.