shaiko
Advanced Member level 5
- Joined
- Aug 20, 2011
- Messages
- 2,644
- Helped
- 303
- Reputation
- 608
- Reaction score
- 297
- Trophy points
- 1,363
- Activity points
- 18,302
I never said that there's a "right" way to do it.There is no single answer to your question and no 'right' way to do it (although academics will probably say I'm wrong).
That's why I said - "when writing reusable logic blocks" (as opposed to logic customized to a very special system)The particular design kind of dictates how you should partition it.
Exactly! And I'm asking about the personal preference of users in this forum.There's also personal preference; that's where the 'art' comes into play.
So eventually you end up with a hierarchical structural design of a netlist? If you are designing down to the gate level for all your logic and aren't letting a synthesis tool do the work, then you must have a very forgiving job/boss that doesn't care about schedules or meeting deadlines to produce a product.I would describe my design down to even gate level logic(so that I can get a gate estimate as well as get to know the number of logic levels) and flop level logic.
The decision on the number of files to be used will be based on the functionality I suppose..(you might want to group stuff performing a common function together)
So eventually you end up with a hierarchical structural design of a netlist? If you are designing down to the gate level for all your logic and aren't letting a synthesis tool do the work, then you must have a very forgiving job/boss that doesn't care about schedules or meeting deadlines to produce a product.
If I did that at any of the jobs I've had I would have been put on the short list of next in line for layoffs. The easiest way to get a quick estimate of size and logic levels is to just run the module through synthesis, not creating a gate level description. It makes me think that your exposure to FPGA/ASIC design is primarily in academia, outside academia the primary objective is to produce something before the competition or within a certain schedule to meet a customer requirement. You certainly don't want to waste time doing what a synthesis tool already does for you.
The lowest level stuff you'll see is common library components for stuff like synchronizers, edge detectors, hamming codes, etc. For other stuff I sort of use a standard of keeping a file to 200 lines or less of code (ignoring comments) give or take 100 lines ;-). The only file that doesn't adhere to that standard are top level files for a large chunk of a design, which is made up of a bunch of instantiated submodules. In those cases I may have 1000+ line files.If I take a look at 80% of your "general purpose" designs - what type of components will I see in the lowest hierarchies?
Code Verilog - [expand] 1 shift_reg shift_reg_i (.shift_out(shift_data), .shift_in({shift_data[N-2:0], new_data}), .clk(clk));
Code Verilog - [expand] 1 2 always @ (posedge clk) shift_data <= {shift_data[N-2:0], new_data};
Code Verilog - [expand] 1 2 always @ (posedge clk) shift_data <= {new_data, shift_data[N-1:1], };
Code Verilog - [expand] 1 2 always @ (posedge clk) shift_data <= {shift_data[N-2:0], new_data};
And that is why I have a common library of synthesizable code that is parameterized and allows specifying all those special cases. So if I need something that specific I pull it from the library and bingo I know by looking at the code that it's from the library and it's not the simple version.Say when you want the SRL juuuust over there, and then a buffer flip-flop right there. Then you probably want a module that neatly abstracts that away. Otherwise you get too many inline constraints making it a bit unwieldy.
YesA simple example to elaborate:
An SPI peripheral consists of several logical components:
Shift register, clock generation logic, IO toggling, flag generation(ready/received data), etc...
If you look deeper - the clock generation logic will always have a counter in its heart and a comparator.
1. Will you design the SPI peripheral as a single component?
No. Something as simple as a shift register is just code in the file. For a SPI peripheral I don't know what sort of 'clock generator' there would be. However, for a SPI Controller, the 'clock generator' wouldn't really exist as such. Instead it is simply a counter where logic will use that counter value to do various things such as generating the SPI clock, enabling when input data is captured, allowing output data to change, etc.2. Will you divide it to components (shift register, clock generator , etc...) in several files ?
Not quite sure what you're asking here but yes the counter is described with a comparator. The upper limit on that counter is defined by two generic inputs to the entity: Clock_Period (the period of the FPGA's internal clock that is clocking the logic) and Spi_Clock_Period (which is the desired Spi clock period). Both are generic inputs of type 'time'. The ratio determines the upper bound of the counter. From that upper bound other constants that are useful to the Spi Controller are then computed such as the count that corresponds to when the rising edge should happen, the falling edge should happen, etc. (by the way, this is for the Spi controller, a Spi device would not need these since it is simply a slave to whatever the external Spi controller does). A Spi peripheral generally only needs to detect changes in the input Spi clock and then do something. To detect a change in the Spi clock one would simply compare the previous state to the current state, there would be no need for a 'clock generator'.3. Will you go even further down and describe the clock generator as a counter and comparator ?
And that is why I have a common library of synthesizable code that is parameterized and allows specifying all those special cases. So if I need something that specific I pull it from the library and bingo I know by looking at the code that it's from the library and it's not the simple version.
I've seen way to many designs turned into maintainence nightmares due to dividing up the logic into it's constituent components, shift registers, counters, etc.
When I said SPI peripheral - I meant ALL the logic that's required for a fully featured master & slave (including the controller).For a SPI peripheral I don't know what sort of 'clock generator' there would be. However, for a SPI Controller, the 'clock generator' wouldn't really exist as such.
The bad: to make it versatile and suitable for every need, each component tends to be complex.
I don't see anything "elegant" about having a bunch of shift registers, counters and glue logic scattered around, when you can put all that stuff into a single, well-verified module that provides a simple interface.
And then when you end up with 256 types of SPI modules you start generalizing again ?Yup. And sometimes this bad can become very bad. And then you pay the price for overgeneralization. And then you get sick of paying the price for overgeneralization. And then you keep things simple again.
Code Verilog - [expand] 1 2 3 a a_i (xyz, abc, nmo, pqr, c, r); b b_i (c, r, abc, xyz, hij); add add_i (hij, xyz, add_out);
And then when you end up with 256 types of SPI modules you start generalizing again ?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?