Thursday, December 7, 2023

XC9536 CPLD Ring Counter Example Using VHDL

A digital electronics ring counter chip is popular for electronics hobbyists especially in a DIY LED chasing circuit. A common digital IC ring counter is the CD4017. It's easily to find with a very low price.

XC9536 CPLD Ring Counter Example Using VHDL
Ring Counter Testing On XC9536 CPLD Board









XC9536 CPLD Ring Counter Example Using VHDL
A Ring Counter Board Using CD4017 And NE555 Oscillator

However we can use a programmable logic device to design a simple ring counter circuit. A small CPLD "XC9536" can do this job. I use VHDL to build a ring counter. We can customize a number of outputs and its operating modes.

I use clock and clear input signal. The output is an 8-bit standard logic vector. Input clock is driven from a 60Hz on-board NE555 square signal generator.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 07:53:59 12/08/2023
  6. -- Design Name:
  7. -- Module Name: ring_counter - 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. use IEEE.STD_LOGIC_UNSIGNED.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 ring_counter is
  34. Port ( CLK : in BIT;
  35. CLR : in BIT;
  36. Q : out STD_LOGIC_VECTOR (7 downto 0));
  37. end ring_counter;
  38.  
  39. architecture Behavioral of ring_counter is
  40.  
  41. begin
  42.  
  43. process(CLK,CLR)
  44. variable cmp : INTEGER RANGE 0 TO 10;
  45. variable tmp : INTEGER RANGE 0 TO 7;
  46.  
  47. begin
  48. if(CLR = '1') then
  49. tmp:=0;
  50. cmp:=0;
  51. elsif(CLK'EVENT AND CLK='1') then
  52. cmp:=cmp+1;
  53. if(cmp>=5) then
  54. cmp:=0;
  55. tmp:=tmp+1;
  56. end if;
  57. end if;
  58.  
  59. case tmp is
  60. when 0 => Q <= x"01";
  61. when 1 => Q <= x"02";
  62. when 2 => Q <= x"04";
  63. when 3 => Q <= x"08";
  64. when 4 => Q <= x"10";
  65. when 5 => Q <= x"20";
  66. when 6 => Q <= x"40";
  67. when 7 => Q <= x"80";
  68. when OTHERS => NULL;
  69. end case;
  70. end process;
  71.  
  72. end Behavioral;
  73.  
  74.  

Using VHDL to design this circuit is very easy. If we don't prefer it we can design this ring counter digital circuit using schematic tool.

XC9536 CPLD Ring Counter Example Using VHDL
Register Transfer Level - RTL


We can look at its CPLD reports to know its resource usage.

XC9536 CPLD Ring Counter Example Using VHDL
CPLD Reports

After the design is succeed we need to assign its I/O pins using Floorplan IO.

XC9536 CPLD Ring Counter Example Using VHDL
Xilinx PACE

When we already assigned all I/O pins we need to save and close it. A user constraint ".ucf" will be generated by software.

#PACE: Start of Constraints generated by PACE
#PACE: Start of PACE I/O Pin Assignments
NET "CLK"  LOC = "P5"  ;
NET "CLR"  LOC = "P25"  ;
NET "Q<0>"  LOC = "P40"  ;
NET "Q<1>"  LOC = "P39"  ;
NET "Q<2>"  LOC = "P38"  ;
NET "Q<3>"  LOC = "P37"  ;
NET "Q<4>"  LOC = "P36"  ;
NET "Q<5>"  LOC = "P35"  ;
NET "Q<6>"  LOC = "P34"  ;
NET "Q<7>"  LOC = "P33"  ;
#PACE: Start of PACE Area Constraints
#PACE: Start of PACE Prohibit Constraints
#PACE: End of Constraints generated by PACE


We will need to re-run the Implement Design again to get CPLD ".jed" program file. We have to run the iMPACT tool to program the target CPLD device.

XC9536 CPLD Ring Counter Example Using VHDL
iMPACT


I use a parallel port JTAG cable "Parallel Cable III". The version of ISE Design is 14.7. It run on Windows 10 64-bit. Some of IBM type Desktop PC have a legacy parallel port. Click here to download the VHDL and user constraint 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)