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.
|  | 
| 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.
|  | 
| 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.
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 08:31:41 02/03/2024
-- Design Name:
-- Module Name: parallel_serial_2 - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity parallel_serial_2 is
Port ( CLK : in STD_LOGIC;
LOAD : in STD_LOGIC;
DOUT : out STD_LOGIC;
D : in STD_LOGIC_VECTOR (7 downto 0));
end parallel_serial_2;
architecture Behavioral of parallel_serial_2 is
SIGNAL REG: STD_LOGIC_VECTOR(7 DOWNTO 0);
begin
PROCESS(CLK,LOAD)
BEGIN
IF(CLK'EVENT AND CLK='1') THEN
IF(LOAD='1') THEN REG<=D;
ELSE REG<=REG(6 DOWNTO 0)&'0'; END IF;
END IF;
END PROCESS;
DOUT<=REG(7);
end Behavioral;
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.
#PACE: Start of Constraints generated by PACE
#PACE: Start of PACE I/O Pin Assignments
NET "CLK" LOC = "P50" ;
NET "D<0>" LOC = "P48" ;
NET "D<1>" LOC = "P47" ;
NET "D<2>" LOC = "P46" ;
NET "D<3>" LOC = "P45" ;
NET "D<4>" LOC = "P44" ;
NET "D<5>" LOC = "P43" ;
NET "D<6>" LOC = "P41" ;
NET "D<7>" LOC = "P40" ;
NET "DOUT" LOC = "P52" ;
NET "LOAD" LOC = "P51" ;
#PACE: Start of PACE Area Constraints
#PACE: Start of PACE Prohibit Constraints
#PACE: End of Constraints generated by PACE
The Arduino is very popular for most of electronics projects. I use an Arduino Uno to read the data from this chip.
const char clockPin= 13;
const char Enable = 10;
const char dataPin=12;
uint8_t incoming=0,oldData;
void setup() {
Serial.begin(9600);
Serial.println("Arduino ShiftIn And XC95108 Parallel To Serial Converter.");
pinMode(clockPin,OUTPUT);
pinMode(Enable,OUTPUT);
pinMode(dataPin,INPUT);
digitalWrite(clockPin,LOW);
digitalWrite(Enable,LOW);
}
void loop() {
digitalWrite(Enable,HIGH);
digitalWrite(clockPin,LOW);
digitalWrite(clockPin,HIGH);
digitalWrite(Enable,LOW);
for(uint8_t i=0;i<8;i++){
digitalWrite(clockPin,LOW);
if(digitalRead(dataPin)==1) incoming|=(1<<(7-i));
else incoming&=~(1<<(7-i));
digitalWrite(clockPin,HIGH);
}
if(incoming!=oldData){
Serial.println("Received 8-Bit HEX Data: 0x" + String(incoming,HEX));
Serial.println("Received 8-Bit BIN Data: 0b" + String(incoming,BIN));
oldData=incoming;
}
// Serial.println(incoming,HEX);
//Serial.println(incoming,BIN);
delay(1500);
}
Click here to download this example.
 
No comments:
Post a Comment