Saturday, December 9, 2023

XC9536 CPLD Binary To Hexadecimal Conversion Using VHDL

Overview

In this VHDL example, I use an XC9536 CPLD to read a 4-bit binary input. This input will translate to a hexadecimal value on a single common cathode 7-segment display. The XC9536 CPLD experiment board has four input slide switches, and eight output LEDs. So we don't need to use an additional bread board.







XC9536 CPLD Binary To Hexadecimal Conversion Using VHDL
when the binary input is "0000"

The SELECT Statement

I use VHDL SELECT statement. It's a concurrent statement that's similar to the sequential statement CASE. The SELECT statement allows the use of multiple values (instead of multiple conditions). It requires that all input values be covered (complete truth table), for which the keyword OTHERS is often helpful. (Reference: Circuit Design With VHDL, Second Edition)

With BIN Select
HEX	<=	"0111111"	when	"0000",	-- 0
		"0000110"	when	"0001",	-- 1
		"1011011"	when	"0010",	-- 2
		"1001111"	when	"0011",	-- 3
		"1100110"	when	"0100",	-- 4
		"1101101"	when	"0101",	-- 5
		"1111101"	when	"0110", -- 6
		"0000111"	when	"0111",	-- 7
		"1111111"	when	"1000",	-- 8
		"1101111"	when	"1001",	-- 9
		"1110111"	when	"1010",	-- A
		"1111100"	when	"1011",	-- B
		"0111001"	when	"1100",	-- C
		"1011110"	when	"1101",	-- D
		"1111001"	when	"1110",	-- E
		"1110001"	when	"1111",	-- F
		"0000000"	when 	OTHERS;

This design creates a concurrent circuit. That's not require of input clock.

VHDL Code

There are one 4-bit input, and one 7 bit output. The inputs read a digital value created by slide switches while the output connects to a single common cathode display. The display shows a hexadecimal value ranges from 0 to F.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 11:15:56 12/09/2023
  6. -- Design Name:
  7. -- Module Name: bin_to_hex - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. --use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. entity bin_to_hex is
  33. Port ( BIN : in STD_LOGIC_VECTOR (3 downto 0);
  34. HEX : out STD_LOGIC_VECTOR (6 downto 0));
  35. end bin_to_hex;
  36.  
  37. architecture Behavioral of bin_to_hex is
  38.  
  39. begin
  40.  
  41. With BIN Select
  42. HEX <= "0111111" when "0000", -- 0
  43. "0000110" when "0001", -- 1
  44. "1011011" when "0010", -- 2
  45. "1001111" when "0011", -- 3
  46. "1100110" when "0100", -- 4
  47. "1101101" when "0101", -- 5
  48. "1111101" when "0110", -- 6
  49. "0000111" when "0111", -- 7
  50. "1111111" when "1000", -- 8
  51. "1101111" when "1001", -- 9
  52. "1110111" when "1010", -- A
  53. "1111100" when "1011", -- B
  54. "0111001" when "1100", -- C
  55. "1011110" when "1101", -- D
  56. "1111001" when "1110", -- E
  57. "1110001" when "1111", -- F
  58. "0000000" when OTHERS;
  59.  
  60. end Behavioral;
  61.  
  62.  

We should try to compile this source code first before we assign the I/O on CPLD.

Pin Assignments

Under the User Constraints, double click on the Floorplan IO to open the Xilinx PACE tool.

XC9536 CPLD Binary To Hexadecimal Conversion Using VHDL
Pin Assignments


After saving and close this window the ISE Design Suite will generate a user constraints ".ucf" file.

#PACE: Start of Constraints generated by PACE
#PACE: Start of PACE I/O Pin Assignments
NET "BIN<0>" LOC = "P28" ;
NET "BIN<1>" LOC = "P27" ;
NET "BIN<2>" LOC = "P26" ;
NET "BIN<3>" LOC = "P25" ;
NET "HEX<0>" LOC = "P3" ;
NET "HEX<1>" LOC = "P4" ;
NET "HEX<2>" LOC = "P8" ;
NET "HEX<3>" LOC = "P9" ;
NET "HEX<4>" LOC = "P11" ;
NET "HEX<5>" LOC = "P13" ;
NET "HEX<6>" LOC = "P12" ;
#PACE: Start of PACE Area Constraints
#PACE: Start of PACE Prohibit Constraints
#PACE: End of Constraints generated by PACE

Click here to download its source file.

Programming the CPLD

After pin assignments is completed, we need to re-run the Implement Design. After it's finished we expand the Configure Target Device, and run the Manage Configuration Project (iMPACT).

XC9536 CPLD Binary To Hexadecimal Conversion Using VHDL
Xilinx iMPACT Tool

The Parallel Cable III is useable under Microsoft Windows 10.

XC9536 CPLD Binary To Hexadecimal Conversion Using VHDL
Maximum Value
You can watch the overall process on YouTube.


The WHEN Statement

We can use VHDL WHEN statement to create this binary to hexadecimal converter. WHEN is the simplest conditional statement. It is approximately equivalent to the sequential statement IF. (Reference: Circuit Design With VHDL, Second Edition)

HEX	<=	"0111111"	When	BIN="0000" 	else	--      0
		"0000110"	When	BIN="0001"	else	--	1
		"1011011"	When	BIN="0010"	else	--	2
		"1001111"	When	BIN="0011"	else	--	3
		"1100110"	When	BIN="0100"	else	--	4
		"1101101"	When	BIN="0101"	else	--	5
		"1111101"	When	BIN="0110"	else	--	6
		"0000111"	When	BIN="0111"	else	--	7
		"1111111"	When	BIN="1000"	else	--	8
		"1101111"	When	BIN="1001"	else	--	9
		"1110111"	When	BIN="1010"	else	--	A
		"1111100"	When	BIN="1011"	else	--	B
		"0111001"	When	BIN="1100"	else	--	C
		"1011110"	When	BIN="1101"	else	--	D
		"1111001"	When	BIN="1110"	else	--	E
		"1110001"	When	BIN="1111";		--      F

Its complete VHDL code is shown below.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 16:14:08 12/09/2023
  6. -- Design Name:
  7. -- Module Name: bin_2_hex - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. --use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. entity bin_2_hex is
  33. Port ( BIN : in STD_LOGIC_VECTOR (3 downto 0);
  34. HEX : out STD_LOGIC_VECTOR (6 downto 0));
  35. end bin_2_hex;
  36.  
  37. architecture Behavioral of bin_2_hex is
  38.  
  39. begin
  40.  
  41. HEX <= "0111111" When BIN="0000" else -- 0
  42. "0000110" When BIN="0001" else -- 1
  43. "1011011" When BIN="0010" else -- 2
  44. "1001111" When BIN="0011" else -- 3
  45. "1100110" When BIN="0100" else -- 4
  46. "1101101" When BIN="0101" else -- 5
  47. "1111101" When BIN="0110" else -- 6
  48. "0000111" When BIN="0111" else -- 7
  49. "1111111" When BIN="1000" else -- 8
  50. "1101111" When BIN="1001" else -- 9
  51. "1110111" When BIN="1010" else -- A
  52. "1111100" When BIN="1011" else -- B
  53. "0111001" When BIN="1100" else -- C
  54. "1011110" When BIN="1101" else -- D
  55. "1111001" When BIN="1110" else -- E
  56. "1110001" When BIN="1111"; -- F
  57.  
  58. end Behavioral;
  59.  
  60.  

The operating function using the SELECT statement.

XC9536 CPLD Binary To Hexadecimal Conversion Using VHDL
The WHEN Statement

Click here to download its source code.

No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)