# [SOLVED]Problem with fixed point multiplication

Status
Not open for further replies.

#### normantg

##### Newbie level 1
I am trying to do a fixed point multiplication and I always get the same error in the simulation stage.

I have a histogram values saved in a memory and at some point I want to compute a threshold for that histogram which I will use to classify the bins in two groups. I have these 3 variables, where 'maxim' is the highest value of the histogram, 'thresh_low' is a percentage value to apply, let's say 0.2, and 'thvar' is where I am planning to save the absolute threshold value:

variable maxim : ufixed(18 downto 0);
variable thresh_low : ufixed(0 downto -8);
variable thvar : ufixed(18 downto -8);

At some point I assign values for the variables 'maxim' and 'thresh_low', and proceed to make a multiplication

thvar := maxim*thresh_low;​

My intention later is to discard all the decimal values from 'thvar' and keep the integer part as a threshold.

I am simulating all my code with Modelsim for now, so I compile the code without any errors and proceed to simulate. I have some other code that is executed before this part is, and it is simulated correctly. But, when the simulation arrives to the multiplication code, it stops and generates the following error:

# Fatal error in Process line__289 at pixelclassification_wrapper.vhd line 320
#
# HDL call sequence:
# Stopped at pixelclassification_wrapper.vhd 320 Process line__289

The line 320 of this code is the line I have the multiplication presented previously. If instead of having a multiplication I assign a value to 'thvar' everything will work correctly, so there is some problem when I am multiplying both ufixed values, but I really don't know what is it. Could anyone have an idea of what is happening?

##### Super Moderator
Staff member
I'm not sure if this is the problem, but the bit widths don't match.

Code VHDL - [expand]1
2
3
variable maxim : ufixed(18 downto 0);       -- 19 bits \ 28-bits
variable thresh_low : ufixed(0 downto -8);  --  9 bits /
variable thvar : ufixed(18 downto -8);      -- 27 bits

Maybe the thresh_low should be (-1 downto -8) if it's only a fractional value, otherwise by using (0 downto -8) it could be as large as 1.990234375 (i.e. 1 + 1/2 + ... + 1/256).

normantg

Points: 2