Binary To BCD - VHD
Binary To BCD - VHD
--
-- FileName: binary_to_bcd.vhd
-- Dependencies: binary_to_bcd_digit.vhd
-- Design Software: Quartus II 64-bit Version 13.1.0 Build 162 SJ Web Edition
--
-- HDL CODE IS PROVIDED "AS IS." DIGI-KEY EXPRESSLY DISCLAIMS ANY
-- WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
-- PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL DIGI-KEY
-- BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
-- DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
-- PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
-- BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
-- ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
--
-- Version History
-- Version 1.0 6/15/2017 Scott Larson
-- Initial Public Release
-- Version 1.1 6/23/2017 Scott Larson
-- Fixed small corner-case bug
-- Version 1.2 1/16/2018 Scott Larson
-- Fixed reset logic to include resetting the state machine
--
--------------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY binary_to_bcd IS
GENERIC(
bits : INTEGER := 10; --size of the binary input numbers in bits
digits : INTEGER := 3); --number of BCD digits to convert to
PORT(
clk : IN STD_LOGIC; --system clock
reset_n : IN STD_LOGIC; --active low asynchronus
reset
ena : IN STD_LOGIC; --latches in new binary
number and starts conversion
binary : IN STD_LOGIC_VECTOR(bits-1 DOWNTO 0); --binary number to
convert
busy : OUT STD_LOGIC; --indicates conversion
in progress
bcd : OUT STD_LOGIC_VECTOR(digits*4-1 DOWNTO 0)); --resulting BCD number
END binary_to_bcd;
BEGIN
PROCESS(reset_n, clk)
VARIABLE bit_count : INTEGER RANGE 0 TO bits+1 := 0; --counts the binary bits
shifted into the converters
BEGIN
IF(reset_n = '0') THEN --asynchronous reset asserted
bit_count := 0; --reset bit counter
busy <= '1'; --indicate not available
converter_ena <= '0'; --disable the converter
bcd <= (OTHERS => '0'); --clear BCD result port
state <= idle; --reset state machine
ELSIF(clk'EVENT AND clk = '1') THEN --system clock rising edge
CASE state IS
END CASE;
END IF;
END PROCESS;
END logic;