How To Loop With Registers
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 y'all need to annals. Registration is complimentary. Click hither to annals now.
- Digital Design and Embedded Programming
- PLD, SPLD, GAL, CPLD, FPGA Design
You should upgrade or utilize an culling browser.
[SOLVED] Verilog Loop performance with registers.
- Thread starter ismailov-due east
- Showtime engagement
- Status
- Not open for further replies.
- #1
- Joined
- January 26, 2015
- Messages
- 34
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activeness points
- 295
Who can help me please.
I want to brand some loop performance. for example: utilize loop in register indexes
Code Verilog - [aggrandize] one ii 3 4 5 vi 7 eight 9 10 11 12 13 fourteen 15 16 17 18 nineteen 20 21 22 reg [ vii : 0 ] res; reg [ 7 : 0 ] buff for (i = 0 ; i < 8 ; i = i + 1 ) res <= vitrify[i+ 1 :i] + i; module integers( clock, res ) ; input clock; output res; wire clock; reg [ vii : 0 ] res; reg [ seven : 0 ] buff = 0 ; genvar i; for (i = 0 ; i < viii ; i = i + i ) brainstorm e'er @ ( negedge clock) begin res <= vitrify + i; end terminate
information technology outputs only 1. but should counts.
- #2
- specify what y'all exactly want to accomplish
- read a Verilog text volume or tutorial
- write a code that complies with Verilog syntax rules
- come back with specific questions most your design, if any
- #three
- Joined
- Jan 26, 2015
- Letters
- 34
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Bays points
- 6
- Activity points
- 295
For example i have a viii-bit annals "res [seven:0]". Allow say i want to discover positive value in each $.25 in this register. Count positive bits.
- #4
This kind of question can easily be looked up by you. Why make u.s. do it. I plant a postal service on edaboard that discusses this.Actually i wrote separate lawmaking. But it seems merged.
For example i take a 8-fleck register "res [7:0]". Allow say i desire to find positive value in each bits in this register. Count positive $.25.
Use the advanced search and look for a mail called "Count the number of 1's" as the title of the mail.
- #five
1 - Do you want something that loops in time?
ii - Do you want to unroll logic, so that you get multiple pieces of logic that execute simultaneously next (loop in infinite)?
Pick 1) is typically what people desire. And so they try (and fail) to employ the loop keyword in verilog for that. This is precisely Not how it works.
When y'all use the loop construct in verilog you really get option 2.
So, repeat after me: loop in verilog does Non loop temporally. loop in verilog loops spatially.
If you want something that loops in time yous should use a counter.
If I look at your code you are already ahead of a large number of the "Don't know what looping does" oversupply, because yous do some things right. Buuuut there'due south as well a few problems with information technology.
It would assistance if you tin can clearly state what your requirements are:
Should it produce a issue every clock cycle? Or is it allowed to produce a result every 8th bike for example.
What does "Count positive bits." mean exactly? I suspect you want to find the number of $.25 that is set to value of 1, but not 100% sure.
Then practise you desire something like this?
input ==> output
8'b00000000 => 0
8'b00010000 => 1
8'b10000000 => i
8'b00100110 => 3
8'b11111111 => 8
...
etc
- #6
- Joined
- January 26, 2015
- Messages
- 34
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 295
Code Verilog - [expand] 1 ii 3 4 5 6 seven 8 9 10 11 12 13 xiv xv sixteen 17 xviii nineteen module integers( clock, res ) ; input clock; output res; wire clock; reg [ 7 : 0 ] res; reg [ 7 : 0 ] buff = 0 ; genvar i; for (i = 0 ; i < 8 ; i = i + i ) begin : exam always @ ( negedge clock) brainstorm vitrify[i] <= 1 ; res <= buff; finish stop endmodule
For each clock сycle information technology should output:
res = 00000001
res = 00000011
res = 00000111
.
till
res = 11111111
but it outputs:
everytime
res =1111111
information technology seem it shows last count. complete loop then outputs. Not every clock сycle.
what i want is:
buff <= ane;
when i = one
buff[i] = i
and outputs = 00000001
fist bit to prepare one;
then
buff[2] = i e.t.c
- - - Updated - - -
Code Verilog - [expand] one 2 iii module integers( clock, res ) ; input clock;
Code Verilog - [expand] i 2 iii iv 5 6 7 8 9 10 11 12 13 14 15 output res; wire clock; reg [ 7 : 0 ] res; reg [ 7 : 0 ] vitrify = 0 ; reg [ 7 : 0 ] count = 0 ; genvar i; //for (i = 0; i < viii ; i = i + 1) begin: test always @ ( negedge clock) begin count <= count + i ; buff[count] <= 1 ; res <= buff; end //end
- #7
So, repeat afterwards me: loop in verilog does Non loop temporally. loop in verilog loops spatially.If you want something that loops in time you lot should use a counter.
It's a mutual enough mistake, and then no shame there. But it does aid to read replies.
What yous fabricated there is 8 always blocks that exist and execute in parallel. I'll mail service the equivalent to help understand what's going on.
Your lawmaking:
Lawmaking Verilog - [expand] 1 2 3 4 5 6 7 8 nine 10 xi 12 13 14 15 16 17 module integers( clock, res) ; input clock; output res; wire clock; reg [ 7 : 0 ] res; reg [ vii : 0 ] vitrify = 0 ; genvar i; for (i = 0 ; i < viii ; i = i + 1 ) begin : test always @ ( negedge clock) brainstorm buff[i] <= 1 ; res <= buff; end end endmodule
Equivalent code with the generate loop explicitely unrolled:
Code Verilog - [expand] 1 ii 3 4 5 6 7 8 9 ten 11 12 xiii xiv 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 module integers( clock, res) ; input clock; output res; wire clock; reg [ 7 : 0 ] res; reg [ 7 : 0 ] vitrify = 0 ; // equivalent for i=0 always @ ( negedge clock) begin buff[ 0 ] <= 1 ; res <= buff; end // equivalent for i=1 always @ ( negedge clock) begin buff[ 1 ] <= 1 ; res <= vitrify; end // equivalents for i=2..half-dozen go hither // equivalent for i=seven always @ ( negedge clock) begin buff[ vii ] <= 1 ; res <= buff; end endmodule
And equally you can imagine that is equivalent to:
Code Verilog - [expand] 1 2 3 4 5 6 seven ... // equivalent with all the above always blocks lumped together always @ ( negedge clock) begin buff <= 8'b11111111 ; res<= buff; end
And that is why you get that all ones (8'b11111111) consequence after one clock cycle.
And to repeat the repeated repetition:
If you desire something that loops in time you should utilise a counter.
Promise that clear things up.
PS: Two more modest things. Offset, it mostly gives better results to use spaces instead of tabs when posting code. Four (4) spaces for an indent is a reasonable value IMO. And the other small thing is that it's considered better style to use this kind of module port proclamation:
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 x eleven 12 module integers( input clock, // you could comment this, although clock is probably understood well plenty output reg [ vii : 0 ] res// putting a short description of the "res" bespeak here will increment code readability ) ; reg [ 7 : 0 ] buff = 0 ; ever @ ( negedge clock) begin buff <= 8'b11111111 ; res<= vitrify; finish endmodule
That'due south a bit shorter, and possibly more readable and maintainable.
- #viii
- Joined
- Jan 26, 2015
- Messages
- 34
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Bays points
- half-dozen
- Activity points
- 295
Code Verilog - [expand] 1 2 three 4 5 half dozen 7 8 9 10 11 12 13 14 fifteen xvi 17 18 module integers( clock, res ) ; input clock; output res; wire clock; reg [ 7 : 0 ] res; reg [ 7 : 0 ] buff = 0 ; reg [ 7 : 0 ] count = 0 ; genvar i; //for (i = 0; i < viii ; i = i + ane) begin: test always @ ( negedge clock) begin count <= count + i ; vitrify[count] <= 1 ; res <= buff; stop //end
- #ix
That, and try to actually incorporate suggestions to improve your code readability:
- Your indents are haphazard and all over the place. apply four spaces per indent. Why? Curt version: to the lowest degree amount of trouble, and always works
- Do not put in commented bits of old code, unless these are specific to the problem being discussed. In this instance your two commented lines have nothing to exercise with the residual of information technology.
- Amend to post a consummate module. Now nosotros have to judge what comes subsequently information technology. sometimes relevant, former not.
- And for bonus points yous could use verilog-2001 ANSI style module port declarations, as shown to you in previous posts.
Anyways, main thing is I don't sympathise this... please rephrase:
in this code (count reg) can use equally alphabetize for one fleck and works well; just when i desire to utilise multiple indexes it shows bug"count is not a constant"
- #10
Code Verilog - [aggrandize] 1 2 // assign past pairs of indicies [1:0], [3:2], etc buff[ 2 *count +: two ] <= 3 ;
- #11
In which case your mistake correcting requirements decoder works better than mine.I recollect the OP is trying to assign a slice.
- #12
Here y'all can buy a new i ;-)In which case your mistake correcting requirements decoder works meliorate than mine.![]()
- #13
- Joined
- Jan 26, 2015
- Messages
- 34
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 295
Y'all have caught exact what i hateful.
One question: is there any sources(books) where i can find such rools.
- #14
rools? If you mean rules. I found that syntax for chip slicing in the LRM.One question: is at that place whatever sources(books) where i can observe such rools.
- Condition
- Not open for further replies.
Similar threads
- [SOLVED] Verilog loop with certain registers
- Started past ismailov-due east
- Replies: 2
- [SOLVED] Problem with loop operation
- Started past ismailov-east
- Replies: half-dozen
- Verilog error with for loop
- Started by ykishore
- Replies: two
-
problem with for loop in verilog- Started by keremcant
- Replies: 9
- Verilog array of registers synthesis problem
- Started by Dwaipayan
- Replies: 7
- Digital Pattern and Embedded Programming
- PLD, SPLD, GAL, CPLD, FPGA Pattern
- This site uses cookies to help personalise content, tailor your experience and to keep you lot logged in if y'all register.
By continuing to use this site, you are consenting to our use of cookies.
How To Loop With Registers,
Source: https://www.edaboard.com/threads/verilog-loop-operation-with-registers.330775/
Posted by: smithbrose1970.blogspot.com

0 Response to "How To Loop With Registers"
Post a Comment