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.

vhdl logic_vector to signed int conversion

Status
Not open for further replies.

konradb

Newbie level 6
Joined
May 28, 2009
Messages
13
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,281
Activity points
1,386
vhdl logic_vector

I wish to take a 16-bit logic vector in (from an ADC). This is an AC-biased sine wave connected to an ADC centered around the mid point of the ADC (i.e. 32767).

How do I change this to a signed integer that i then use to do a multiply and subsequently output as a signed logic vector?

I have some code snipets below,

------------------

Library IEEE;
Use IEEE.Std_Logic_1164.all;
use IEEE.Std_Logic_arith.all;
use IEEE.Std_Logic_signed.all;

DAT_I : in std_logic_vector(15 downto 0);
DAT_O : out std_logic_vector(15 downto 0);

signal A_int: integer range -2147483647 to 2147483647;
signal result_int: integer range -2147483647 to 2147483647;


A_int <= conv_integer(DAT_I);

Result_int <= (A_int-32767) * coef_int; -- convert A to signed 16-bit and multiply

DAT_O(15 downto 0) <= conv_std_logic_vector(result_int,16);

------------------

does the above give me a signed DAT_O?

Do I need to replace the following?

A_int <= conv_integer(unsigned(DAT_I));
 

signed int range

- The conversion from "offset binary" to two's complement is done by inverting the MSB (respectively performing XOR x"8000") rather than substracting -32767. You can check, that the latter produces an overflow for full scale input of x"FFFF".

- The multiply result has 16 + coef_int'length bits, so you can't use it for an 16 bit output without causing truncation. You should rather select 16 bits from the left. If coef_int is a signed signal, you get two sign bits in result. You must use saturation logic to scale the result to the full signed range.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top