+ Post New Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 23 of 23
  1. #21
    Newbie level 6
    Points: 79, Level: 1

    Join Date
    Sep 2019
    Posts
    14
    Helped
    0 / 0
    Points
    79
    Level
    1

    Re: Shift register implementation and use of its value

    Quote Originally Posted by ads-ee View Post

    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.



    •   AltAdvertisement

        
       

  2. #22
    Super Moderator
    Points: 31,607, Level: 43
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    7,310
    Helped
    1719 / 1719
    Points
    31,607
    Level
    43

    Re: Shift register implementation and use of its value

    Quote Originally Posted by rogger201 View Post
    Why?
    I tried doing this
    Code:
    always@(posedge clock) begin 
    if (reset) shift_reg = input_data;
    else        shift_reg = {1'b0, input_data[7:1]};
    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?
    Quote Originally Posted by rogger201 View Post
    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.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  3. #23
    Newbie level 6
    Points: 79, Level: 1

    Join Date
    Sep 2019
    Posts
    14
    Helped
    0 / 0
    Points
    79
    Level
    1

    Re: Shift register implementation and use of its value

    Hello,

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



--[[ ]]--