Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a hexadecimal value into a module in Verilog

I created a module that accepts a wire [ 4 : 0 ] as input, and I'm using several instances of this module. But, I'm getting:

Syntax error in instance port expression(s)

whenever I pass a value that contains A-F.

For example:

key_schedule i1(09); // works
key_schedule i1(0A); // doesn't work
key_schedule i1(15); // works
key_schedule i1(1D); // doesn't work

If anyone knows what's wrong, I'd appreciate their help.

Also, what happens if I'm passing a value "C", but I also have a wire called C?

like image 697
Hardell Avatar asked Jan 07 '13 21:01

Hardell


People also ask

How do you represent a hexadecimal number in Verilog?

Verilog Number Format. The <base format> consist of an apostrophe ( ' ) followed by b (binary, base-2), d (decimal, base-10), o (octal, base-8) or h (hexadecimal, base-16) for integer numbers.

Can I store a hex in an int?

Assigning the Hexadecimal number in a variable There is no special type of data type to store Hexadecimal values in C programming, Hexadecimal number is an integer value and you can store it in the integral type of data types (char, short or int).

What does #5 do in Verilog?

You might sometimes see this used with raw values, like #5 or #10, which means to wait 5 or 10 units of your timescale.

What is hexadecimal code?

Hexadecimal is a numbering system with base 16. It can be used to represent large numbers with fewer digits. In this system there are 16 symbols or possible digit values from 0 to 9, followed by six alphabetic characters -- A, B, C, D, E and F.


2 Answers

Verilog treats all bare numeric literals as decimal. A and D are not legal decimal values.

For hexadecimal literals, you need to specify the literal type using 'h:

key_schedule i1('h0A); // works
key_schedule i1('h1D); // works

Refer to the IEEE Std (1800-2009, for example), section "Numbers".

The following code compiles for me without errors on 2 different simulators (Incisive and VCS):

module tb;
    key_schedule i1(5'h1A);
    key_schedule i2('h1A);
endmodule

module key_schedule (input [4:0] in);
    always @(in) $display(in);
endmodule
like image 185
toolic Avatar answered Oct 11 '22 07:10

toolic


From http://www.asic-world.com/verilog/syntax1.html#Integer_Numbers

Verilog HDL allows integer numbers to be specified as

  • Sized or unsized numbers (Unsized size is 32 bits)
  • In a radix of binary, octal, decimal, or hexadecimal
  • Radix and hex digits (a,b,c,d,e,f) are case insensitive
  • Spaces are allowed between the size, radix and value

Syntax:

[size]'[radix][value];

Example:

8'h1D;   # 8-bit hex value "1D"
like image 45
dwikle Avatar answered Oct 11 '22 09:10

dwikle