Monday, February 5, 2024

XC95108 VHDL Parallel to Serial Shift Registers and Arduino Example

A parallel to serial shift register is useful for microprocessor digital inputs extending. For instant a keypad input for printer for photocopier machine. There are many off-the-shelf parallel to serial shift register chips, especially the SN74HC165.

XC95108 VHDL Parallel to Serial Shift Registers and Arduino Example
Hardware Testing

Using a programmable logic device we can design this kind of chip with customizable operations, and the numbers of I/O. This job could be done with a CPLD chip and its design tool, VHLD, Verilog code, or even schematic design tool.

XC95108 VHDL Parallel to Serial Shift Registers and Arduino Example
Running Arduino Program and the XC95108

In this example, I use an XC95108 CPLD to design a parallel to serial converter chip. VHDL code is preferred for this design. This design contains,

  • Clock (CLK) input,
  • LOAD input to latch data from an 8-bit digital input to the internal register,
  • Serial Data Out (DOUT) that shift data serially at the rising edge of input clock,
  • Digital Input (D) is an 8-bit data input.

The overall process requires 9 clock cycles. At the first clock, data will be read and latched into an internal register, then the 8-bit serial data shifting out will be processed.

  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 08:31:41 02/03/2024
  6. -- Design Name:
  7. -- Module Name: parallel_serial_2 - 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. entity parallel_serial_2 is
  24. Port ( CLK : in STD_LOGIC;
  25. LOAD : in STD_LOGIC;
  26. DOUT : out STD_LOGIC;
  27. D : in STD_LOGIC_VECTOR (7 downto 0));
  28. end parallel_serial_2;
  29.  
  30. architecture Behavioral of parallel_serial_2 is
  31. SIGNAL REG: STD_LOGIC_VECTOR(7 DOWNTO 0);
  32. begin
  33. PROCESS(CLK,LOAD)
  34. BEGIN
  35. IF(CLK'EVENT AND CLK='1') THEN
  36. IF(LOAD='1') THEN REG<=D;
  37. ELSE REG<=REG(6 DOWNTO 0)&'0'; END IF;
  38. END IF;
  39. END PROCESS;
  40. DOUT<=REG(7);
  41. end Behavioral;
  42.  
  43.  

You can use the FloorPlan I/O tool in the ISE Design Suite to assign its I/O pins. On the XC95108 CPLD Prototype Board, I set the I/O as follow.

  1. #PACE: Start of Constraints generated by PACE
  2.  
  3. #PACE: Start of PACE I/O Pin Assignments
  4. NET "CLK" LOC = "P50" ;
  5. NET "D<0>" LOC = "P48" ;
  6. NET "D<1>" LOC = "P47" ;
  7. NET "D<2>" LOC = "P46" ;
  8. NET "D<3>" LOC = "P45" ;
  9. NET "D<4>" LOC = "P44" ;
  10. NET "D<5>" LOC = "P43" ;
  11. NET "D<6>" LOC = "P41" ;
  12. NET "D<7>" LOC = "P40" ;
  13. NET "DOUT" LOC = "P52" ;
  14. NET "LOAD" LOC = "P51" ;
  15. #PACE: Start of PACE Area Constraints
  16.  
  17. #PACE: Start of PACE Prohibit Constraints
  18.  
  19. #PACE: End of Constraints generated by PACE
  20.  

The Arduino is very popular for most of electronics projects. I use an Arduino Uno to read the data from this chip.

  1.  
  2.  
  3. const char clockPin= 13;
  4. const char Enable = 10;
  5. const char dataPin=12;
  6.  
  7. uint8_t incoming=0,oldData;
  8.  
  9. void setup() {
  10. Serial.begin(9600);
  11. Serial.println("Arduino ShiftIn And XC95108 Parallel To Serial Converter.");
  12. pinMode(clockPin,OUTPUT);
  13. pinMode(Enable,OUTPUT);
  14. pinMode(dataPin,INPUT);
  15. digitalWrite(clockPin,LOW);
  16. digitalWrite(Enable,LOW);
  17. }
  18.  
  19. void loop() {
  20. digitalWrite(Enable,HIGH);
  21. digitalWrite(clockPin,LOW);
  22. digitalWrite(clockPin,HIGH);
  23. digitalWrite(Enable,LOW);
  24.  
  25. for(uint8_t i=0;i<8;i++){
  26. digitalWrite(clockPin,LOW);
  27. if(digitalRead(dataPin)==1) incoming|=(1<<(7-i));
  28. else incoming&=~(1<<(7-i));
  29. digitalWrite(clockPin,HIGH);
  30. }
  31. if(incoming!=oldData){
  32. Serial.println("Received 8-Bit HEX Data: 0x" + String(incoming,HEX));
  33. Serial.println("Received 8-Bit BIN Data: 0b" + String(incoming,BIN));
  34. oldData=incoming;
  35. }
  36. // Serial.println(incoming,HEX);
  37. //Serial.println(incoming,BIN);
  38. delay(1500);
  39. }

Click here to download this example.



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)