使用verilog生成正弦波

时间:2019-11-08 09:44:19

标签: verilog system-verilog

我必须使用Verilog生成正弦波,在Google上,我发现了与之相关的东西,但不知何故。enter link description here 因此,有人可以向我解释这段代码背后的逻辑吗?

assign sine = sine_r + {cos_r[7], cos_r[7], cos_r[7], cos_r[7:3]};
assign cos = cos_r - {sine[7], sine[7], sine[7], sine[7:3]};

这里是MCVE

module sine_cos(clk, reset, en, sine, cos);
   input clk, reset, en;
   output [7:0] sine,cos;
   reg [7:0] sine_r, cos_r;
   assign      sine = sine_r + {cos_r[7], cos_r[7], cos_r[7], cos_r[7:3]};
   assign      cos  = cos_r - {sine[7], sine[7], sine[7], sine[7:3]};
   always@(posedge clk or negedge reset)
     begin
         if (!reset) begin
             sine_r <= 0;
             cos_r <= 120;
         end else begin
             if (en) begin
                 sine_r <= sine;
                 cos_r <= cos;
             end
         end
     end
endmodule // sine_cos

module M;

  reg clk, reset, en;
  wire [7:0] sine,cos;

  sine_cos sc (clk, reset, en, sine, cos);

  initial
    begin
      $dumpfile("dump.vcd"); $dumpvars;
      en = 1'b1;
      clk = 1'b0;
      reset = 1'b0;
      #1 reset = 1'b1;
      repeat (100)
        #1 clk = ~clk;
    end

endmodule

https://www.edaplayground.com/x/4YRR

0 个答案:

没有答案