正弦波の生成

pp.270-273

1象限ぶんだけのデータを排列として持っていてそれを順番に読み出す。ボード上の48 MHz発信器からPLLで36 kHzを合成し、それをモジュロ360のカウンターでカウントして順番にデータを読み出す。結果、100 Hzの正弦波が得られる。それをR-2R式DACでアナログに変換してオシロで見る。

これをサブvhdとして作っておく。

-- ライブラリーは何も使わない。

entity sine_calculator_sub is
    port(
        phase: in natural range 0 to 359;
        sine: out natural range 0 to 255
    );
end entity;

architecture rtl of sine_calculator_sub is
    type integer_matrix is array (0 to 31) of natural range 0 to 127;
    
    constant ROM: integer_matrix := (
          3,  9, 16, 22, 28, 34, 40, 46,
         51, 57, 63, 68, 73, 78, 83, 88,
         92, 96,100,104,107,111,113,116,
        118,121,122,124,125,126,127,127
    );
begin
    with phase select
        sine <=
            0 + 128                         when 0,
            ROM((32*phase)/90) + 128        when 1 to  89,
            
            ROM(31) + 128                   when 90,
            ROM((32*(180-phase))/90) + 128  when 91 to 179,
            
            0 + 128                         when 180,
            -ROM((32*(phase-180))/90) + 128 when 181 to 269,
            
            -ROM(31) + 128                  when 270,
            -ROM((32*(360-phase))/90) + 128 when 271 to 359,
            
            0 + 128                         when others;
end architecture;

トップ回路
f:id:ti-nspire:20210416104554p:plain:w500
f:id:ti-nspire:20210416104743p:plain:w500
f:id:ti-nspire:20210416115257j:plain:w500