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.

multiplying unsigned number and sfixed number

Status
Not open for further replies.

214

Junior Member level 2
Joined
Feb 22, 2016
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
247
how can i multiply an unsigned number with a sfixed number (for eg 0.703125) ??

should i convert the unsigned into sfixed type and carry on with multiplication ?

i want the result of the multiplication back in unsigned format..
thanks in advance
 

how can i multiply an unsigned number with a sfixed number (for eg 0.703125) ??

should i convert the unsigned into sfixed type and carry on with multiplication ?
Yes

i want the result of the multiplication back in unsigned format..
Then you need to convert it back to unsigned. The fixed point package that I assume you must be using has conversion functions to perform these operations.

Kevin Jennings
 

Why would you want the signed result back as an unsigned number? Are you deliberately forcing wrap around?
 

Multiplication using sfixed numbers in vhdl

I am trying to multiply an unsigned number with sfixed number (0.703125). following are the code and errors:


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
USE ieee.numeric_std.all;
 
entity tryproduct is
end tryproduct;
 
architecture Behavioral of tryproduct is        (Line 11)
signal a : sfixed(0 downto -6);
signal k : sfixed(8 downto -6);
SIGNAL temp1: UNSIGNED (8 downto 0) := "101001001" ;
 
begin
 
a <= to_sfixed (0.703125,a);
k <= to_sfixed(temp1) * a;       (Line 19)
end Behavioral;



Errors:
Code:
ERROR:HDLCompiler:432 - "G:/vhdlcodes/producttry/tryproduct.vhd" Line 19: Formal <arg> has no actual or default value.
ERROR:HDLCompiler:841 - "G:/vhdlcodes/producttry/tryproduct.vhd" Line 19: Expecting type integer for <temp1>.
ERROR:HDLCompiler:9 - "G:/vhdlcodes/producttry/tryproduct.vhd" Line 19: Found 0 definitions for operator "*".
ERROR:HDLCompiler:854 - "G:/vhdlcodes/producttry/tryproduct.vhd" Line 11: Unit <behavioral> ignored due to previous errors.


thanks in advance
 
Last edited by a moderator:

Re: Multiplication using sfixed numbers in vhdl

to_sfixed is only defined for the following:
Code:
  function to_sfixed (
    arg                  : STD_ULOGIC_VECTOR;  -- shifted vector
    constant left_index  : INTEGER;
    constant right_index : INTEGER)
Code:
  function to_sfixed (
    arg                     : INTEGER;  -- integer
    constant left_index     : INTEGER;  -- left index (high index)
    constant right_index    : INTEGER                   := 0;  -- right index
    constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
    constant round_style    : fixed_round_style_type    := fixed_round_style)
Code:
  function to_sfixed (
    arg                     : REAL;     -- real
    constant left_index     : INTEGER;  -- left index (high index)
    constant right_index    : INTEGER;  -- right index
    constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
    constant round_style    : fixed_round_style_type    := fixed_round_style;
    constant guard_bits     : NATURAL                   := fixed_guard_bits)  -- # of guard bits
Code:
  function to_sfixed (
    arg                     : UNRESOLVED_SIGNED;               -- signed
    constant left_index     : INTEGER;  -- left index (high index)
    constant right_index    : INTEGER                   := 0;  -- right index
    constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
    constant round_style    : fixed_round_style_type    := fixed_round_style)
Code:
  function to_sfixed (
    arg : UNRESOLVED_SIGNED)            -- signed
Code:
  function to_sfixed (arg : UNRESOLVED_ufixed)
Code:
  function to_sfixed (
    arg      : STD_ULOGIC_VECTOR;       -- shifted vector
    size_res : UNRESOLVED_sfixed)       -- for size only
Code:
  function to_sfixed (
    arg                     : INTEGER;            -- integer
    size_res                : UNRESOLVED_sfixed;  -- for size only
    constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
    constant round_style    : fixed_round_style_type    := fixed_round_style)
Code:
  function to_sfixed (
    arg                     : REAL;     -- real
    size_res                : UNRESOLVED_sfixed;  -- for size only
    constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
    constant round_style    : fixed_round_style_type    := fixed_round_style;
    constant guard_bits     : NATURAL                   := fixed_guard_bits)  -- # of guard bits
Code:
  function to_sfixed (
    arg                     : UNRESOLVED_SIGNED;  -- signed
    size_res                : UNRESOLVED_sfixed;  -- for size only
    constant overflow_style : fixed_overflow_style_type := fixed_overflow_style;
    constant round_style    : fixed_round_style_type    := fixed_round_style)
None of which accepts an UNSIGNED as the arg value.
 

It's unclear why you use sfixed instead of ufixed for the positive factor and perform an unsigned multiply. But if you want to multiply signed *unsigned, you have to convert the unsigned number to signed before, extending it by one bit. E.g.
Code:
temp2 <= SIGNED('0' & temp1)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top