pia-468x60

pia-728x90

Showing posts with label Timer. Show all posts
Showing posts with label Timer. Show all posts

Monday, December 11, 2023

XC9536 CPLD Simple Three-Digit Multiplexing Display Using VHDL

In this VHDL Example, an XC9536 CPLD drives a 3-digit common cathode multiplexing display. It requires a square signal generator for display timing. The generator frequency is 60Hz generated by an on-board NE555 square wave oscillator. Each digits are activated for 16 milliseconds.







XC9536 CPLD Simple Three-Digit Multiplexing Display Using VHDL
XC9536 Prototyping Board 

VHDL codes for this example is very simple. We directly assign 7-segment data to each digits. However we can use VHDL array data type.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 14:41:42 12/11/2023
  6. -- Design Name:
  7. -- Module Name: mux_3 - 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 mux_3 is
  33. Port ( CLK : in STD_LOGIC;
  34. COM : out STD_LOGIC_VECTOR (2 downto 0);
  35. DAT : out STD_LOGIC_VECTOR (7 downto 0));
  36. end mux_3;
  37.  
  38. architecture Behavioral of mux_3 is
  39.  
  40. begin
  41. process(CLK)
  42. variable count : INTEGER RANGE 0 TO 2;
  43. begin
  44. if(CLK'EVENT AND CLK='1') then count:=count+1; end if;
  45. CASE count IS
  46. WHEN 0 =>
  47. DAT<=x"06"; COM<="001";
  48. WHEN 1 =>
  49. DAT<=x"5B"; COM<="010";
  50. WHEN 2 =>
  51. DAT<=x"4F"; COM<="100";
  52. WHEN OTHERS => NULL;
  53. END CASE;
  54. end process;
  55.  
  56.  
  57.  
  58. end Behavioral;
  59.  
  60.  

All 7-Segment data pins share with the on-board output LEDs. So it reduce driving current. I use an ULN2003 transistors array to drive each common pins.

I assign all output pins in Xilinx PACE as follow.

XC9536 CPLD Simple Three-Digit Multiplexing Display Using VHDL
Pin Assignments

Click here to download its source file.

XC9536 CPLD Simple Three-Digit Multiplexing Display Using VHDL

If you are a beginner in VHDL you can watch this video to see the overall process.



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.



Labels

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