You are on page 1of 33

UNIVERSAL SHIFT REGISTER

Figure 4.2 Serial-in, Parallel-out Shift Register Details

If a serial-in/parallel-out shift register is so similar to a serial-in/ serial-out shift register, whydo manufacturers

bother to offer both types? Why not just offer the serial-in/parallel-out shiftregister? They actually only offer the

serial-in/parallel-out shift register, as long as it has nomore than 8-bits. Note that serial-in/ serial-out shift registers

come in gigger than 8-bitlengths of 18 to to 64-bits. It is not practical to offer a 64-bit serial-in/parallel-out

shiftregister requiring that many output pins. See waveforms below for above shift register.
Figure 4.3 Serial-in, Parallel-out Shift Register Waveforms

The shift register has been cleared prior to any data byCLR ', an active low signal, whichclears all type D Flip-Flops

within the shift register. Note the serial data1011 patternpresented at theSI input. This data is synchronized with the

clockCLK. This would be thecase if it is being shifted in from something like another shift register, for example, a

parallel-in/ serial-out shift register (not shown here). On the first clock att1, the data1 atSI is shiftedfromD toQ of

the first shift register stage. Aftert2 this first data bit is atQB. Aftert3 it is at
QC. After t4 it is at QD. Four clock pulses have shifted the first data bit all the way to the last

stageQD. The second data bit a0 is atQC after the 4th clock. The third data bit a1 is atQB.The fourth data bit

another1 is atQA. Thus, the serial data input pattern1011 is contained in(QD QC QB QA). It is nowavailable on the

four outputs.
It will available on the four outputs from just after clockt4 to just beforet5. This parallel datamust be used or stored

between these two times, or it will be lost due to shifting out the QDstage on following clockst5 tot8 as shown

above.
14

UNIVERSAL SHIFT REGISTER


5. PARALLEL-IN, PARALLEL-OUT, UNIVERSAL
SHIFT REGISTER

The purpose of the parallel-in/ parallel-out shift register is to take in parallel data, shift it,then output it as shown

below. A universal shift register is a do-everything device in additionto the parallel-in/ parallel-out function.
Figure 5.1 Parallel-in, Parallel-out Shift Register with 4-Stages
Above we apply four bit of data to a parallel-in/ parallel-out shift register atDA DB DC DD.The mode control,

which may be multiple inputs, controls parallel loading vs shifting. Themode control may also control the direction

of shifting in some real devices. The data will beshifted one bit position for each clock pulse. The shifted data is

available at the outputsQA


QB QC QD . The "data in" and "data out" are provided for cascading of multiple stages.

Though, above, we can only cascade data for right shifting. We could accommodatecascading of left-shift data by

adding a pair of left pointing signals, "data in" and "data out",above. The internal details of a right shifting parallel-

in/ parallel-out shift register are shownbelow. The tri-state buffers are not strictly necessary to the parallel-in/

parallel-out shiftregister, but are part of the real-world device shown below. The 74LS395 so closely matchesour

concept of a hypothetical right shifting parallel-in/ parallel-out shift register that we usean overly simplified version

of the data sheet details above.LD /S H' controls the AND-ORmultiplexer at the data input to the FF's. IfLD /S

H'=1, the upper four AND gates are enabledallowing application of parallel inputsDA DB DC DD to the four FF

data inputs. Note theinverter bubble at the clock input of the four FFs. This indicates that the 74LS395 clocks dataon

the negative going clock, which is the high to low transition. The four bits of data will beclocked in parallel

fromDA DB DC DD toQA QB QC QD at the next negative going clock. In


15
UNIVERSAL SHIFT REGISTER
this "real part",OC ' must be low if the data needs to be available at the actual output pins as
opposed to only on the internal FFs.
Figure 5.2 Parallel-in, Parallel-out Shift Register with tri-state Output

The previously loaded data may be shifted right by one bit position ifLD /SH'=0 for thesucceeding negative going

clock edges. Four clocks would shift the data entirely out of our 4-bit shift register. The data would be lost unless

our device was cascaded fromQD' toSER ofanother device.


Figure 5.3 Parallel-in, Parallel-out Shift Register
Above, a data pattern is presented to inputsDA DB DC DD. The pattern is loaded toQA QB QC
QD . Then it is shifted one bit to the right. The incoming data is indicated by X, meaning the

we do no know what it is. If the input (SER) were grounded, for example, we would knowwhat data (0) was shifted

in. Also shown, is right shifting by two positions, requiring two clocks.
Figure 5.4 Shift Right
16
UNIVERSAL SHIFT REGISTER

The above figure serves as a reference for the hardware involved in right shifting of data. It istoo simple to even

bother with this figure, except for comparison to more complex figures tofollow.
Right shifting of data is provided above for reference to the previous right shifter.
Figure 5.5 Shift Left

If we need to shift left, the FFs need to be rewired. Compare to the previous right shifter.Also,SI andSO have been

reversed.SI shifts toQC.QC shifts toQB.QB shifts toQA.QAleaves on theSO connection, where it could cascade to

another shifterSI. This left shiftsequence is backwards from the right shift sequence.
Above we shift the same data pattern left by one bit.

There is one problem with the "shift left" figure above. There is no market for it. Nobodymanufactures a shift-left

part. A "real device" which shifts one direction can be wiredexternally to shift the other direction. Or, should we say

there is no left or right in the contextof a device which shifts in only one direction. However, there is a market for a

device whichwill shift left or right on command by a control line. Of course, left and right are valid in thatcontext.
17
UNIVERSAL SHIFT REGISTER
Figure 5.6 Shift Left/Right, Right Action

What we have above is a hypothetical shift register capable of shifting either direction underthe control ofL'/R. It is

setup withL'/R=1 to shift the normal direction, right.L'/R=1enables the multiplexer AND gates labeledR. This

allows data to follow the path illustratedby the arrows, when a clock is applied. The connection path is the same as

the"too simple""shift right" figure above.


Data shifts in atSR, toQA, toQB, toQC, where it leaves at SR cascade. This pin could drive
SR of another device to the right. What if we change L'/Rto L'/R=0?
Figure 5.7 Shift Left/Right Register, Left Action

WithL'/R =0, the multiplexer AND gates labeledL are enabled, yielding a path, shown bythe arrows, the same as the

above "shift left" figure. Data shifts in atSL, toQC, toQB, toQA,where it leaves at SL cascade. This pin could

driveSL of another device to the left.


The prime virtue of the above two figures illustrating the "shift left/ right register" issimplicity. The operation of the

left right controlL'/R =0 is easy to follow. A commercial partneeds the parallel data loading implied by the section

title. This appears in the figure below.Now that we can shift both left and right viaL'/R, let us addSH/LD ', shift/

load, and theAND gates labeled "load" to provide for parallel loading of data from inputsDA DB DC. When
SH/LD'=0, AND gates Rand L are disabled, AND gates "load" are enabled to pass data DA
DB DC to the FF data inputs. the next clock CLK will clock the data to QA QB QC. As long as

the same data is present it will be re-loaded on succeeding clocks. However, data present foronly one clock will be

lost from the outputs when it is no longer present on the data inputs.One solution is to load the data on one clock,

then proceed to shift on the next four clocks.This problem is remedied in the 74ALS299 by the addition of another

AND gate to themultiplexer.

Figure 5.8 Shift Left/Right Load

IfSH/LD ' is changed toS H/LD '=1, the AND gates labeled "load" are disabled, allowing theleft/ right

controlL'/R to set the direction of shift on theL orR AND gates. Shifting is as inthe previous figures.
The only thing needed to produce a viable integrated device is to add the fourth AND gate to
the multiplexer as alluded for the 74ALS299. This is shown in the next section for that part
6. VHDL PROGRAM
UNIVERSAL
SHIFT
REGISTER
USING
ARRAY
SLICING
AND
CONCATENATION METHOD

library IEEE;

use IEEE.std_logic_1164.all;

entity universalshift is

port (

cntrl: in STD_LOGIC_VECTOR (1 downto 0);

data: inout STD_LOGIC_VECTOR (3 downto 0);

clk:in std_logic;

ip: in STD_LOGIC;

pip:in std_logic_vector(3 downto 0);

op: out STD_LOGIC

);

end universalshift;

--}} End of automatically maintained section

architecture universalshift of universalshift is

begin

process

(clk)

begin

if(clk' event and clk='1' )


then if(cntrl(1)='0' and cntrl(0)='0')

then op<=data(3);

data(3)<=data(2);

data(2)<=data(1);
data(1)<=data(0);
data(0)<=ip;
end if;
if(cntrl(1)='0' and cntrl(0)='1')
then op<=data(0);

data(0)<=data(1);

data(1)<=data(2);
data(2)<=data(3);

data(3)<=ip;

end if;

if(cntrl(1)='1' and cntrl(0)='0')


thendata(0)<=pip(0);

data(1)<=pip(1);

data(2)<=pip(2);

data(3)<=pip(3);

end if;

end if;

end process;
-- <<enter your statements here>>
end universalshift;

UNIVERSAL SHIFT REGISTER USING SHIFTING OPERATORS: SLL, SRL.

library ieee;

use ieee.std_logic_1164.all;

use ieee.numeric_bit.all;
entity univ_shiftreg2 is
port(clk,il,ir :in bit;
s :in bit_vector(1 downto 0);
i : in bit_vector(3 downto 0);
q : out bit_vector(3 downto 0));

end univ_shiftreg2;

architecture beh2 of univ_shiftreg2 is

signal qtmp: bit_vector(5 downto 0);

begin
process(clk)
begin

if (clk = '1' and clk'event) then

case s is
when "00" =>

qtmp <= qtmp; when "01" =>


qtmp <=il&i&ir;

when "10" =>

qtmp <= (il&qtmp(4 downto 1)&ir) sll 1;

when "11" =>

qtmp<= (il&qtmp(4 downto 1)&ir) srl 1 ;

when others =>

null;

end case;

end if;
end process;
q<=qtmp(4 downto 1);
end beh2;
UNIVERSAL SHIFT REGISTER
7. APPLICATIONS
1.
An application of a parallel-in/ serial-out shift register is to read data into a
microprocessor.
Figure 7.1 Alarm with Remote Keypad

The Alarm above is controlled by a remote keypad. The alarm box supplies +5V and groundto the remote keypad to

power it. The alarm reads the remote keypad every few tens ofmilliseconds by sending shift clocks to the keypad

which returns serial data showing thestatus of the keys via a parallel-in/ serial-out shift register. Thus, we read nine

key switcheswith four wires. How many wires would be required if we had to run a circuit for each of thenine keys?
2.

A real-world application of the serial-in/ parallel-out shift register is to output datafrom a microprocessor to a remote

panel indicator. Or, another remote output devicewhich accepts serial format data.
Figure 7.2 Alarm with Remote Kaypad and Display

The figure ”Alarm with remote key pad” is repeated here from the parallel-in/ serial-outsection with the addition of

the remote display. Thus, we can display, for example, the statusof the alarm loops connected to the main alarm box.

If the Alarm detects an open window, itcan send serial data to the remote display to let us know. Both the keypad

and the display


UNIVERSAL SHIFT REGISTER
Figure 4.2 Serial-in, Parallel-out Shift Register Details

If a serial-in/parallel-out shift register is so similar to a serial-in/ serial-out shift register, whydo manufacturers

bother to offer both types? Why not just offer the serial-in/parallel-out shiftregister? They actually only offer the

serial-in/parallel-out shift register, as long as it has nomore than 8-bits. Note that serial-in/ serial-out shift registers

come in gigger than 8-bitlengths of 18 to to 64-bits. It is not practical to offer a 64-bit serial-in/parallel-out

shiftregister requiring that many output pins. See waveforms below for above shift register.
Figure 4.3 Serial-in, Parallel-out Shift Register Waveforms

The shift register has been cleared prior to any data byCLR ', an active low signal, whichclears all type D Flip-Flops

within the shift register. Note the serial data1011 patternpresented at theSI input. This data is synchronized with the

clockCLK. This would be thecase if it is being shifted in from something like another shift register, for example, a

parallel-in/ serial-out shift register (not shown here). On the first clock att1, the data1 atSI is shiftedfromD toQ of

the first shift register stage. Aftert2 this first data bit is atQB. Aftert3 it is at
QC. After t4 it is at QD. Four clock pulses have shifted the first data bit all the way to the last

stageQD. The second data bit a0 is atQC after the 4th clock. The third data bit a1 is atQB.The fourth data bit

another1 is atQA. Thus, the serial data input pattern1011 is contained in(QD QC QB QA). It is nowavailable on the

four outputs.
It will available on the four outputs from just after clockt4 to just beforet5. This parallel datamust be used or stored

between these two times, or it will be lost due to shifting out the QDstage on following clockst5 tot8 as shown

above.
14

UNIVERSAL SHIFT REGISTER


5. PARALLEL-IN, PARALLEL-OUT, UNIVERSAL
SHIFT REGISTER

The purpose of the parallel-in/ parallel-out shift register is to take in parallel data, shift it,then output it as shown

below. A universal shift register is a do-everything device in additionto the parallel-in/ parallel-out function.
Figure 5.1 Parallel-in, Parallel-out Shift Register with 4-Stages
Above we apply four bit of data to a parallel-in/ parallel-out shift register atDA DB DC DD.The mode control,

which may be multiple inputs, controls parallel loading vs shifting. Themode control may also control the direction

of shifting in some real devices. The data will beshifted one bit position for each clock pulse. The shifted data is

available at the outputsQA


QB QC QD . The "data in" and "data out" are provided for cascading of multiple stages.

Though, above, we can only cascade data for right shifting. We could accommodatecascading of left-shift data by

adding a pair of left pointing signals, "data in" and "data out",above. The internal details of a right shifting parallel-

in/ parallel-out shift register are shownbelow. The tri-state buffers are not strictly necessary to the parallel-in/

parallel-out shiftregister, but are part of the real-world device shown below. The 74LS395 so closely matchesour

concept of a hypothetical right shifting parallel-in/ parallel-out shift register that we usean overly simplified version

of the data sheet details above.LD /S H' controls the AND-ORmultiplexer at the data input to the FF's. IfLD /S

H'=1, the upper four AND gates are enabledallowing application of parallel inputsDA DB DC DD to the four FF

data inputs. Note theinverter bubble at the clock input of the four FFs. This indicates that the 74LS395 clocks dataon

the negative going clock, which is the high to low transition. The four bits of data will beclocked in parallel

fromDA DB DC DD toQA QB QC QD at the next negative going clock. In


15
UNIVERSAL SHIFT REGISTER
this "real part",OC ' must be low if the data needs to be available at the actual output pins as
opposed to only on the internal FFs.
Figure 5.2 Parallel-in, Parallel-out Shift Register with tri-state Output

The previously loaded data may be shifted right by one bit position ifLD /SH'=0 for thesucceeding negative going

clock edges. Four clocks would shift the data entirely out of our 4-bit shift register. The data would be lost unless

our device was cascaded fromQD' toSER ofanother device.


Figure 5.3 Parallel-in, Parallel-out Shift Register
Above, a data pattern is presented to inputsDA DB DC DD. The pattern is loaded toQA QB QC
QD . Then it is shifted one bit to the right. The incoming data is indicated by X, meaning the

we do no know what it is. If the input (SER) were grounded, for example, we would knowwhat data (0) was shifted

in. Also shown, is right shifting by two positions, requiring two clocks.
Figure 5.4 Shift Right
16
UNIVERSAL SHIFT REGISTER

The above figure serves as a reference for the hardware involved in right shifting of data. It istoo simple to even

bother with this figure, except for comparison to more complex figures tofollow.
Right shifting of data is provided above for reference to the previous right shifter.
Figure 5.5 Shift Left

If we need to shift left, the FFs need to be rewired. Compare to the previous right shifter.Also,SI andSO have been

reversed.SI shifts toQC.QC shifts toQB.QB shifts toQA.QAleaves on theSO connection, where it could cascade to

another shifterSI. This left shiftsequence is backwards from the right shift sequence.
Above we shift the same data pattern left by one bit.

There is one problem with the "shift left" figure above. There is no market for it. Nobodymanufactures a shift-left

part. A "real device" which shifts one direction can be wiredexternally to shift the other direction. Or, should we say

there is no left or right in the contextof a device which shifts in only one direction. However, there is a market for a

device whichwill shift left or right on command by a control line. Of course, left and right are valid in thatcontext.
17
UNIVERSAL SHIFT REGISTER
Figure 5.6 Shift Left/Right, Right Action

What we have above is a hypothetical shift register capable of shifting either direction underthe control ofL'/R. It is

setup withL'/R=1 to shift the normal direction, right.L'/R=1enables the multiplexer AND gates labeledR. This

allows data to follow the path illustratedby the arrows, when a clock is applied. The connection path is the same as

the"too simple""shift right" figure above.


Data shifts in atSR, toQA, toQB, toQC, where it leaves at SR cascade. This pin could drive
SR of another device to the right. What if we change L'/Rto L'/R=0?
Figure 5.7 Shift Left/Right Register, Left Action

WithL'/R =0, the multiplexer AND gates labeledL are enabled, yielding a path, shown bythe arrows, the same as the

above "shift left" figure. Data shifts in atSL, toQC, toQB, toQA,where it leaves at SL cascade. This pin could

driveSL of another device to the left.


The prime virtue of the above two figures illustrating the "shift left/ right register" issimplicity. The operation of the

left right controlL'/R =0 is easy to follow. A commercial partneeds the parallel data loading implied by the section

title. This appears in the figure below.Now that we can shift both left and right viaL'/R, let us addSH/LD ', shift/

load, and theAND gates labeled "load" to provide for parallel loading of data from inputsDA DB DC. When
SH/LD'=0, AND gates Rand L are disabled, AND gates "load" are enabled to pass data DA
DB DC to the FF data inputs. the next clock CLK will clock the data to QA QB QC. As long as

the same data is present it will be re-loaded on succeeding clocks. However, data present foronly one clock will be

lost from the outputs when it is no longer present on the data inputs.One solution is to load the data on one clock,

then proceed to shift on the next four clocks.This problem is remedied in the 74ALS299 by the addition of another

AND gate to themultiplexer.

Figure 5.8 Shift Left/Right Load

IfSH/LD ' is changed toS H/LD '=1, the AND gates labeled "load" are disabled, allowing theleft/ right

controlL'/R to set the direction of shift on theL orR AND gates. Shifting is as inthe previous figures.
The only thing needed to produce a viable integrated device is to add the fourth AND gate to
the multiplexer as alluded for the 74ALS299. This is shown in the next section for that part
6. VHDL PROGRAM
UNIVERSAL
SHIFT
REGISTER
USING
ARRAY
SLICING
AND
CONCATENATION METHOD

library IEEE;

use IEEE.std_logic_1164.all;

entity universalshift is

port (

cntrl: in STD_LOGIC_VECTOR (1 downto 0);

data: inout STD_LOGIC_VECTOR (3 downto 0);

clk:in std_logic;

ip: in STD_LOGIC;

pip:in std_logic_vector(3 downto 0);

op: out STD_LOGIC

);

end universalshift;

--}} End of automatically maintained section

architecture universalshift of universalshift is

begin

process

(clk)

begin

if(clk' event and clk='1' )


then if(cntrl(1)='0' and cntrl(0)='0')

then op<=data(3);

data(3)<=data(2);

data(2)<=data(1);
data(1)<=data(0);
data(0)<=ip;
end if;
if(cntrl(1)='0' and cntrl(0)='1')
then op<=data(0);

data(0)<=data(1);

data(1)<=data(2);
data(2)<=data(3);

data(3)<=ip;

end if;

if(cntrl(1)='1' and cntrl(0)='0')


thendata(0)<=pip(0);

data(1)<=pip(1);

data(2)<=pip(2);

data(3)<=pip(3);

end if;

end if;

end process;
-- <<enter your statements here>>
end universalshift;

UNIVERSAL SHIFT REGISTER USING SHIFTING OPERATORS: SLL, SRL.

library ieee;

use ieee.std_logic_1164.all;

use ieee.numeric_bit.all;
entity univ_shiftreg2 is
port(clk,il,ir :in bit;
s :in bit_vector(1 downto 0);
i : in bit_vector(3 downto 0);
q : out bit_vector(3 downto 0));

end univ_shiftreg2;

architecture beh2 of univ_shiftreg2 is

signal qtmp: bit_vector(5 downto 0);

begin
process(clk)
begin

if (clk = '1' and clk'event) then

case s is
when "00" =>

qtmp <= qtmp; when "01" =>


qtmp <=il&i&ir;

when "10" =>

qtmp <= (il&qtmp(4 downto 1)&ir) sll 1;

when "11" =>

qtmp<= (il&qtmp(4 downto 1)&ir) srl 1 ;

when others =>

null;

end case;

end if;
end process;
q<=qtmp(4 downto 1);
end beh2;
UNIVERSAL SHIFT REGISTER
7. APPLICATIONS
1.
An application of a parallel-in/ serial-out shift register is to read data into a
microprocessor.
Figure 7.1 Alarm with Remote Keypad

The Alarm above is controlled by a remote keypad. The alarm box supplies +5V and groundto the remote keypad to

power it. The alarm reads the remote keypad every few tens ofmilliseconds by sending shift clocks to the keypad

which returns serial data showing thestatus of the keys via a parallel-in/ serial-out shift register. Thus, we read nine

key switcheswith four wires. How many wires would be required if we had to run a circuit for each of thenine keys?
2.

A real-world application of the serial-in/ parallel-out shift register is to output datafrom a microprocessor to a remote

panel indicator. Or, another remote output devicewhich accepts serial format data.
Figure 7.2 Alarm with Remote Kaypad and Display

The figure ”Alarm with remote key pad” is repeated here from the parallel-in/ serial-outsection with the addition of

the remote display. Thus, we can display, for example, the statusof the alarm loops connected to the main alarm box.

If the Alarm detects an open window, itcan send serial data to the remote display to let us know. Both the keypad

and the display


would likely be contained within the same remote enclosure, separate from the main alarm
box. However, we will only look at the display panel in this section.
3.
Serial to parallel converter
4.
Parallel to serial converter
5.
Ring counter
6.
Jhonson counter e

vhdl and verilog module for a universal shift register using behavioral model with following functions
mr is active low ,asynchronous reset input that resets all flipflops
function table
controlinputs
s1 s0 function
0 0 no action
0 1 left shift&serial data sl enters q3
1 0 right shift &serial data sr enters q0
1 1 parallel loading

where sl,sr,s0,s1,mr,clk are inputs


q0,q1,q2,q3 are outputs

Posted by: jeppe 4/12/2008 3:06:06 PM


Comments Posted:61
Signal Shreg: Std_logic_vector( 3 downto 0);
Signal S1S0: Std_logic_vector( 1 downto 0);

begin
process( Clk,mr)
begin
. if mr='0' then
. Shreg <= "0000";
. elsif rising_edge(Clk) then
. case S1S0 is
. when "00" => null;
. when "01" => Shreg <= Shreg( 2 downto 0)&SL;
. when "10" => Shreg <= SR& Shreg( 3 downto 1);
. when "11" => Shreg <= Data;
. when others => null;
. end case;
. end if;
end process;

S1S0 <= S1&S0;


Q3 <= Shreg(3);

You might also like