Author Topic: Verilog - elegant way of reading/writing into an array of registers?  (Read 3658 times)

0 Members and 1 Guest are viewing this topic.

Online daqqTopic starter

  • Super Contributor
  • ***
  • Posts: 2302
  • Country: sk
    • My site
Hi guys,

I've been trying to implement a simple configuration memory kind of module - basically you'd have N registers (8 in this case), you'd select them by the appropriate RWAddress and if you wished to write in the selected one you would assert RegisterWriteDataValid. The register array should be the output as well, in order to directly be able to connect the things that are to be configured by the registers.

I know that this could be done by means of a bunch of case statements, but I was hoping for something more elegant and easier to expand. The code below does not compile, giving the errors even further down.

Is there any simple way of doing this, or will I have to use case?

Code: [Select]
module ConfigurationRegisterManager(
input Clock, //Main input clock
input NReset, //Global negative reset

input [2:0] RWAddress, //7 = 1write, 0 read, 6:0 = address
input [15:0] NewValue,
output [15:0] Registers[0:3],
input RegisterWriteDataValid
);

reg [15:0] RegisterCurrentValue = 0;
reg [15:0] rRegisters[0:3];
assign Registers = rRegisters;

always @(posedge Clock) begin
if(RegisterWriteDataValid == 1) begin
RegisterCurrentValue[15:0] <= rRegisters[15:0][RWAddress];
end
end

endmodule


Code: [Select]
[HDLCompiler 1335] Port Registers must not be declared to be an array ["xxxxConfigurationRegisterManager.v":9]

[HDLCompiler 255] Cannot assign to memory Registers directly ["xxxxConfigurationRegisterManager.v":16]

[HDLCompiler 251] Cannot access memory rRegisters directly ["xxxxConfigurationRegisterManager.v":16]

[HDLCompiler 747] Range is not allowed in a prefix ["xxxxConfigurationRegisterManager.v":19]

[HDLCompiler 252] Cannot assign an unpacked type to a packed type ["xxxxConfigurationRegisterManager.v":19]

[HDLCompiler 598] Module <ConfigurationRegisterManager> ignored due to previous errors. ["xxxx/ConfigurationRegisterManager.v":3]

Thanks,

David
Believe it or not, pointy haired people do exist!
+++Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
 

Offline ale500

  • Frequent Contributor
  • **
  • Posts: 415
Re: Verilog - elegant way of reading/writing into an array of registers?
« Reply #1 on: November 15, 2016, 06:17:00 pm »
You are using all bits of RegisterCurrentValue and  rRegisters, thus you don't need to specify them:
Code: [Select]
      RegisterCurrentValue <= rRegisters[RWAddress];

would be right.

If you only want to assign bit 3 to 0, then you need an extra wire:

Code: [Select]
wire [15:0] extraWire;

      extraWire<= rRegisters[RWAddress];
      RegisterCurrentValue[3:0] <= extraWire[3:0];
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf