multiplication real with std_logic vector

Guest #3720118
Rate this post
• ▲ useful
▼ not useful
Hi everyone!

I want to multiply a std_logic_vector value (14 bits) with a real 
number.
But there is a problem of size of data I think. The compiler show me 
these errors: "operator argument type mismatch"

Below the part of code I wrote:
1
data <= data * std_logic_vector(to_signed(integer(1.5*8192.0),data'length))
2
               when VREF_ADC_COM_value = 0.6 else
3
  
4
        data * std_logic_vector(to_signed(integer(1.2*8192.0),data'length))
5
               when VREF_ADC_COM_value = 0.75 else
6
  
7
        data;
How can I fix it ?

Thank you!
Guest #3720214
Rate this post
• ▲ useful
▼ not useful
Lothar Miller wrote:
> BTW: What data type is data?

data is a std_logic_vector(13 downto 0)

So, do I have to create an other signal "data unsigned" to use in the 
multiplication?

Like this:
1
signal data          : std_logic_vector(13 downto 0);
2
signal data_unsigned : unsigned(13 downto 0);
3

4
data_unsigned <= data_unsigned * unsigned(integer(1.5*8192.0),data'length))...
5

6
data <= std_logic_vector(data_unsigned);

I'm a little bit lost with all these types...
Moderator (Company: Titel) #3720294
Rate this post
• ▲ useful
▼ not useful
sebgimi wrote:
> I'm a little bit lost with all these types...
Have a look there (try Google translator,its German):
http://www.lothar-miller.de/s9y/categories/16-Numeric_Std
And then remind: in the numeric_std the multiplication is only defined 
for signed and unsigned vectors.

Then your calculation must look this way
1
 data <= std_logic_vector( signed(data) * to_signed(integer(1.5*8192.0),data'length) );
But why not definig data itself as a signed vector?
The result of a vector multiplication is twice the with of a single 
vector (or the sum of the bits of both).

I would do the calculation in integer. Then you don't have to hassle 
aruond with vector lengths:
1
 data <= std_logic_vector(to_signed(to_integer(signed(data)) * integer(1.5*8192.0), data'length));
Guest #3720423
Rate this post
• ▲ useful
▼ not useful
Lothar Miller wrote:
> But why not definig data itself as a signed vector?
> The result of a vector multiplication is twice the with of a single
> vector (or the sum of the bits of both).
>
> I would do the calculation in integer. Then you don't have to hassle
> aruond with vector lengths: data <=
> std_logic_vector(to_signed(to_integer(signed(data)) *
> integer(1.5*8192.0), data'length));

So, if I understand right, I have to declare data as a signed vector of 
28 bits and write the line of calculation above ?

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.