Splitting the bits of a parameter for memory initialization in Verilog

Status
Not open for further replies.

parasonic

Newbie level 3
Joined
Apr 19, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
USA
Visit site
Activity points
1,316
I have written a SPI master in Verilog to write values to a PLL synthesizer chip. It works. I am now trying to clean up my code so that I can put all of the parameters for the PLL at the top of the file either as parameters or macro-style definitions. In a few cases, I have some values that are larger and need to be split in half to fit into the SPI words which are inferred ROM. Here is an abbreviated form of my code.

Code:
...
// Define with whatever works, possibly a wire, parameter, or define
wire [12:0] pll_r_counter = 13'd49;
...
reg [0:1] spi_reg [7:0];
initial
begin
   spi_reg[0] = pll_r_counter[7:0];
   spi_reg[1] = {{3'b0},pll_r_counter[13:8]};
...

This code doesn't seem to work, and I wouldn't really want to implement it with a wire. How should I approach this problem? Thanks!
 

I'm not 100% sure if this is what you're asking, but maybe this:


Code Verilog - [expand]
1
2
3
4
5
initial begin
    spi_reg[0] = MY_PARAMETER & 8'hFF;
    spi_reg[1] = (MY_PARAMETER >> 8) & 8'hFF;
// ...
end



Also keep in mind that parameters only 32-bits.
 
Thank you. This answers my question. It crossed my mind to do it this way, but I was not sure whether it would be the cleanest method.
 

Thank you. This answers my question. It crossed my mind to do it this way, but I was not sure whether it would be the cleanest method.
Well, not sure if it is the cleanest way, but it is reasonably clean. As far as I'm concerned, wires and `defines are out for this purpose. This is readible enough. A bit depending on how many you have, and how maintainable it will become you could also define all the parameters elsewhere. As in you have your parameters with The Numbers [tm], and then you have other parameters, that are simply a repack of those numbers into the 8-bit parameters. Like I said, it depends a bit on how many, and the packing in question. If it 90% of it is like this, just a byte selected from a larger parameter ... then I'd stick with the example. If you get hundreds of bytes, with all sorts of convoluted packing then I'd put that in a separate file with some comments on the format.
 
You could do this concatenation in a single statement:

Code:
{spi_reg[1],spi_reg[0]} = pll_r_counter;

And even more easy in SystemVerilog with the streaming operator
Code:
spi_reg = {<<8{pll_r_counter}};
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…