Shift Register Parallel In Serial Out Vhdl Code

37 views
Skip to first unread message

Irena Kerfien

unread,
Jan 25, 2024, 12:21:50 PM1/25/24
to lanfirestu

I'm creating an n bit shift register. When the enable signal is high, I want the shift register to shift n times, irrespective of whether enable continues to be high or low. I've put a for loop to shift n times inside a process. My code is given below.

shift register parallel in serial out vhdl code


Download ————— https://t.co/yM1SRPwMgy



VHDL Code for shift register can be categorised in serial in serial out shift register, serial in parallel out shift register, parallel in parallel out shift register and parallel in serial out shift register.

So I've been using VHDL to make a register, where it loads in the input X if LOAD is '1' , and outputs the data in serial fashion , basically a parallel in serial out register. The input X is a 4 bit ( 3 downto 0 ) input , what I want to make the program do is constantly output 0 when the register has successfully output all the btis in the input.

In this post, we analyzed the VHDL code for a parallel to serial converter. This approach is very useful in interfacing different devices. Many FPGA vendors like Xilinx, Intel/Altera give us the possibility to use internal serializer-deserializer such as a serial transceiver. In this post, we want to implement the complementary interface of the parallel to serial interface. We will see how to implement the VHDL code for a serial to parallel interface in order to get back the parallel data bus we sent in the transmitter device. In other words, we will implement the VHDL block in the of the bottom right of Figure1

Let assume the parallel data bus of the Serial to Parallel converter to be N bit. The parallel output to the module will be available every N clock cycle since N clock cycles are needed to load the shift register that provided the parallel output as in Figure2

In the VHDL code every G_N clockcycles the counter enable the parallel output register and provides theparallel data output and the relative enable pulse. With respect to theparallel to serial converter in this case no error detection logic is present.The output parallel data rate is slower than the input serial data rate, so noerror condition can occur.

In Figure4 is reported a simulation of the serial to parallel converter VHDL code above. In order to realize the test bench, the parallel to serial converter of this post is used. As a convention, the first serial output bit is the MSB of the input parallel data. You can choose to output first the LSB. It depends on the convention you are using.

In this post, we implemented a simple example of a serial to parallel VHDL code. Such a conversion strategy can be used when we need to connect two different devices like two FPGA, and we need to minimize the connection wires. Using a serial connection, we can minimize the number of connection wires, minimizing also the skew problem on the connection itself. This module can be used in conjunction with the serial to parallel converter discussed in this post.

There are many ways to create a shift register in VHDL, though not all of them are equal. You can dramatically reduce the number of consumed resources by choosing the right shift register implementation for your needs and FPGA architecture.

A shift register implements a FIFO of fixed length. Every time a new element enters the queue, it shifts the existing ones one place further away from the input. To understand the basics of the shift register, I recommend viewing the VHDL tutorial about the std_logic_vector.

While any shift register is suitable for creating generic, smaller buffers, there are methods of efficiently creating larger ones. Many FPGAs have logic elements that can double as specialized shift register primitives. You can improve performance in magnitudes by being mindful of how you write your VHDL code.

Even though the shift register should require 128 flip-flops (FFs), we see that the resource usage reported by Vivado and Quartus is far less. Instead of using expensive FFs, the synthesis tools have used special built-in features of the logic blocks.

The most straightforward way to create a shift register is to use vector slicing. Insert the new element at one end of the vector, while simultaneously shifting all of the others one place closer to the output side. Put the code in a clocked process and tap the last bit in the vector, and you have your shift register.

You should be cautious about adding reset values to the shift register vector or output. The problem is that it prevents the synthesis tool from packing the shift register into LUTs or BRAM. Consider the example below, which is the same as the first one in this article, but with synchronous reset added.

The synchronous reset has forced the synthesis tool to implement the shift register entirely in FFs. Therefore, you should ask yourself if you need to be able to reset the entire shift register at once.

The final example in this article is a shift register with generic width and depth, using synchronous reset. The code below shows the implementation which uses the reset counter that we discussed earlier in this article.

We can see from the listing below that the Xilinx FPGA needs eight additional regular LUTs and seven FFs for implementing the counter reset. Intel Quartus II still somehow reports the same resource usage as without reset. The Lattice FPGA consumes 24 more LUTs and 31 more FFs for implementing the counter, but the shift register still fits in one BRAM.

But you can override the automatic choice by using a synthesis attribute, also known as a pragma or compiler directive. The different FPGA vendors have their own sets of VHDL attributes. To specify a desired primitive type, you define the attribute in the architecture region of the VHDL file, referencing your shift register array or vector by name.

Setting the shreg_extract attribute to "no" disables all shift register optimization. This setting acts like a master switch, overriding other SRL synthesis settings. You can also assign "yes" to shreg_extract, but this is the default setting anyway.

The main usage for a shift register is for converting from a serial datainput stream to a parallel data output or vice versa. For a serial toparallel data conversion, the bits are shifted into the register at eachclock cycle, and when all the bits (usually eight bits) are shifted in, the8-bit register can be read to produce the eight bit parallel output. For aparallel to serial conversion, the 8-bit register is first loaded with theinput data. The bits are then individually shifted out, one bit per clockcycle, on the serial output line. In general a shift register ischaracterized by the following control and data signals:

Shift registers consist of D flip-flops as shown in the figure below. This is a four bit shift register and therefore consists of four D flip-flops. This shift register is configured to shift data from the left to the right.

This example creates a shift register using a VHDL signal called shift_reg shown in the code listing below. This register is initialized with the value of 00h so that when power is switched on to the CPLD board, the register will be cleared. The shift_reg register is 8 bits wide and the VHDL code connects each bit in the register to an LED, so that 8 LEDs show the value in each bit of the register.

In the above code, the shifting is done by moving seven bits of data in a single line of code. Bits 7 to 1 (the upper seven bits) are moved to bits 6 to 0 all in one go. In other words the upper seven bits are moved right by one bit position.

The method suggested by Paul Menchini is clearly more concise but I do believe
that the block is functional. Since the signal ssr(word'right) does not leave
the shift register (only ssr(word'left) is connected to Q) the code should work
but this is a moot point at best since the alternative architecture is better.-- Prasad

Creating delay in an FPGA is the most common use of a shift register. The delay is often used to align data in time. The figure below shows this simple type of shift register. The number of Flip-Flops in the delay chain dictates how many clock cycles it will take for the data on the input to propagate to the data on the output. So in the picture below, it will take four clock cycles for an input on D on the first Flip-Flop to be seen on the output Q of the last Flip-Flop. Read about Processes in VHDL or Always Blocks in Verilog for a tutorial on how to create a shift register in your HDL of choice.

Converting from serial data to parallel data is another common use of shift registers. This occurs when interfacing to off-chip signals that transmit data serially such as a UART Receiver. When data comes in over a UART, it need to be converted from serial data 1-bit wide to a parallel byte that the FPGA can look at.

This is the opposite of the above and is used in UART Transmitter. When you want to transmit a byte over UART, it must first be serialized and sent out over the single UART line. A shift register can be used for this purpose.

The General CRC Syndrome Detector HDL Optimized block performs a cyclic redundancy check (CRC) on data and compares the resulting checksum with the appended checksum. The General CRC Syndrome Detector HDL Optimized block processing is optimized for HDL code generation. If the two checksums do not match, the block reports an error. Instead of processing an entire frame at once, the block accepts and returns a data sample stream with accompanying control signals. The control signals indicate the validity of the samples and the boundaries of the frame. To achieve higher throughput, the block accepts vector data up to the CRC length and implements a parallel architecture.

Specify initial conditions of the internal shift register as a binary, double-precision, or single-precision scalar or vector. For vector inputs, the length of the initial state must be equal to the degree of the generator polynomial.

Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is 0. For more details, see InputPipeline (HDL Coder).

dd2b598166
Reply all
Reply to author
Forward
0 new messages