1212--
1313-- License:
1414-- =============================================================================
15- -- Copyright 2007-2015 Technische Universitaet Dresden - Germany
16- -- Chair of VLSI-Design, Diagnostics and Architecture
15+ -- Copyright 2025 The PoC-Library Authors
16+ -- Copyright 2007-2016 Technische Universitaet Dresden - Germany
17+ -- Chair of VLSI-Design, Diagnostics and Architecture
1718--
1819-- Licensed under the Apache License, Version 2.0 (the "License");
1920-- you may not use this file except in compliance with the License.
@@ -38,46 +39,49 @@ use work.components.all;
3839
3940entity arith_convert_bin2bcd is
4041 generic (
41- BITS : positive := 8 ;
42- DIGITS : positive := 3 ;
43- RADIX : positive := 2
42+ BITS : positive := 8 ;
43+ DIGITS : positive := 3 ;
44+ RADIX : positive := 2 ;
45+ REGISTER_OUTPUT : boolean := FALSE
4446 );
4547 port (
46- Clock : in std_logic ;
47- Reset : in std_logic ;
48+ Clock : in std_logic ;
49+ Reset : in std_logic ;
4850
49- Start : in std_logic ;
50- Busy : out std_logic ;
51+ Start : in std_logic ;
52+ Busy : out std_logic ;
5153
52- Binary : in std_logic_vector (BITS - 1 downto 0 );
53- IsSigned : in std_logic := '0' ;
54- BCDDigits : out T_BCD_VECTOR(DIGITS - 1 downto 0 );
55- Sign : out std_logic
54+ Binary : in std_logic_vector (BITS - 1 downto 0 );
55+ IsSigned : in std_logic := '0' ;
56+ BCDDigits : out T_BCD_VECTOR(DIGITS - 1 downto 0 );
57+ Sign : out std_logic
5658 );
5759end entity ;
5860
5961
6062architecture rtl of arith_convert_bin2bcd is
61- constant RADIX_BITS : positive := log2ceil(RADIX);
62- constant BINARY_SHIFTS : positive := div_ceil(BITS, RADIX_BITS);
63- constant BINARY_BITS : positive := BINARY_SHIFTS * RADIX_BITS;
63+ constant RADIX_BITS : positive := log2ceil(RADIX);
64+ constant BINARY_SHIFTS : positive := div_ceil(BITS, RADIX_BITS);
65+ constant BINARY_BITS : positive := BINARY_SHIFTS * RADIX_BITS;
6466
65- subtype T_CARRY is unsigned (RADIX_BITS - 1 downto 0 );
66- type T_CARRY_VECTOR is array (natural range <> ) of T_CARRY;
67+ subtype T_CARRY is unsigned (RADIX_BITS - 1 downto 0 );
68+ type T_CARRY_VECTOR is array (natural range <> ) of T_CARRY;
6769
68- signal Digit_Shift_rst : std_logic ;
69- signal Digit_Shift_en : std_logic ;
70- signal Digit_Shift_in : T_CARRY_VECTOR(DIGITS downto 0 );
70+ signal Digit_Shift_rst : std_logic ;
71+ signal Digit_Shift_en : std_logic ;
72+ signal Digit_Shift_in : T_CARRY_VECTOR(DIGITS downto 0 );
73+
74+ signal Binary_en : std_logic ;
75+ signal Binary_rl : std_logic ;
76+ signal Binary_d : std_logic_vector (BINARY_BITS - 1 downto 0 ) := (others => '0' );
77+
78+ signal Sign_d : std_logic := '0' ;
79+ signal DelayShifter : std_logic_vector (BINARY_SHIFTS downto 0 ) := '1' & (BINARY_SHIFTS - 1 downto 0 => '0' );
7180
72- signal Binary_en : std_logic ;
73- signal Binary_rl : std_logic ;
74- signal Binary_d : std_logic_vector (BINARY_BITS - 1 downto 0 ) := (others => '0' );
7581
76- signal Sign_d : std_logic := '0' ;
77- signal DelayShifter : std_logic_vector (BINARY_SHIFTS downto 0 ) := '1' & (BINARY_SHIFTS - 1 downto 0 => '0' );
7882
7983 function nextBCD(Value : unsigned (4 downto 0 )) return unsigned is
80- constant Temp : unsigned (4 downto 0 ) := Value - 10 ;
84+ constant Temp : unsigned (4 downto 0 ) := Value - 10 ;
8185 begin
8286 if Value > 9 then
8387 return '1' & Temp(3 downto 0 );
@@ -87,66 +91,73 @@ architecture rtl of arith_convert_bin2bcd is
8791 end function ;
8892
8993begin
90- Busy <= not DelayShifter(DelayShifter'high );
94+ Busy <= not DelayShifter(DelayShifter'high );
9195
92- Binary_en <= Start;
93- Binary_rl <= Start nor DelayShifter(DelayShifter'high );
94- Digit_Shift_rst <= Start;
95- Digit_Shift_en <= Start nor DelayShifter(DelayShifter'high );
96+ Binary_en <= Start;
97+ Binary_rl <= Start nor DelayShifter(DelayShifter'high );
98+ Digit_Shift_rst <= Start;
99+ Digit_Shift_en <= Start nor DelayShifter(DelayShifter'high );
96100
97101 process (Clock)
98102 begin
99103 if rising_edge (Clock) then
100104 if (Reset = '1' ) then
101- Binary_d <= (others => '0' );
105+ Binary_d <= (others => '0' );
102106 elsif (Binary_en = '1' ) then
103- Binary_d(Binary_d'high downto Binary'high ) <= (others => '0' );
107+ Binary_d(Binary_d'high downto Binary'high ) <= (others => '0' );
104108 if ((IsSigned and Binary(Binary'high )) = '1' ) then
105- Binary_d(Binary'high downto 0 ) <= std_logic_vector (- signed (Binary));
106- Sign_d <= '1' ;
109+ Binary_d(Binary'high downto 0 ) <= std_logic_vector (- signed (Binary));
110+ Sign_d <= '1' ;
107111 else
108- Binary_d(Binary'high downto 0 ) <= Binary;
109- Sign_d <= '0' ;
112+ Binary_d(Binary'high downto 0 ) <= Binary;
113+ Sign_d <= '0' ;
110114 end if ;
111- DelayShifter <= (BINARY_SHIFTS downto 1 => '0' ) & '1' ;
115+ DelayShifter <= (BINARY_SHIFTS downto 1 => '0' ) & '1' ;
112116 elsif (Binary_rl = '1' ) then
113- DelayShifter <= DelayShifter(DelayShifter'high - 1 downto 0 ) & DelayShifter(DelayShifter'high );
114- Binary_d <= Binary_d(Binary_d'high - RADIX_BITS downto 0 ) & Binary_d(Binary_d'high downto Binary_d'high - RADIX_BITS + 1 );
117+ DelayShifter <= DelayShifter(DelayShifter'high - 1 downto 0 ) & DelayShifter(DelayShifter'high );
118+ Binary_d <= Binary_d(Binary_d'high - RADIX_BITS downto 0 ) & Binary_d(Binary_d'high downto Binary_d'high - RADIX_BITS + 1 );
115119 end if ;
116120 end if ;
117121 end process ;
118122
119- Sign <= Sign_d;
120- Digit_Shift_in(0 ) <= unsigned (Binary_d(Binary_d'high downto Binary_d'high - RADIX_BITS + 1 ));
123+ Sign <= Sign_d;
124+ Digit_Shift_in(0 ) <= unsigned (Binary_d(Binary_d'high downto Binary_d'high - RADIX_BITS + 1 ));
121125
122126 -- generate DIGITS many systolic elements
123127 genDigits : for i in 0 to DIGITS - 1 generate
124- signal Digit_nxt : unsigned (3 + RADIX_BITS downto 0 );
125- signal Digit_d : unsigned (3 downto 0 ) := (others => '0' );
128+ signal Digit_nxt : unsigned (3 + RADIX_BITS downto 0 );
129+ signal Digit_d : unsigned (3 downto 0 ) := (others => '0' );
126130 begin
127131 process (Digit_d, Digit_Shift_in)
128132 variable Temp : unsigned (4 downto 0 );
129133 begin
130134 Temp := '0' & Digit_d;
131135 for j in RADIX_BITS - 1 downto 0 loop
132- Temp := nextBCD(Temp(3 downto 0 ) & Digit_Shift_in(i)(j));
133- Digit_nxt(j + 4 downto j) <= Temp;
136+ Temp := nextBCD(Temp(3 downto 0 ) & Digit_Shift_in(i)(j));
137+ Digit_nxt(j + 4 downto j) <= Temp;
134138 end loop ;
135139 end process ;
136140
137- Digit_Shift_in(i + 1 ) <= Digit_nxt(Digit_nxt'high downto Digit_nxt'high - RADIX_BITS + 1 );
141+ Digit_Shift_in(i + 1 ) <= Digit_nxt(Digit_nxt'high downto Digit_nxt'high - RADIX_BITS + 1 );
138142
139143 process (Clock)
140144 begin
141145 if rising_edge (Clock) then
142- if ( Digit_Shift_rst = '1' ) then
146+ if Reset = '1' or Digit_Shift_rst = '1' then
143147 Digit_d <= "0000" ;
144148 elsif (Digit_Shift_en = '1' ) then
145149 Digit_d <= Digit_nxt(Digit_d'range );
146150 end if ;
147151 end if ;
148152 end process ;
149153
150- BCDDigits(i) <= T_BCD(std_logic_vector (Digit_d));
154+ unstableOutput: if not REGISTER_OUTPUT generate
155+ BCDDigits(i) <= T_BCD(std_logic_vector (Digit_d));
156+ else generate
157+ signal BCDDigits_d : BCDDigits'element := (others => '0' );
158+ begin
159+ BCDDigits_d <= T_BCD(std_logic_vector (Digit_d)) when rising_edge (Clock) and Busy = '0' ;
160+ BCDDigits(i) <= BCDDigits_d;
161+ end generate ;
151162 end generate ;
152- end ;
163+ end architecture ;
0 commit comments