Question

In: Electrical Engineering

Write the Verilog code for a 12-bit shift register with ability to shift left or right,...

Write the Verilog code for a 12-bit shift register with ability to shift left or right, synchronized parallel load, asynchronous reset, and serial output? The register is able to load the 12-bit input value (at the positive edge of the clock) if the load signal is one, shift the value in register one bit to the right (at the positive edge of the clock) if the rss signal is one, shift the value in register one bit to the left(at the positive edge of the clock) if lss signal is one, and reset the value in the register at any time if the rst signal is one. The shift register has two 1-bit output which are the MSB (Most significant bit) and LSB (Least significant bit) of the register at any given time. The priority of the signals is in the order as follows with rst having the highest priority. rst, load, rss, lss. When shift register is shifting the value to the right, the MSB bit takes in the load input MSB bit. When shift register is shifting the value to the left, the LSB bit takes in the load input LSB bit.

Solutions

Expert Solution

The working code of the above problem is written which is simulated also and verified for correct operation - I have a small suggestion in the problem statement that when the register is shifting towards right MSB bit will become zero so there is no point in tracking MSB bit. Similarly, for lest shift operation, this implies. BUT THE CODE I HAVE WRITTEN IS ACCORDING TO PROBLEM STATEMENT ONLY. So no need to worry about that.

If you want to make changes you can make any change d[0] to d[11] in last second line of code.

I have also written the comment in the code for better understanding (//)

written code - again


module shift_reg(data,clk,rst,load,rss,lss,msb,lsb);
input [11:0]data;
input clk;
input rst,load,rss,lss;
output reg msb,lsb;
reg [11:0]d;
reg [1:0]z;

always @(*) // Priority encoder which assigns priority accordingly to rst>load>rss>lss
begin
if(rst == 1)
z = 2'b11;
else if(rst == 0 && load == 1)
z = 2'b10;
else if(rst == 0 && load == 0 && rss == 1)
z = 2'b01;
else if(rst == 0 && load == 0 && rss == 0 && lss == 1)
z = 2'b00;
else
z = 2'bzz;
end

always @(*) // asynchronous reset without waiting for the clock posedege
begin
if(z == 2'b11)
begin d = 12'b0;
lsb = 0; msb = 0;
end
end

always@ (posedge clk)
begin
case(z)
2'b10: d = data; // loading the value of the load_data

2'b01: begin msb = d[11]; d = d>>1; end // assigning MSB bit of load to MSB_out
// as well as shifting the register
2'b00: begin lsb = d[0]; d = d<<1; end // assigning LSB bit of load to LSB_out
// as well as shifting the register to left
endcase
end
endmodule

If any more query you have you can comment in the comment section I am always ready to help


Related Solutions

4- a) Draw a 4-Bit Shift Register that shifts from right to left instead of left...
4- a) Draw a 4-Bit Shift Register that shifts from right to left instead of left to right using D-Flip flops. b) Draw the serial transfer from shift register A on the right to the shift register B on the left in block form including the timing diagrammes. c) Draw the serial transfer table in the following form, assuming an initial value of 1101 in the register A and 0110 in the register B. Timing Pulse Shift Register B Shift...
Can anyone write a Verilog code and a test bench for a universal shift register with...
Can anyone write a Verilog code and a test bench for a universal shift register with 4 bits using D flip flop? Thanks
Design a circuit and write a verilog code description of the 16-bit right rotator using barrel...
Design a circuit and write a verilog code description of the 16-bit right rotator using barrel shift method
Write a Verilog code to implement 16 bit LFSR
Write a Verilog code to implement 16 bit LFSR
Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to...
Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to implement this.
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
1) Explain the oprerating principle of left-rotating, right rotating shift register by sketching the circuit and...
1) Explain the oprerating principle of left-rotating, right rotating shift register by sketching the circuit and timing diagram for 4-bit register configurations?
Write the VHDL codes for (7494) 4 bit shift register using Behavioral style of modeling. this...
Write the VHDL codes for (7494) 4 bit shift register using Behavioral style of modeling. this is the datasheet for this Quation ( http://www.ralphselectronics.com/productimages/SEMI-SN7494N.PDF )
Write a code in C to shift serially the content of the register labelled x through...
Write a code in C to shift serially the content of the register labelled x through the bit #1 of Port A starting with least significant bit. Include the port configuration. Do not include any directive.           
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado...
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado and show waveform.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT