vhdl - 我的 VHDL 正弦函数生成器出了什么问题?

标签 vhdl trigonometry

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

我尝试了一切,归结为接下来的两行使输出始终为零,我不明白为什么。它应该是具有正弦函数的输出。 (count 是每个周期 256 个样本。n 是位数。)以下格式是否有效?

                -- 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;

最佳答案

除了 @brianreavis 所指出的之外,您不想将分数 math_2_pi/real(256) 转换为整数,因为它始终为 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))));

关于vhdl - 我的 VHDL 正弦函数生成器出了什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6209727/

相关文章:

C:通过大量使用 sin() 来提高函数的性能

python - 产生颤音正弦波

Python 三角函数返回意外值

vhdl - 将 Chisel 转换为 Vhdl 和 SystemC?

VHDL 如何将 std_logic_vector 与 std_logic 信号一起添加?

vhdl - 在 vhdl 中将 sfixed 转换为 std_logic_vector 的正确方法是什么?

javascript - 如何创建始终打开到固定点的圆弧

java - 如何使用正弦/余弦波返回振荡数

syntax - 如何在不循环的情况下将信号切片分配给单个标准逻辑?

timestamp - 获取当前时间戳VHDL