我将代码分为三部分编写。第一部分包含加法、减法和求反等函数。第二部分是蝶形结构。第三部分是fft4。
我发现蝴蝶部分有一些错误,请帮忙解决。
程序如下。在 fft_pkg 中,我使用了否定函数,而不是乘以 -j。
我避免了乘以 1 和 -j 并使用加法和求反函数。
-- Design Name:
-- Module Name: butterfly - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
-------------------------------------------------------------
library ieee;
use IEEE.STD_LOGIC_1164.ALL;
library work;
use work.fft_pkg.all;
entity butterfly is
port (
s1,s2 : in complex;
stage : in std_logic; -- inputs
-- w : in complex -- phase factor
g1,g2 : out complex -- outputs
);
end butterfly;
architecture Behavioral of butterfly is
begin
--butterfly equations.
if ( stage ='0') then
g1 <= add(s1,s2);
g2 <= sub(s1,s2);
elsif (stage ='1') then
g1 <= add(s1,negate(s2));
g2 <= sub(s1,negate(s2));
end if;
end Behavioral;
--butterfly structure(in it instead of multiplication negate func is used)
library ieee;
use IEEE.STD_LOGIC_1164.ALL;
library work;
use work.fft_pkg.all;
entity butterfly is
port (
s1,s2 : in complex;
stage : in std_logic; -- inputs
-- w : in complex; -- phase factor
g1,g2 :out complex -- outputs
);
end butterfly;
architecture Behavioral of butterfly is
begin
--butterfly equations.
if ( stage ='0') then
g1 <= add(s1,s2);
g2 <= sub(s1,s2);
elsif (stage ='1') then
g1 <= add(s1,negate(s2));
g2 <= sub(s1,negate(s2));
end if;
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
library work;
use work.fft_pkg.all;
entity fft4 is
port (
s: in comp_array;
y : out comp_array
);
end fft4;
architecture rtl of fft4 is
component butterfly is
port (
s1,s2 : in complex; -- inputs
-- w : in complex; -- phase factor
g1,g2 : out complex -- outputs
);
end component;
signal g1,g2: comp_array; -- :=(others=>(0000,0000));
-- signal w:comp_array2 :=(("0000","0001"),("0000","1111"));
begin
--first stage of butterfly
bf11 : butterfly port map(s(0),s(2),'0',g1(0),g1(1));
bf12 : butterfly port map(s(1),s(3),'0',g1(2),g1(3));
--second stage of butterfly's.
bf21 : butterfly port map(g1(0),g1(2),'0',g2(0),g2(2));
bf22 : butterfly port map(g1(1),g1(3),'1',g2(1),g2(3));
end rtl;
错误是
错误:HDLCompiler:806 - “C:\Users\RObin ftfinal utterfly.vhd”第 36 行:“if”附近的语法错误。
错误:HDLCompiler:806 - “C:\Users\RObin ftfinal utterfly.vhd”第 39 行:“elsif”附近的语法错误。
错误:HDLCompiler:806 - “C:\Users\RObin ftfinal utterfly.vhd”第 42 行:“if”附近的语法错误。
错误:HDLCompiler:854 - “C:\Users\RObin ftfinal utterfly.vhd”第 31 行:由于之前的错误,单元被忽略。
尝试将 if 语句放入流程中:
architecture behavioral of butterfly is
begin
--butterfly equations.
process (s1, s2)
begin
if ( stage ='0') then
g1 <= add(s1,s2);
g2 <= sub(s1,s2);
elsif (stage ='1') then
g1 <= add(s1,negate(s2));
g2 <= sub(s1,negate(s2));
end if;
end process;
end behavioral;
如果没有包 fft_pkg 或编写包,则无法验证您的代码,这似乎需要确定类型
complex
是什么。
请注意,虽然 Nicolas 还评论说您可以使用并发条件赋值语句,但所有并发语句都有等效的过程语句或过程和块语句,这就是 VHDL 在详细阐述后进行模拟和综合的方式。
您还可以注释掉或删除实体蝴蝶及其架构行为的两个副本之一。如果您需要具有相同接口的两种不同表示形式,您可以更改连续不同架构的架构名称。
默认情况下,将使用最后分析的一个。再次分析相同的命名实体和体系结构具有替换第一次出现的效果,同时仍然要求两者都是有效的 VHDL。
我可以询问您的 4 点 FFT 代码吗 我有一个问题 这是 4 点 FFT 和基数 2 的代码吗? 谢谢你