FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-05-2008, 06:24 AM
sandeep
Guest
 
Posts: n/a
Default size specification in size constant

Hi
Consider following size constant -- "temp = 10'd28".
Now I want to replace 10 with parameter TEN = 10;
i.e temp = TEN'd28.
But compiler is giving error for above expression. It is allowing me
to use `define TEN 10
and `TEN'd28.
I donot know my complain is valid or not but it is stupid thing. I
donot want to use `define construct instead my pref is parameter
construct.
Is there any way I can use parameter and write temp = {parameter'd28}
Regards
Reply With Quote
  #2 (permalink)  
Old 11-05-2008, 07:19 AM
Robert Miles
Guest
 
Posts: n/a
Default Re: size specification in size constant


"sandeep" <[email protected]> wrote in message
news:[email protected]..
> Hi
> Consider following size constant -- "temp = 10'd28".
> Now I want to replace 10 with parameter TEN = 10;
> i.e temp = TEN'd28.
> But compiler is giving error for above expression. It is allowing me
> to use `define TEN 10
> and `TEN'd28.
> I donot know my complain is valid or not but it is stupid thing. I
> donot want to use `define construct instead my pref is parameter
> construct.
> Is there any way I can use parameter and write temp = {parameter'd28}
> Regards

..
Constants are seldom called temp, so you might want to see if it helps if
you give it some other name instead.


Reply With Quote
  #3 (permalink)  
Old 11-05-2008, 07:31 AM
Rock
Guest
 
Posts: n/a
Default Re: size specification in size constant

On 11月5日, 下午1时24分, sandeep <sandeepkumar....@gmail.com> wrote:
> Hi
> Consider following size constant -- "temp = 10'd28".
> Now I want to replace 10 with parameter TEN = 10;
> i.e temp = TEN'd28.
> But compiler is giving error for above expression. It is allowing me
> to use `define TEN 10
> and `TEN'd28.
> I donot know my complain is valid or not but it is stupid thing. I
> donot want to use `define construct instead my pref is parameter
> construct.
> Is there any way I can use parameter and write temp = {parameter'd28}
> Regards


The Verilog Spec just defines that we can use unsigned none zero
number as the SIZE.
Reply With Quote
  #4 (permalink)  
Old 11-05-2008, 11:48 PM
gabor
Guest
 
Posts: n/a
Default Re: size specification in size constant

On Nov 5, 12:24*am, sandeep <sandeepkumar....@gmail.com> wrote:
> Hi
> Consider following size constant -- "temp = 10'd28".
> Now I want to replace 10 with parameter TEN = 10;
> i.e temp = TEN'd28.
> But compiler is giving error for above expression. It is allowing me
> to use `define TEN 10
> and `TEN'd28.
> I donot know my complain is valid or not but it is stupid thing. I
> donot want to use `define construct instead my pref is parameter
> construct.
> Is there any way I can use parameter and write temp = {parameter'd28}
> Regards


Deja Vu

Look for the thread:

Parameterised width assignments

in this newsgroup from May of last year.
Reply With Quote
  #5 (permalink)  
Old 11-06-2008, 03:10 PM
Jonathan Bromley
Guest
 
Posts: n/a
Default Re: size specification in size constant

On Tue, 4 Nov 2008 21:24:22 -0800 (PST), sandeep wrote:

>Consider following size constant -- "temp = 10'd28".
>Now I want to replace 10 with parameter TEN = 10;
>i.e temp = TEN'd28.
>But compiler is giving error for above expression. It is allowing me
>to use `define TEN 10
>and `TEN'd28.
>I donot know my complain is valid or not but it is stupid thing. I
>donot want to use `define construct instead my pref is parameter
>construct.
>Is there any way I can use parameter and write temp = {parameter'd28}


Since Verilog-2001 it has been legal to size parameters explicitly.

parameter SIZE = 10;
parameter [SIZE-1:0] temp = 28;

Now you know for sure that temp is exactly SIZE bits wide,
and you can use it in concatenations etc.

As others have said, the bit-wdith in sized numbers like 8'b1 must
be a simple literal number, and cannot be a parameter. For some
constants it's possible to use replication:

parameter temp = {SIZE{1'b0}};

However, I would question why you ever need to do this. What
will you do with the sized constant? As soon as you copy it
into some other variable, it takes on the size of the target
variable:

parameter SIZE = 10;
parameter n = 28; // there is no need for this to be 10 bits wide
reg [SIZE-1:0] target;

initial begin
...
target = n; // this is legal even though "n" is 32 bits
...

--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
[email protected]
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
Reply With Quote
  #6 (permalink)  
Old 11-07-2008, 12:20 AM
[email protected]
Guest
 
Posts: n/a
Default Re: size specification in size constant

On Nov 5, 12:24*am, sandeep <sandeepkumar....@gmail.com> wrote:
> Hi
> Consider following size constant -- "temp = 10'd28".
> Now I want to replace 10 with parameter TEN = 10;
> i.e temp = TEN'd28.
> But compiler is giving error for above expression. It is allowing me
> to use `define TEN 10
> and `TEN'd28.
> Is there any way I can use parameter and write temp = {parameter'd28}


Not directly, no.

A sized constant is a single entity that represents a simple constant,
and has a specific syntax. It is not an expression, and the 'd is not
an operator that combines two arbitrary expressions. It is composed
of several lexical tokens, which can be separated by white space and
can be independently macro-substituted, but these tokens are not
expressions.

As an analogy, consider the syntax of a real constant (such as
1.5e3). That has 3 numeric fields in it, but you cannot replace those
with expressions either. You cannot use ONE.FIVEeTHREE to set the
integer part, fractional part and exponent from three different
parameters. That probably seems reasonable to you because you have
more experience with this notation. If not, consider the simpler case
of the integer constant 15. If you have parameters ONE=1 and FIVE=5,
you cannot use ONE FIVE to represent the constant 15. The closest you
can get is to use ONE*10+FIVE.

If you want to build a constant value from expressions, you will have
to do it with operators. One ugly way to do this one would be
{{(TEN-5){1'b0}}, 5'd28}.

But I have to ask why you are trying to do this anyway? Why do you
care what the width of the constant is? The "28" part is fixed, and
you know it requires at least 5 bits. You can just use 5'd28. If you
use it in a context where you need something wider, the Verilog rules
for implicit width conversions will take care of extending it for
you. That is what they are for, to avoid having to worry about this
kind of thing.

If you have tools that warn about width mismatches for this, then they
are just being annoying and unreasonable. If you just use 28 (which
is 32 bits wide) and they complain about truncation to 10 bits, that
isn't quite as unreasonable, though they could stand to be smarter and
recognize that they are just truncating zeroes. If you use 5'd28 and
they complain about truncation to less than 5 bits, you need to look
closer.
Reply With Quote
  #7 (permalink)  
Old 11-07-2008, 03:35 AM
Glen Herrmannsfeldt
Guest
 
Posts: n/a
Default Re: size specification in size constant

sandeep wrote:

> Consider following size constant -- "temp = 10'd28".
> Now I want to replace 10 with parameter TEN = 10;
> i.e temp = TEN'd28.
> But compiler is giving error for above expression. It is allowing me
> to use `define TEN 10
> and `TEN'd28.
> I donot know my complain is valid or not but it is stupid thing. I
> donot want to use `define construct instead my pref is parameter
> construct.
> Is there any way I can use parameter and write temp = {parameter'd28}


You might be able to use the C preprocessor with verilog. I do wonder
about the apostrophes, though. I believe it is pretty rare, though.

-- glen

Reply With Quote
  #8 (permalink)  
Old 11-14-2008, 07:51 AM
sandeep
Guest
 
Posts: n/a
Default Re: size specification in size constant

On Nov 7, 10:35*am, Glen Herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
> sandeep wrote:
> > Consider following size constant -- "temp = 10'd28".
> > Now I want to replace 10 with parameter TEN = 10;
> > i.e temp = TEN'd28.
> > But compiler is giving error for above expression. It is allowing me
> > to use `define TEN 10
> > and `TEN'd28.
> > I donot know my complain is valid or not but it is stupid thing. I
> > donot want to use `define construct instead my pref is parameter
> > construct.
> > Is there any way I can use parameter and write temp = {parameter'd28}

>
> You might be able to use the C preprocessor with verilog. *I do wonder
> about the apostrophes, though. * I believe it is pretty rare, though.
>
> -- glen


Hi Everyone
Thanks for replies. Actually i write verilog code for modem and i have
to write lots of code like
signal_a <= signal_a + 1;
signal_b <= signal_b + 7;
signal_c <= signal_c + 15;
etc...

Synthesis tool are not creating any problem but linting tools generate
lots of warning about
size mismatch. So i thought i will write integer constant in sized
constant format.
but then i start getting trouble whenever i change bit width of
signal_a/_b_c.. ..
Finally i think it is better to write like unsized constant and donot
care about lint warning.
signal_a <= signal_a + 'd5;
signal_b <= signal_b + 'd8;
etc..
regards


Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
expression size romi Verilog 2 06-21-2008 01:11 AM
How to retrieve the size of a vector Ben Verilog 11 05-30-2008 10:59 PM
size of file terabits Verilog 3 01-02-2008 11:01 PM
vcd file size reduction thirunadha rao Verilog 5 06-07-2004 04:45 PM
Must function returns be of a known size? DW Verilog 10 06-02-2004 07:52 PM


All times are GMT +1. The time now is 01:58 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved