Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Shift register implementation and use of its value

Status
Not open for further replies.
The way you wrote the shift register code won't work unless there is other code which you neglected to show that takes shift_reg and feeds it back into the input_data. Unless you show everything to do with the code all the way back to inputs and outputs of the module, we can only comment on the code you provide with your question.

This is how I have written:
Code:
parameter input_width = 8;
parameter bit_width = 1; //in this case to shift 1 bit at a time

input [input_width-1:0] input_data;
reg    [input_width-1:0] shift_reg;

always @(posedge CLK or negedge RST)
begin 
if (!RST) shift_reg <= input_data;
else       shift_reg <= {bit_width{1'b0}}, shift_reg[input_width-1:bit_width]};
end
I am running this code with different input_data values and it works. Even with different widths of "bit_width" it works by shifting. How could that be possible?
This is all the code thats related to this operation.
 

Why?
I tried doing this
Code:
always@(posedge clock) begin 
if (reset) shift_reg = input_data;
else        [COLOR="#FF0000"]shift_reg = {1'b0, input_data[7:1]};[/COLOR]

So all of the data gets loaded in in the first cycle after reset .
This way its achieved in one cycle. Either way I want to use the last bit so I just keep shifting in 0's every clock. Am I going wrong somewhere?

parameter input_width = 8;
parameter bit_width = 1; //in this case to shift 1 bit at a time

input [input_width-1:0] input_data;
reg [input_width-1:0] shift_reg;

always @(posedge CLK or negedge RST)
begin
if (!RST) shift_reg <= input_data;
else shift_reg <= {bit_width{1'b0}}, shift_reg[input_width-1:bit_width]};
end

[/CODE]
I am running this code with different input_data values and it works. Even with different widths of "bit_width" it works by shifting. How could that be possible?
This is all the code thats related to this operation.

Notice there is a difference in the RHS of the two code snippets you posted (highlighted in red). The top one is not a shift register no matter how much you claimed it was.

The second is a shift register. You should proof read your code more carefully to avoid misunderstandings like this, or at a minimum READ others posts carefully so you can correct the mistake sooner.
 
Hello,

Sorry about that. I i will mark this question solved. Thanks for your help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top