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.

Conversion from sfixed to ufixed (gives error)

Status
Not open for further replies.

jdh_1984

Member level 2
Joined
Aug 11, 2010
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Norway
Activity points
1,854
Hi
I am trying to convert a signal from sfixed to ufixed, using the syntax given in the fixed package documentation:

-- Conversion from sfixed to ufixed (performs an "abs" function)
function to_ufixed (
arg : UNRESOLVED_sfixed)
return UNRESOLVED_ufixed;

My code:
SIGNAL result : ufixed(8 DOWNTO -4);
SIGNAL position : sfixed(8 DOWNTO -4);
:
:
result<=to_ufixed(position);

In quartus 9.1 the following error message is given:
Error (10476): VHDL error at hjulenkodernxt.vhd(96): type of identifier "position" does not agree with its usage as "UNSIGNED" type

Have I done anything wrong? Is it a alternative way to do this conversion?
 

I am not familiar with VHDL,from verilog view,in the "position",signed number would not be recognized.
And if you want to implement "abs" function ,here show you an example in verilog(16bit):
assign abs_num_diff = num_diff[15]?
(~num_diff[15:0] + 1'b1) : num_diff[15:0];
 

no problem for me.
Are you sure you havent got a local variable called result overriding the result you posted?
 

no problem for me.
Are you sure you havent got a local variable called result overriding the result you posted?

Hi

Just for testing the conversion I removed all other code, and only used this:

Library ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_signed.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;

ENTITY HjulEnkoderNxt IS
PORT (TACHO0,TACHO1: IN STD_LOGIC;
Clock : IN STD_LOGIC;
distanse :OUT ufixed(8 downto -4));
END HjulEnkoderNxt;

ARCHITECTURE Behavior OF HjulEnkoderNxt IS
SIGNAL scalingfactor : sfixed(2 downto -4);
SIGNAL position : sfixed(8 DOWNTO -4);
SIGNAL pulsesSfixed : sfixed(5 DOWNTO 0);
SIGNAL result : ufixed(8 DOWNTO -4);

BEGIN
scalingfactor<=to_sfixed(1.0,scalingfactor);
pulsesSfixed<=to_sfixed(2.0,pulsesSfixed);
position<=Scalingfactor*pulsesSfixed;
result<=to_ufixed(position);--Conversion from sfixed to ufixed
END Behavior;

I still get the error message:
Error (10476): VHDL error at hjulenkodernxt.vhd(95): type of identifier "position" does not agree with its usage as "UNSIGNED" type
 

I copied and pasted your code - no problems.
Your error points to line 95, which is not in your cut down code. So please post the full code.

Also - remove ieee.std_logic_signed from your code. You dont need it because you are using numeric_std.
 

I copied and pasted your code - no problems.
Your error points to line 95, which is not in your cut down code. So please post the full code.

Also - remove ieee.std_logic_signed from your code. You dont need it because you are using numeric_std.

My code is:

Library ieee;
USE ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;

ENTITY HjulEnkoderNxt IS
PORT (TACHO0,TACHO1: IN STD_LOGIC;
Clock : IN STD_LOGIC;
distanse :OUT ufixed(8 downto -4));

END HjulEnkoderNxt;

ARCHITECTURE Behavior OF HjulEnkoderNxt IS
SIGNAL scalingfactor : sfixed(2 downto -4);
SIGNAL TACHO0prev,TACHO1prev : STD_LOGIC;
SIGNAL pulses : SIGNED(5 DOWNTO 0);
SIGNAL position : sfixed(8 DOWNTO -4);
SIGNAL pulsesSfixed : sfixed(5 DOWNTO 0);
SIGNAL result : ufixed(8 DOWNTO -4);



BEGIN
scalingfactor<=to_sfixed(1.0,scalingfactor);--Setter verdien til skaleringsfaktoren.
PROCESS(TACHO0,TACHO1,Clock,pulses)
BEGIN
IF rising_edge(Clock) THEN

IF (TACHO0='0' AND TACHO1='0') THEN
IF (TACHO0prev='1' AND TACHO1prev='0') THEN
TACHO0prev<='0';
TACHO1prev<='0';
ELSIF (TACHO0prev='0' AND TACHO1prev='1') THEN
TACHO0prev<='0';
TACHO1prev<='0';
ELSIF (TACHO0prev='0' AND TACHO1prev='0') THEN
TACHO0prev<='0';
TACHO1prev<='0';
END IF;

ELSIF(TACHO0='0' AND TACHO1='1') THEN
IF (TACHO0prev='0' AND TACHO1prev='1') THEN
TACHO0prev<='0';
TACHO1prev<='1';
ELSIF(TACHO0prev='0' AND TACHO1prev='0') THEN
pulses<=pulses-1;
TACHO0prev<='0';
TACHO1prev<='1';
ELSIF(TACHO0prev='0' AND TACHO1prev='0') THEN
pulses<=pulses-1;
TACHO0prev<='0';
TACHO1prev<='1';
ELSIF(TACHO0prev='1' AND TACHO1prev='1') THEN
TACHO0prev<='0';
TACHO1prev<='1';
END IF;
END IF;

IF (TACHO0='1' AND TACHO1='1') THEN
IF (TACHO0prev='1' AND TACHO1prev='1') THEN
TACHO0prev<='1';
TACHO1prev<='1';
ELSIF(TACHO0prev='1' AND TACHO1prev='0') THEN
pulses<=pulses+1;
TACHO0prev<='1';
TACHO1prev<='1';
ELSIF(TACHO0prev='0' AND TACHO1prev='1') THEN
pulses<=pulses-1;
TACHO0prev<='1';
TACHO1prev<='1';
ELSIF(TACHO0prev='1' AND TACHO1prev='0') THEN
TACHO0prev<='1';
TACHO1prev<='1';
END IF;
END IF;

IF (TACHO0='1' AND TACHO1='0') THEN
IF (TACHO0prev='1' AND TACHO1prev='0') THEN
TACHO0prev<='1';
TACHO1prev<='0';
ELSIF (TACHO0prev='0' AND TACHO1prev='0') THEN
pulses<=pulses+1;
TACHO0prev<='1';
TACHO1prev<='0';
ELSIF (TACHO0prev='1' AND TACHO1prev='1') THEN
TACHO0prev<='1';
TACHO1prev<='0';
END IF;
END IF;

pulsesSfixed<=to_sfixed(pulses,5,0);
position<=Scalingfactor*pulsesSfixed;
distanse<=to_ufixed(position);--Conversion from sfixed to ufixed (Line 94)

END IF;

END PROCESS;

END Behavior;

Quartus message: Error (10476): VHDL error at hjulenkodernxt.vhd(94): type of identifier "position" does not agree with its usage as "UNSIGNED" type
 

I can only think that you have modified or have an incomplete version of the fixed package. there should be 2 to_ufixed functions, one using sfixed and using unsigned. it looks like it can only see the latter ( protection could be an old version of the library). alternatively just do abs yourself and just type covert to a ufixed.
 

I can only think that you have modified or have an incomplete version of the fixed package. there should be 2 to_ufixed functions, one using sfixed and using unsigned. it looks like it can only see the latter ( protection could be an old version of the library). alternatively just do abs yourself and just type covert to a ufixed.

I downloaded the package from: **broken link removed** so I think it should be updated.
Could you post an example of how to use the abs function and type convert? I have tried this, but I do not get it working.
I used this abs syntax:
-- Absolute value, 2's complement
-- abs sfixed(a downto b) = sfixed(a+1 downto b)
function "abs" (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed;
 

you will need a temporary signal or variable.

signal a : sfixed(position'high + 1 downto position'low);

a <= abs(position);
distanse <= ufixed(a);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top