Forum Discussion
Altera_Forum
Honored Contributor
18 years agoHello,
--- Quote Start --- Make sure results(63 downto 48) are either all F's or all 0's. If not, you have a problem. --- Quote End --- that's true, but I guess, the said "artifacts" are rather limit cycles visible at the output cause the input/output signal is scaled too low. Without additional fractional bits in internal processing, such quantization effects can't be avoided. Also rounding rather than truncation at the output is necessary, when toggling of least significant bits respectively sign is unwanted. When discarding most significant bits, as with the said bit 48 to 63, saturation logic is a must, unless you can't be absolutely sure, that no overflow can occur. A good method, to keep the code readable anyway is to use a function for saturation and truncation of multiply output, here with configurable shift for scaling purposes. With the normalized 16.16 format, that shift factor should be 16:FUNCTION MUL_ASL (X1,X2: SIGNED; N: INTEGER) RETURN SIGNED IS
VARIABLE P:SIGNED(X1'length+X2'length-1 downto 0);
BEGIN
P:=X1*X2;
IF P(P'left-1 downto P'left-N) /= 0 AND P>=0 THEN
P:= (others => '1');
P(P'left-N):='0';
ELSIF P(P'left-1 downto P'left-N) /= -1 AND P<0 THEN
P:= (others => '0');
P(P'left-N):='1';
END IF;
-- Result length equal to X2
RETURN P(P'left-N downto X1'length-N);
END; Regards, Frank