什么';我的VHDL正弦函数有什么问题吗?

什么';我的VHDL正弦函数有什么问题吗?,vhdl,trigonometry,Vhdl,Trigonometry,我尝试了所有的方法,最后得出结论,接下来的两行使输出始终为零,我不明白为什么。它应该是一个带有正弦函数的输出。(计数是每个周期256个样本。n是位数。)以下格式是否有效 library IEEE; use IEEE.MATH_REAL.ALL; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.NUMERIC_STD.ALL; entity SineGen is Port (clock

我尝试了所有的方法,最后得出结论,接下来的两行使输出始终为零,我不明白为什么。它应该是一个带有正弦函数的输出。(计数是每个周期256个样本。n是位数。)以下格式是否有效

library IEEE;
use IEEE.MATH_REAL.ALL;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.NUMERIC_STD.ALL;

entity SineGen is
    Port (clock             : in  std_logic;
          dac_ab_vpp        : in  integer range 0 to 4095;
          dac_cd_vpp        : in  integer range 0 to 4095;
          sine_dac_ab       : out std_logic_vector(11 downto 0);
          sine_dac_cd       : out std_logic_vector(11 downto 0));
end SineGen;

architecture Behavioral of SineGen is

subtype slv is std_logic_vector(11 downto 0);


begin

        process(clock)
            variable count       : integer range 0 to 255  := 0;
            variable temp_dac_ab : integer range 0 to 4095 := 0;
            variable temp_dac_cd : integer range 0 to 4095 := 0;

        begin   
            if rising_edge(clock) then
--A*sin(2PI/2^n*计数)
temp_dac_ab:=dac_ab_vpp*整数(四舍五入(sin)(实数)(计数*整数)(数学2_π/实数(256щщ)));
temp_dac_cd:=dac_cd_vpp*整数(四舍五入(sin)实数(count*整数)(math_2_pi/real(256щщ)));
如果计数小于256,则
计数:=计数+1;
其他的
计数:=0;
如果结束;

sine_dac_ab我对我的VHDL真的很生疏,但我想你想要这个:

                -- A*sin (2PI/2^n * count)
                temp_dac_ab := dac_ab_vpp * integer(round(sin(real(count * integer(math_2_pi/real(256))))));
                temp_dac_cd := dac_cd_vpp * integer(round(sin(real(count * integer(math_2_pi/real(256))))));

                if count < 256 then 
                    count := count + 1;
                else
                    count := 0;
                end if;

                sine_dac_ab <= conv_std_logic_vector(temp_dac_ab, slv'length); 
                sine_dac_cd <= conv_std_logic_vector(temp_dac_cd, slv'length); 

            end if;


        end process;
end Behavioral;

(你不想对来自sin的浮点进行取整/施放,直到你将它与dac_ab_vpp
/
dac_cd_vpp
)相乘后才能进行取整/施放。

除了@brianreavis指出的,你不想将分数
math_2_pi/real(256)
转换为整数,因为分数总是0。因此:

temp_dac_ab := integer(round(dac_ab_vpp * sin(real(count * integer(math_2_pi/real(256))))));
temp_dac_cd := integer(round(dac_cd_vpp * sin(real(count * integer(math_2_pi/real(256))))));

与输出为0无关,计数器中也有一个错误(
count
):指定为0到255范围内的整数将始终小于256。因此,当计数器为255时,计数器也将尝试递增,这将导致运行时错误。。。但是,您的代码片段是不正确的,因为它将sin(count)作为类型转换
integer(val小于1.0)
始终生成零。。。
temp_dac_ab := integer(round(dac_ab_vpp * sin(real(count) * math_2_pi/real(256))));
temp_dac_cd := integer(round(dac_cd_vpp * sin(real(count) * math_2_pi/real(256))));