Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign a synthesizable initial value to a reg in Verilog

Tags:

I'm an FPGA noob trying to learn Verilog. How can I "assign" a value to a reg in an always block, either as an initial value, or as a constant. I'm trying to do something like this in the code below. I get an error because the 8 bit constant doesn't count as input. I also don't want to trigger the always off of a clock. I just want to assign a register to a specific value. As I want it to be synthesisable I can't use an initial block. Thanks a lot.

module top (     input wire clk,     output wire [7:0] led     );   reg [7:0] data_reg ;  always @* begin     data_reg = 8'b10101011; end  assign led = data_reg;  endmodule 
like image 208
Frank Dejay Avatar asked Apr 04 '12 05:04

Frank Dejay


People also ask

Can you use assign on a reg Verilog?

It is illegal to drive or assign reg type variables with an assign statement. This is because a reg variable is capable of storing data and does not require to be driven continuously. reg signals can only be driven in procedural blocks like initial and always .

Is initial begin synthesizable?

An initial block is not synthesizable and hence cannot be converted into a hardware schematic with digital elements. Hence initial blocks do not serve much purpose than to be used in simulations. These blocks are primarily used to initialize variables and drive design ports with specific values.

How do you assign a value to a variable in Verilog?

The value can either be a constant or an expression comprising of a group of signals. The assignment syntax starts with the keyword assign, followed by the signal name, which can be either a signal or a combination of different signal nets.

What is the default value of reg in Verilog?

reg is by default a one bit unsigned value.


1 Answers

You can combine the register declaration with initialization.

reg [7:0] data_reg = 8'b10101011; 

Or you can use an initial block

reg [7:0] data_reg; initial data_reg = 8'b10101011; 
like image 193
Nathan Farrington Avatar answered Oct 03 '22 08:10

Nathan Farrington