Saturday, December 9, 2023

XC9536 CPLD Free Running Counter with 7-Segment Display Using VHDL

Introduction

A digital counter circuit can be made from scratch by using some digital ICs that contains a counter (eg, 74LS90), a 7-Segment decoder(eg, 74LS47), a 7-Segment display, a switch, and some passive components. 







However we can use a microcontroller or even a programmable logic device to to such electronics stuff. Using a CPLD we can generate a digital circuit that able to replace some ASICs functionalities. An XC9536 CPLD can be used to design a small digital circuit with a little number of I/O.

XC9536 CPLD Free Running 7-Segment Counter Using VHDL
Testing On Experiment Board

I design a free running counter using VHDL code. It has a frequency divider, a counter, reset circuit, and a seven segment decoder inside. So we don't need to inter-connect between chips as the standard digital circuit does.

Design Tools

VHDL is simple to code. For XC9536 CPLD we can use ISE Design Suite. It's free for most of small CPLD and FPGA. Using this tool we can code VHDL, Verilog, or design by using Schematic tool. To program target device we can use a USB JTAG, or even a DIY parallel port JTAG cable.

The CASE Statement

This statement is only allowed inside sequential circuit (PROCESS or subprogram). Like SELECT, CASE too allows the use of multiple values, which can be grouped with "|" or "TO".

WHEN value value1|value2|...    --value1 or value2 or ...
WHEN value1 TO value2            --range (for enumerated type only)

It requires that all input values be covered (complete truth table), for which the keyword OTHERS is often helpful. Another important keyword is NULL (the counterpart of UNAFFECTED, used with SELECT), which should be used when no action is to take place. (Circuit Design and Simulation with VHDL, Second Edition)

In this example I use this statement as follow.

CASE tmp IS
			WHEN	0	=> Q<=x"3F";
			WHEN	1	=> Q<=x"06";
			WHEN	2	=> Q<=x"5B";
			WHEN	3	=> Q<=x"4F";
			WHEN	4	=> Q<=x"66";
			WHEN	5	=> Q<=x"6D";
			WHEN	6	=> Q<=x"7D";
			WHEN	7	=> Q<=x"07";
			WHEN	8	=> Q<=x"7F";
			WHEN	9	=> Q<=x"6F";
			WHEN	10	=> Q<=x"77";
			WHEN	11	=> Q<=x"7C";
			WHEN	12	=> Q<=x"39";
			WHEN	13      => Q<=x"5E";
			WHEN	14	=> Q<=x"79";
			WHEN	15	=> Q<=x"71";
			WHEN	OTHERS	=> NULL;
		END CASE;

It contain 16 values plus one NULL value in OTHERS keyword. Letter x represent hexadecimal numbers.

VHDL Design

In VHDL code I use,

  • one input clock pin (CLK),
  • one reset pin (CLR),
  • one blinking output (BLK),
  • 8-bit output data (Q),
  • one counting variable (cmp) for frequency division,
  • and one temporary variable (tmp) for counting value.

Its ARCHITECTURE uses sequential statements.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 17:30:14 12/09/2023
  6. -- Design Name:
  7. -- Module Name: count_up - 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 count_up is
  33. Port ( CLK : in BIT;
  34. CLR : in BIT;
  35. BLK : buffer BIT;
  36. Q : out STD_LOGIC_VECTOR (7 downto 0));
  37. end count_up;
  38.  
  39. architecture Behavioral of count_up is
  40.  
  41. begin
  42.  
  43. Process(CLK,CLR)
  44. variable cmp : INTEGER RANGE 0 TO 99;
  45. variable tmp : INTEGER RANGE 0 TO 15;
  46. begin
  47. if(CLR='0') then
  48. cmp:=0; tmp:=0;
  49. elsif(CLK'event AND CLK='1') then
  50. cmp:=cmp+1;
  51. if(cmp>=50) then
  52. cmp:=0;
  53. tmp:=tmp+1;
  54. BLK<=NOT BLK;
  55. end if;
  56. end if;
  57. CASE tmp IS
  58. WHEN 0 => Q<=x"3F";
  59. WHEN 1 => Q<=x"06";
  60. WHEN 2 => Q<=x"5B";
  61. WHEN 3 => Q<=x"4F";
  62. WHEN 4 => Q<=x"66";
  63. WHEN 5 => Q<=x"6D";
  64. WHEN 6 => Q<=x"7D";
  65. WHEN 7 => Q<=x"07";
  66. WHEN 8 => Q<=x"7F";
  67. WHEN 9 => Q<=x"6F";
  68. WHEN 10 => Q<=x"77";
  69. WHEN 11 => Q<=x"7C";
  70. WHEN 12 => Q<=x"39";
  71. WHEN 13 => Q<=x"5E";
  72. WHEN 14 => Q<=x"79";
  73. WHEN 15 => Q<=x"71";
  74. WHEN OTHERS => NULL;
  75. END CASE;
  76.  
  77. end process;
  78. end Behavioral;
  79.  
  80.  

BLK is an output buffer because we need to read and write this bit.

XC9536 CPLD Free Running 7-Segment Counter Using VHDL
ISE Design Suite 14.7


I/O Pin Assignment

We need to assign inputs and output for this design using Xilinx PACE.

XC9536 CPLD Free Running 7-Segment Counter Using VHDL
Pin Assignments


After the pin assignments completed we click save and close this windows. The ISE will generate a user constraints file.

#PACE: Start of Constraints generated by PACE
#PACE: Start of PACE I/O Pin Assignments
NET "BLK"  LOC = "P33"  ; 
NET "CLK"  LOC = "P5"  ; 
NET "CLR"  LOC = "P19"  ; 
NET "Q<0>"  LOC = "P3"  ;
NET "Q<1>"  LOC = "P4"  ;
NET "Q<2>"  LOC = "P8"  ;
NET "Q<3>"  LOC = "P9"  ;
NET "Q<4>"  LOC = "P11"  ;
NET "Q<5>"  LOC = "P13"  ;
NET "Q<6>"  LOC = "P12"  ;
NET "Q<7>"  LOC = "P7"  ;
#PACE: Start of PACE Area Constraints
#PACE: Start of PACE Prohibit Constraints
#PACE: End of Constraints generated by PACE

XC9536 CPLD Free Running 7-Segment Counter Using VHDL
CPLD Reports


Device Programming

After the Pin Assignments is ready we have to re-run the Implement Design again to get a  *.jed programming file. It will be used to upload to the XC9536 internal Flash memory.

XC9536 CPLD Free Running 7-Segment Counter Using VHDL
Device Programming


This parallel port JTAG header must be unplug after use because it has a detection pin on PC parallel port.



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)