Reputation: 15
I have an array of size 2400. I want to be able to update a certain bit in this array based on combinational logic that determines the index of that bit.
Accessing the bit directly gives me a multiple driver error due to having already assigning the array an initial value, and after trying to implement a state machine, I have found it nearly impossible due to it requiring the previous value of the entire array. ie: Can't assign ranges with a variable.
logic [0:2400] big_array;
assign big_array = {ALL BITS ASSIGNED};
//Here is where I want to be able to update
logic [11:0] index;
//INDEX Determined via logic
assign big_array[index] = 1'b0;
Any help would be awesome!
Note: I'm fairly sure I can accomplish this through some type of state machine because I am assigning an original value, but I can't figure it out. Is it possible to priority assign values?
Subtracting is out of the questions since the number would be too large.
Upvotes: 0
Views: 2181
Reputation: 1032
I'm not sure if this is what you are looking for, but there is an array (vector) of 2400 bits. Given an index, which we'll assume you derived using combinational logic as you said, the element at that index is updated.
I am giving a solution that is meant for synthesizable RTL, since you used the word combinational, and I am assuming you are trying to synthesize this logic to hardware.
logic [2399:0] big_array;
logic [11:0] index;
always_comb begin
// combinational logic here
index = ...
end
always_ff @(posedge clk, posedge reset) begin
if (reset) begin
big_array = '0; // vector fill operation
end else begin
big_array[index] = ...;
end
end
I haven't checked the code above for syntax errors. Also, note that I used a clocked process for the array updating, however, you could use some other triggering mechanism if you weren't intending to synthesize this code. Likewise, you could use an initial statement instead of the reset block.
I think the assignment big_array[index] = ...
will elaborate, but if not you could loop through all indices until a match is found as other commenters have suggested.
Upvotes: 1