EmbDev.net

Forum: FPGA, VHDL & Verilog SISO Shift Register


von Dayana (Guest)


Rate this post
useful
not useful
Hello everyone.

Current Im designing 3x8 shift right SISO

Below is my verilog code:
1
`timescale 1ns / 1ps
2
module ShiftReg (Clk,En,In,Out);
3
4
parameter InWidth = 3;
5
parameter Length = 8;
6
7
input Clk,En;
8
input  [InWidth-1:0] In;
9
output [InWidth-1:0] Out;
10
11
reg [Length-1:0] sr ;
12
13
always@(posedge Clk)
14
begin
15
  if (En == 1'b1)
16
  begin
17
    sr[0] <= In;
18
    sr <= sr<<1;
19
  end
20
end
21
22
assign Out = sr[Length-1];
23
24
endmodule

However this is my warning:

WARNING:HDLCompiler:413 - 
"C:\Users\User\Desktop\PE\ShiftReg\ShiftReg\ShiftReg.v" Line 17: Result 
of 3-bit expression is truncated to fit in 1-bit target.
WARNING:Xst:647 - Input <In> is never used. This port will be preserved 
and left unconnected if it belongs to a top-level block or it belongs to 
a sub-block and the hierarchy of this sub-block is preserved.
WARNING:Xst:1710 - FF/Latch <sr_0> (without init value) has a constant 
value of 0 in block <ShiftReg>. This FF/Latch will be trimmed during the 
optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_1> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_2> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_3> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_4> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_5> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_6> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_7> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1710 - FF/Latch <sr_0> (without init value) has a constant 
value of 0 in block <ShiftReg>. This FF/Latch will be trimmed during the 
optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_1> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_2> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_3> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_4> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_5> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_6> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.
WARNING:Xst:1895 - Due to other FF/Latch trimming, FF/Latch <sr_7> 
(without init value) has a constant value of 0 in block <ShiftReg>. This 
FF/Latch will be trimmed during the optimization process.

Does anyone have any idea for my input problem?

Thank you very much

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Dayana wrote:
> However this is my warning:
> WARNING:HDLCompiler:413 -
> "C:\Users\User\Desktop\PE\ShiftReg\ShiftReg\ShiftReg.v" Line 17: Result
> of 3-bit expression is truncated to fit in 1-bit target.
A hint: try to write your code without those generics/constants, but 
with numbers in each signal and register definition. Then you will see, 
that the line "sr[0] <= In;" is trying to pack a input vector "In" of 
three bits width in a single flipflop "sr[0]".

What do you want to get with that code?
Should sr be a shift register to delay those In vectors?

Then you may have a look for "multidimensional arrays in Verilog":
https://www.google.com/search?q=multidimensional+arrays+in+verilog
https://stackoverflow.com/questions/3011510/how-to-declare-and-use-1d-and-2d-byte-arrays-in-verilog

von Dayana S. (dayanasaiful)


Rate this post
useful
not useful
Emmm I dont really understand the hint ...  Sorry for my lack of 
knowledge.

Actually I want to preload my 3 bit data into my systolic array.

von Tim (Guest)


Rate this post
useful
not useful
does it work in Simulation?

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Dayana S. wrote:
> Actually I want to preload my 3 bit data into my systolic array.
Do you want to store 3 bits in parallel (in 3 of those 8 bit shift 
registers) or should they be stored one after the other in 1 shift 
register? If the second: how do 8 bits length match with 3 input bits?

> Emmm I dont really understand the hint ...
Draw a structure of your shift register on a sheet of paper. Then we 
have something to discuss about...

Tim wrote:
> does it work in Simulation?
For sure not. You simply can't assign a input vector of 3 bits width to 
a shift register with 1 bit width...

: Edited by Moderator
von Dayana S. (dayanasaiful)


Attached files:

Rate this post
useful
not useful
No. Its a 3X8 Shift In Shift Out Register

The output of the SISO will be connected to  Sytolic array Input.

True it doesnt work

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Dayana S. wrote:
> Its a 3X8 Shift In Shift Out Register
At the moment you have a 1x8 Shift Register. As I said: you have to add 
one dimension...

I don't do Verilog, but it should be something like that:
1
reg [Length-1:0][InWidth-1:0] sr;
At the end it should give an array of 24 flipflops arranged in some way 
like 8x3...

von Dayana S. (dayanasaiful)


Rate this post
useful
not useful
> At the moment you have a 1x8 Shift Register. As I said: you have to add
> one dimension...

Dimension?

> I don't do Verilog, but it should be something like that:reg
> [Length-1:0][InWidth-1:0] sr;
> At the end it should give an array of 24 flipflops arranged in some way
> like 8x3...

Ive tried this but verilog doesnt used this type of operation? Maybe any 
other idea?

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Dayana S. wrote:
> Maybe any other idea?
According to the link I posted earlier in this thread I would try it 
this way:
reg [InWidth-1:0] sr [Length-1:0];

And if it's not working it would turn around the range:
reg [InWidth-1:0] sr [0:Length-1];

And if that doesn't do the job and if I were a student I would go to my 
university's library  and have a look for any Verilog book. It's in 
there for sure...

von Andi (Guest)


Rate this post
useful
not useful
Instead of a 2 dimensional array, you can also use a 24bit register and 
shift by 3:
1
`timescale 1ns / 1ps
2
module ShiftReg (Clk,En,In,Out);
3
4
input Clk,En;
5
input  [2:0] In;
6
output [2:0] Out;
7
8
reg [23:0] sr ;            //3 x 8 bits = 24
9
10
always@(posedge Clk)
11
begin
12
  if (En == 1'b1)
13
  begin
14
    sr <= {sr[20:0],In};   //shift by 3 and concatenate Input
15
  end
16
end
17
18
assign Out = sr[23:21];    //top 3 bits to output
19
20
endmodule
I've done it with literal numbers instead of parameters, so it's more 
readable.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Andi wrote:
> Instead of a 2 dimensional array, you can also use a 24bit register and
> shift by 3
And of course you can drive in a screw with a sledgehammer...

The one that doesn't like or doesn't understand 2-dimensional arrays, 
that one may try it with 3 explicit shift registers like this:
1
timescale 1ns / 1ps
2
module ShiftReg (Clk,En,In,Out);
3
4
input Clk,En;
5
input  [2:0] In;
6
output [2:0] Out;
7
8
reg [7:0] sr0;
9
reg [7:0] sr1;
10
reg [7:0] sr2;
11
12
always@(posedge Clk)
13
begin
14
  if (En == 1'b1)
15
  begin
16
    sr0 <= In[0];
17
    sr1 <= In[1];
18
    sr2 <= In[2];
19
  end
20
end
21
22
assign Out[0]= sr0[7];
23
assign Out[1]= sr1[7];
24
assign Out[2]= sr2[7];
25
26
endmodule

: Edited by Moderator
von Dayana S. (dayanasaiful)


Rate this post
useful
not useful
Andi

Thank you very much. It works well.

and

thanks also to others that gave ideas and suggestions.

I really appreciate it.

von Andi (Guest)


Rate this post
useful
not useful
Lothar M. wrote:
> And of course you can drive in a screw with a sledgehammer...

Screws, hammers, nails or screwdrivers, at the end all is broken down to 
LUTs and FlipFlops ;-)

The Verilog compiler will produce the same output, if you shift by 3, 
shift 3 times by 1 or move an element of a 3bit two dimensinal array, so 
why not take the one that is easiest to write.

Andi

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Andi wrote:
> Lothar M. wrote:
>> And of course you can drive in a screw with a sledgehammer...
> Screws, hammers, nails or screwdrivers, at the end all is broken down to
> LUTs and FlipFlops ;-)
You are right, but Dayana now learned a workaround  by hammering the 
screw straightaway into the wall instead of selecting the correct tool 
for the task.
And keep in mind: for one only knowing a hammer the whole world looks 
like a nail.  ;-)

> The Verilog compiler will produce the same output, if you shift by 3,
> shift 3 times by 1 or move an element of a 3bit two dimensinal array, so
> why not take the one that is easiest to write.
The "easiest" would be learning a bit about arrays and using them in the 
future as the correct tool:
1
`timescale 1ns / 1ps
2
module ShiftReg (Clk,En,In,Out);
3
4
parameter InWidth = 3;
5
parameter Length = 8;
6
7
input Clk,En;
8
input  [InWidth-1:0] In;
9
output [InWidth-1:0] Out;
10
11
reg [InWidth-1:0] sr [Length-1:0];
12
integer i;
13
14
always@(posedge Clk)
15
begin
16
  if (En == 1'b1)
17
  begin
18
    for (i=1; i<Length; i=i+1) sr[i] <= sr[i-1];
19
    sr[0] <= In;
20
  end
21
end
22
23
assign Out = sr[Length-1];
24
25
endmodule
The whole thing can be found at 
http://www.bitweenie.com/listings/verilog-shift-register/

: Edited by Moderator
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.