Wednesday, December 13, 2023

XC9536 Three Digits Counter Using VHDL

In this VHDL Example, an XC9536 CPLD will drive a three-digit common cathode multiplexing display. Each digits represent individual counting value ranges from 0 to 9 decimal values. A larger CPLD can create a 0 to 999 digital counters but this small XC9536 CPLD run out of resource. So I just design an individual digit counters.

XC9536 Three Digits Counter Using VHDL
Running Circuit on an XC9536 CPLD Prototyping Board







This digital circuit design contains only on sequential process activates by input clock and reset signal.

  1. if
  2. ----------------------------------------------------------------------------------
  3. -- Company:
  4. -- Engineer:
  5. --
  6. -- Create Date: 09:36:40 12/12/2023
  7. -- Design Name:
  8. -- Module Name: mux_counter - Behavioral
  9. -- Project Name:
  10. -- Target Devices:
  11. -- Tool versions:
  12. -- Description:
  13. --
  14. -- Dependencies:
  15. --
  16. -- Revision:
  17. -- Revision 0.01 - File Created
  18. -- Additional Comments:
  19. --
  20. ----------------------------------------------------------------------------------
  21. library IEEE;
  22. use IEEE.STD_LOGIC_1164.ALL;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity mux_counter is
  34. Port ( CLK : in STD_LOGIC;
  35. RST : in STD_LOGIC;
  36. UP_001 : in STD_LOGIC;
  37. UP_010 : in STD_LOGIC;
  38. UP_100 : in STD_LOGIC;
  39. COM : out STD_LOGIC_VECTOR (2 downto 0);
  40. DAT : out STD_LOGIC_VECTOR (7 downto 0));
  41. end mux_counter;
  42.  
  43. architecture Behavioral of mux_counter is
  44. type array_1 is array(0 to 9) of STD_LOGIC_VECTOR (7 downto 0);
  45. signal display : array_1 :=(x"3F",x"06",x"5B",x"4F",x"66",x"6D",x"7D",x"07",x"7F",x"6F");
  46.  
  47. begin
  48. process(CLK,RST,UP_001,UP_010,UP_100)
  49. variable freq_count : INTEGER RANGE 0 TO 2:=0;
  50. variable var_unit : INTEGER RANGE 0 TO 9:=0;
  51. variable var_ten : INTEGER RANGE 0 TO 9:=0;
  52. variable var_hun : INTEGER RANGE 0 TO 9:=0;
  53.  
  54. begin
  55. if(RST='0') then var_unit:=0; var_ten:=0; freq_count:=0;
  56. elsif(CLK'EVENT AND CLK='1') then
  57. freq_count:=freq_count+1;
  58.  
  59. CASE freq_count IS
  60. WHEN 0 =>
  61. DAT<=display(var_unit); COM<="001";
  62. WHEN 1 =>
  63. DAT<=display(var_ten); COM<="010";
  64. WHEN 2 =>
  65. DAT<=display(var_hun); COM<="100";
  66. if(UP_001='0') then
  67. var_unit:=var_unit+1;
  68. if(var_unit>9) then var_unit:=0; end if;
  69. end if;
  70.  
  71. if(UP_010='0') then
  72. var_ten:=var_ten+1;
  73. if(var_ten>9) then var_ten:=0; end if;
  74. end if;
  75.  
  76. if(UP_100='0') then
  77. var_hun:=var_hun+1;
  78. if(var_hun>9) then var_hun:=0; end if;
  79. end if;
  80. WHEN OTHERS => NULL;
  81. END CASE;
  82.  
  83. end if;
  84. end process;
  85.  
  86. end Behavioral;
  87.  
  88.  

Multiplexing display processed by the VHDL WHEN statement. Each input counting buttons are also place inside the WHEN statement because they require a longer period to be activated. So it reduce switch bouncing. 

XC9536 Three Digits Counter Using VHDL
Source Code Windows

I assigned its I/O pins as follow.

XC9536 Three Digits Counter Using VHDL
Xilinx PACE

Click save and close this windows a user constraints file will automatically generated by software.

#PACE: Start of Constraints generated by PACE
#PACE: Start of PACE I/O Pin Assignments
NET "CLK"    LOC = "P5"  ; 
NET "COM<0>"  LOC = "P42"  ; 
NET "COM<1>"  LOC = "P43"  ; 
NET "COM<2>"  LOC = "P44"  ; 
NET "DAT<0>"  LOC = "P33"  ; 
NET "DAT<1>"  LOC = "P34"  ; 
NET "DAT<2>"  LOC = "P35"  ; 
NET "DAT<3>"  LOC = "P36"  ; 
NET "DAT<4>"  LOC = "P37"  ; 
NET "DAT<5>"  LOC = "P38"  ; 
NET "DAT<6>"  LOC = "P39"  ; 
NET "DAT<7>"  LOC = "P40"  ; 
NET "RST"  LOC = "P26"  ;
NET "UP_001"  LOC = "P18"  ;
NET "UP_010"  LOC = "P19"  ;
NET "UP_100"  LOC = "P25"  ;
#PACE: Start of PACE Area Constraints
#PACE: Start of PACE Prohibit Constraints
#PACE: End of Constraints generated by PACE

An Xilinx Parallel Cable III still useable in Xilinx ISE Design Suites 14.7.

XC9536 Three Digits Counter Using VHDL
CPLD Reports

XC9536 Three Digits Counter Using VHDL
Xilinx Parallel Cable III JTAG Programming for XC9536 CPLD

If you are new to VHDL and Xilinx ISE Design Tool you can watch this video on YouTube.


Click here to download its source file.

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)