Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] verilog code to find mean of 20 numbers

Status
Not open for further replies.

Sreya39

Junior Member level 2
Junior Member level 2
Joined
Aug 30, 2007
Messages
24
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,283
Location
India
Activity points
1,516
verilog synthesis unsupported real constant

Hi buddies,

Plz help me to find the mean of 20 numbers. it is easy to add all the 20 numbers. But it accepts the divisor only in power of 2 (ie 2,4, 16....). it is for my project so plz respond as quickly as possible.....

Thanks and regards,
Sreya
 

For division you have got two options
Either writte the code urself *
Or use divider IP Core from core generator. The code for the core will not be visible however it can be synthsized and will perform the task of division for u.

* Division is done by subtracting the denominator from numinator until dmn> nmn
Number of times u subtract is ur answer.
 

    Sreya39

    Points: 2
    Helpful Answer Positive Rating
An alternative to division is to multiply by a fraction.
 

To use IP core let me go in a sequential way

Go to ADD NEW SOURCE
write name of file and in category select IP CORE GENERATOR
A window will open showing all the available cores
Go to MATH FUNCTIONS
in math functions go to DIVDIERS
there are two divider available use any one u like

The console window will shoe GENERATING IP
After the IP is addrd u will see a file added in ur project navigator with the extension *.xco

Go to OPEN FILE
Open the file with the extension ".veo"
This is the instantiation of generated core
Copy it and place it in ur design


If still u get some problems feel free to ask
 

    Sreya39

    Points: 2
    Helpful Answer Positive Rating
Mr.sameem_shabbir
will u plz explain in a more clear way the steps followed.
I hav tried over it. But i am not able to get the output.

Thanks and Regards,
Sreya.
 

Here you need to divide the sum by 20 = 4X5; Means first divide by 4 (shift right by 2) then
multiply by 0.2
 

    Sreya39

    Points: 2
    Helpful Answer Positive Rating
Hi nand_gates,
The error i am getting is unsupported real constant while multiplying the value with 0.2. i have also tried by first dividing by 4, then by 8 and then multiplying by 1.6. Is there any other way to solve this pblm....

Thanks and Regards,
Sreya
 

Today's HDL synthesis tools don't support Verilog or VHDL floating point type, but you can use fixed-point techniques instead. For example, 0.02 is approximately equal to 1311/65536, so you could multiply by 1311, add 32768 (for rounding), and then right-shift by 16. For higher accuracy, use larger terms in the ratio.
 

    Sreya39

    Points: 2
    Helpful Answer Positive Rating
If the numbers are 8bit unsigned integers then you can use lookup table method to do
division by 20.
 

    Sreya39

    Points: 2
    Helpful Answer Positive Rating
how to use look up table method????

Thanks and regards,
Sreya.
 

this is the way!
Code:
case (sum)
     0 : average = 0 ;
     1 : average = 0 ;
     2 : average = 0 ;
     3 : average = 0 ;
     4 : average = 0 ;
     5 : average = 0 ;
     6 : average = 0 ;
     7 : average = 0 ;
     8 : average = 0 ;
     9 : average = 0 ;
    10 : average = 0 ;
    11 : average = 0 ;
    12 : average = 0 ;
    13 : average = 0 ;
    14 : average = 0 ;
    15 : average = 0 ;
    16 : average = 0 ;
    17 : average = 0 ;
    18 : average = 0 ;
    19 : average = 0 ;
    20 : average = 1 ;
    21 : average = 1 ;
    22 : average = 1 ;
    23 : average = 1 ;
    24 : average = 1 ;
    25 : average = 1 ;
    26 : average = 1 ;
    27 : average = 1 ;
    28 : average = 1 ;
    29 : average = 1 ;
    30 : average = 1 ;
    31 : average = 1 ;
    32 : average = 1 ;
    33 : average = 1 ;
    34 : average = 1 ;
    35 : average = 1 ;
    36 : average = 1 ;
    37 : average = 1 ;
    38 : average = 1 ;
    39 : average = 1 ;
    40 : average = 2 ;
    41 : average = 2 ;
    42 : average = 2 ;
    43 : average = 2 ;
    44 : average = 2 ;
    45 : average = 2 ;
    46 : average = 2 ;
    47 : average = 2 ;
    48 : average = 2 ;
    49 : average = 2 ;
    50 : average = 2 ;
    51 : average = 2 ;
    52 : average = 2 ;
    53 : average = 2 ;
    54 : average = 2 ;
    55 : average = 2 ;
    56 : average = 2 ;
    57 : average = 2 ;
    58 : average = 2 ;
    59 : average = 2 ;
    60 : average = 3 ;
    61 : average = 3 ;
    62 : average = 3 ;
    63 : average = 3 ;
    64 : average = 3 ;
    65 : average = 3 ;
    66 : average = 3 ;
    67 : average = 3 ;
    68 : average = 3 ;
    69 : average = 3 ;
    70 : average = 3 ;
    71 : average = 3 ;
    72 : average = 3 ;
    73 : average = 3 ;
    74 : average = 3 ;
    75 : average = 3 ;
    76 : average = 3 ;
    77 : average = 3 ;
    78 : average = 3 ;
    79 : average = 3 ;
    80 : average = 4 ;
    81 : average = 4 ;
    82 : average = 4 ;
    83 : average = 4 ;
    84 : average = 4 ;
    85 : average = 4 ;
    86 : average = 4 ;
    87 : average = 4 ;
    88 : average = 4 ;
    89 : average = 4 ;
    90 : average = 4 ;
    91 : average = 4 ;
    92 : average = 4 ;
    93 : average = 4 ;
    94 : average = 4 ;
    95 : average = 4 ;
    96 : average = 4 ;
    97 : average = 4 ;
    98 : average = 4 ;
    99 : average = 4 ;
   100 : average = 5 ;
   101 : average = 5 ;
   102 : average = 5 ;
   103 : average = 5 ;
   104 : average = 5 ;
   105 : average = 5 ;
   106 : average = 5 ;
   107 : average = 5 ;
   108 : average = 5 ;
   109 : average = 5 ;
   110 : average = 5 ;
   111 : average = 5 ;
   112 : average = 5 ;
   113 : average = 5 ;
   114 : average = 5 ;
   115 : average = 5 ;
   116 : average = 5 ;
   117 : average = 5 ;
   118 : average = 5 ;
   119 : average = 5 ;
   120 : average = 6 ;
   121 : average = 6 ;
   122 : average = 6 ;
   123 : average = 6 ;
   124 : average = 6 ;
   125 : average = 6 ;
   126 : average = 6 ;
   127 : average = 6 ;
   128 : average = 6 ;
   129 : average = 6 ;
   130 : average = 6 ;
   131 : average = 6 ;
   132 : average = 6 ;
   133 : average = 6 ;
   134 : average = 6 ;
   135 : average = 6 ;
   136 : average = 6 ;
   137 : average = 6 ;
   138 : average = 6 ;
   139 : average = 6 ;
   140 : average = 7 ;
   141 : average = 7 ;
   142 : average = 7 ;
   143 : average = 7 ;
   144 : average = 7 ;
   145 : average = 7 ;
   146 : average = 7 ;
   147 : average = 7 ;
   148 : average = 7 ;
   149 : average = 7 ;
   150 : average = 7 ;
   151 : average = 7 ;
   152 : average = 7 ;
   153 : average = 7 ;
   154 : average = 7 ;
   155 : average = 7 ;
   156 : average = 7 ;
   157 : average = 7 ;
   158 : average = 7 ;
   159 : average = 7 ;
   160 : average = 8 ;
   161 : average = 8 ;
   162 : average = 8 ;
   163 : average = 8 ;
   164 : average = 8 ;
   165 : average = 8 ;
   166 : average = 8 ;
   167 : average = 8 ;
   168 : average = 8 ;
   169 : average = 8 ;
   170 : average = 8 ;
   171 : average = 8 ;
   172 : average = 8 ;
   173 : average = 8 ;
   174 : average = 8 ;
   175 : average = 8 ;
   176 : average = 8 ;
   177 : average = 8 ;
   178 : average = 8 ;
   179 : average = 8 ;
   180 : average = 9 ;
   181 : average = 9 ;
   182 : average = 9 ;
   183 : average = 9 ;
   184 : average = 9 ;
   185 : average = 9 ;
   186 : average = 9 ;
   187 : average = 9 ;
   188 : average = 9 ;
   189 : average = 9 ;
   190 : average = 9 ;
   191 : average = 9 ;
   192 : average = 9 ;
   193 : average = 9 ;
   194 : average = 9 ;
   195 : average = 9 ;
   196 : average = 9 ;
   197 : average = 9 ;
   198 : average = 9 ;
   199 : average = 9 ;
   200 : average = 10;
   201 : average = 10;
   202 : average = 10;
   203 : average = 10;
   204 : average = 10;
   205 : average = 10;
   206 : average = 10;
   207 : average = 10;
   208 : average = 10;
   209 : average = 10;
   210 : average = 10;
   211 : average = 10;
   212 : average = 10;
   213 : average = 10;
   214 : average = 10;
   215 : average = 10;
   216 : average = 10;
   217 : average = 10;
   218 : average = 10;
   219 : average = 10;
   220 : average = 11;
   221 : average = 11;
   222 : average = 11;
   223 : average = 11;
   224 : average = 11;
   225 : average = 11;
   226 : average = 11;
   227 : average = 11;
   228 : average = 11;
   229 : average = 11;
   230 : average = 11;
   231 : average = 11;
   232 : average = 11;
   233 : average = 11;
   234 : average = 11;
   235 : average = 11;
   236 : average = 11;
   237 : average = 11;
   238 : average = 11;
   239 : average = 11;
   240 : average = 12;
   241 : average = 12;
   242 : average = 12;
   243 : average = 12;
   244 : average = 12;
   245 : average = 12;
   246 : average = 12;
   247 : average = 12;
   248 : average = 12;
   249 : average = 12;
   250 : average = 12;
   251 : average = 12;
   252 : average = 12;
   253 : average = 12;
   254 : average = 12;
   255 : average = 12;
   256 : average = 12;
   default : average = 0;
endcase
you can add fractional part also if you want
 

    Sreya39

    Points: 2
    Helpful Answer Positive Rating
i think there i asimple way to do this job. I will think about it! Good problem
 

Fixed point division table. fixed point is in middle. LS nibble represents number after decimal point.
Code:
case (sum)
     0 : average = 8'b0000_0000;
     1 : average = 8'b0000_0000;
     2 : average = 8'b0000_1000;   // 0.5
     3 : average = 8'b0000_0100;   // 0.25
     4 : average = 8'b0000_1100;
     5 : average = 8'b0000_0010;
     6 : average = 8'b0000_0010;
     7 : average = 8'b0000_1010;
     8 : average = 8'b0000_0110;
     9 : average = 8'b0000_1110;
    10 : average = 8'b0000_0001;
    11 : average = 8'b0000_0001;
    12 : average = 8'b0000_1001;
    13 : average = 8'b0000_0101;
    14 : average = 8'b0000_1101;
    15 : average = 8'b0000_0011;
    16 : average = 8'b0000_0011;
    17 : average = 8'b0000_1011;
    18 : average = 8'b0000_0111;
    19 : average = 8'b0000_1111;
    20 : average = 8'b0001_0000;
    21 : average = 8'b0001_0000;
    22 : average = 8'b0001_1000;
    23 : average = 8'b0001_0100;
    24 : average = 8'b0001_1100;
    25 : average = 8'b0001_0010;
    26 : average = 8'b0001_0010;
    27 : average = 8'b0001_1010;
    28 : average = 8'b0001_0110;
    29 : average = 8'b0001_1110;    //1.4375
    30 : average = 8'b0001_0001;
    31 : average = 8'b0001_0001;
    32 : average = 8'b0001_1001;
    33 : average = 8'b0001_0101;
    34 : average = 8'b0001_1101;
    35 : average = 8'b0001_0011;
    36 : average = 8'b0001_0011;
    37 : average = 8'b0001_1011;
    38 : average = 8'b0001_0111;
    39 : average = 8'b0001_1111;
    40 : average = 8'b0010_0000;
    41 : average = 8'b0010_0000;
    42 : average = 8'b0010_1000;
    43 : average = 8'b0010_0100;
    44 : average = 8'b0010_1100;
    45 : average = 8'b0010_0010;
    46 : average = 8'b0010_0010;
    47 : average = 8'b0010_1010;
    48 : average = 8'b0010_0110;
    49 : average = 8'b0010_1110;
    50 : average = 8'b0010_0001;
    51 : average = 8'b0010_0001;
    52 : average = 8'b0010_1001;
    53 : average = 8'b0010_0101;
    54 : average = 8'b0010_1101;
    55 : average = 8'b0010_0011;
    56 : average = 8'b0010_0011;
    57 : average = 8'b0010_1011;
    58 : average = 8'b0010_0111;
    59 : average = 8'b0010_1111;
    60 : average = 8'b0011_0000;
    61 : average = 8'b0011_0000;
    62 : average = 8'b0011_1000;
    63 : average = 8'b0011_0100;
    64 : average = 8'b0011_1100;
    65 : average = 8'b0011_0010;
    66 : average = 8'b0011_0010;
    67 : average = 8'b0011_1010;
    68 : average = 8'b0011_0110;
    69 : average = 8'b0011_1110;
    70 : average = 8'b0011_0001;
    71 : average = 8'b0011_0001;
    72 : average = 8'b0011_1001;
    73 : average = 8'b0011_0101;
    74 : average = 8'b0011_1101;
    75 : average = 8'b0011_0011;
    76 : average = 8'b0011_0011;
    77 : average = 8'b0011_1011;
    78 : average = 8'b0011_0111;
    79 : average = 8'b0011_1111;
    80 : average = 8'b0100_0000;
    81 : average = 8'b0100_0000;
    82 : average = 8'b0100_1000;
    83 : average = 8'b0100_0100;
    84 : average = 8'b0100_1100;
    85 : average = 8'b0100_0010;
    86 : average = 8'b0100_0010;
    87 : average = 8'b0100_1010;
    88 : average = 8'b0100_0110;
    89 : average = 8'b0100_1110;  // 4.4375
    90 : average = 8'b0100_0001;
    91 : average = 8'b0100_0001;
    92 : average = 8'b0100_1001;
    93 : average = 8'b0100_0101;
    94 : average = 8'b0100_1101;
    95 : average = 8'b0100_0011;
    96 : average = 8'b0100_0011;
    97 : average = 8'b0100_1011;
    98 : average = 8'b0100_0111;
    99 : average = 8'b0100_1111;
   100 : average = 8'b0101_0000;
   101 : average = 8'b0101_0000;
   102 : average = 8'b0101_1000;
   103 : average = 8'b0101_0100;
   104 : average = 8'b0101_1100;
   105 : average = 8'b0101_0010;
   106 : average = 8'b0101_0010;
   107 : average = 8'b0101_1010;
   108 : average = 8'b0101_0110;
   109 : average = 8'b0101_1110;
   110 : average = 8'b0101_0001;
   111 : average = 8'b0101_0001;
   112 : average = 8'b0101_1001;
   113 : average = 8'b0101_0101;
   114 : average = 8'b0101_1101;
   115 : average = 8'b0101_0011;
   116 : average = 8'b0101_0011;
   117 : average = 8'b0101_1011;
   118 : average = 8'b0101_0111;
   119 : average = 8'b0101_1111;
   120 : average = 8'b0110_0000;
   121 : average = 8'b0110_0000;
   122 : average = 8'b0110_1000;
   123 : average = 8'b0110_0100;
   124 : average = 8'b0110_1100;
   125 : average = 8'b0110_0010;
   126 : average = 8'b0110_0010;
   127 : average = 8'b0110_1010;
   128 : average = 8'b0110_0110;
   129 : average = 8'b0110_1110;
   130 : average = 8'b0110_0001;
   131 : average = 8'b0110_0001;
   132 : average = 8'b0110_1001;
   133 : average = 8'b0110_0101;
   134 : average = 8'b0110_1101;
   135 : average = 8'b0110_0011;
   136 : average = 8'b0110_0011;
   137 : average = 8'b0110_1011;
   138 : average = 8'b0110_0111;
   139 : average = 8'b0110_1111;
   140 : average = 8'b0111_0000;
   141 : average = 8'b0111_0000;
   142 : average = 8'b0111_1000;
   143 : average = 8'b0111_0100;
   144 : average = 8'b0111_1100;
   145 : average = 8'b0111_0010;
   146 : average = 8'b0111_0010;
   147 : average = 8'b0111_1010;
   148 : average = 8'b0111_0110;
   149 : average = 8'b0111_1110;
   150 : average = 8'b0111_0001;
   151 : average = 8'b0111_0001;
   152 : average = 8'b0111_1001;
   153 : average = 8'b0111_0101;
   154 : average = 8'b0111_1101;
   155 : average = 8'b0111_0011;
   156 : average = 8'b0111_0011;
   157 : average = 8'b0111_1011;
   158 : average = 8'b0111_0111;
   159 : average = 8'b0111_1111;
   160 : average = 8'b1000_0000;
   161 : average = 8'b1000_0000;
   162 : average = 8'b1000_1000;
   163 : average = 8'b1000_0100;
   164 : average = 8'b1000_1100;
   165 : average = 8'b1000_0010;
   166 : average = 8'b1000_0010;
   167 : average = 8'b1000_1010;
   168 : average = 8'b1000_0110;
   169 : average = 8'b1000_1110;
   170 : average = 8'b1000_0001;
   171 : average = 8'b1000_0001;
   172 : average = 8'b1000_1001;
   173 : average = 8'b1000_0101;
   174 : average = 8'b1000_1101;
   175 : average = 8'b1000_0011;
   176 : average = 8'b1000_0011;
   177 : average = 8'b1000_1011;
   178 : average = 8'b1000_0111;
   179 : average = 8'b1000_1111;
   180 : average = 8'b1001_0000;
   181 : average = 8'b1001_0000;
   182 : average = 8'b1001_1000;
   183 : average = 8'b1001_0100;
   184 : average = 8'b1001_1100;
   185 : average = 8'b1001_0010;
   186 : average = 8'b1001_0010;
   187 : average = 8'b1001_1010;
   188 : average = 8'b1001_0110;
   189 : average = 8'b1001_1110;
   190 : average = 8'b1001_0001;
   191 : average = 8'b1001_0001;
   192 : average = 8'b1001_1001;
   193 : average = 8'b1001_0101;
   194 : average = 8'b1001_1101;
   195 : average = 8'b1001_0011;
   196 : average = 8'b1001_0011;
   197 : average = 8'b1001_1011;
   198 : average = 8'b1001_0111;
   199 : average = 8'b1001_1111;
   200 : average = 8'b1010_0000;
   201 : average = 8'b1010_0000;
   202 : average = 8'b1010_1000;
   203 : average = 8'b1010_0100;
   204 : average = 8'b1010_1100;
   205 : average = 8'b1010_0010;
   206 : average = 8'b1010_0010;
   207 : average = 8'b1010_1010;
   208 : average = 8'b1010_0110;
   209 : average = 8'b1010_1110;
   210 : average = 8'b1010_0001;
   211 : average = 8'b1010_0001;
   212 : average = 8'b1010_1001;
   213 : average = 8'b1010_0101;
   214 : average = 8'b1010_1101;
   215 : average = 8'b1010_0011;
   216 : average = 8'b1010_0011;
   217 : average = 8'b1010_1011;
   218 : average = 8'b1010_0111;
   219 : average = 8'b1010_1111;
   220 : average = 8'b1011_0000;
   221 : average = 8'b1011_0000;
   222 : average = 8'b1011_1000;
   223 : average = 8'b1011_0100;
   224 : average = 8'b1011_1100;
   225 : average = 8'b1011_0010;
   226 : average = 8'b1011_0010;
   227 : average = 8'b1011_1010;
   228 : average = 8'b1011_0110;
   229 : average = 8'b1011_1110;
   230 : average = 8'b1011_0001;
   231 : average = 8'b1011_0001;
   232 : average = 8'b1011_1001;
   233 : average = 8'b1011_0101;
   234 : average = 8'b1011_1101;
   235 : average = 8'b1011_0011;
   236 : average = 8'b1011_0011;
   237 : average = 8'b1011_1011;
   238 : average = 8'b1011_0111;
   239 : average = 8'b1011_1111;
   240 : average = 8'b1100_0000;
   241 : average = 8'b1100_0000;
   242 : average = 8'b1100_1000;
   243 : average = 8'b1100_0100;
   244 : average = 8'b1100_1100;
   245 : average = 8'b1100_0010;
   246 : average = 8'b1100_0010;
   247 : average = 8'b1100_1010;
   248 : average = 8'b1100_0110;
   249 : average = 8'b1100_1110;
   250 : average = 8'b1100_0001;
   251 : average = 8'b1100_0001;
   252 : average = 8'b1100_1001;
   253 : average = 8'b1100_0101;
   254 : average = 8'b1100_1101;
   255 : average = 8'b1100_0011;
   256 : average = 8'b1100_0011;
   default : average = 0;
endcase
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top