1

このDAC とインターフェイスして正弦波を生成するコードを書いています。DAC コントローラーと一緒に、問題なく値を生成するサイン LUT があります。コントローラは CS を Low にし、16 ビット整数をビットごとに供給し、16 カウント後に CS を High にパルスします。パルスと同様に、sin LUT にイネーブル パルスを送信して、もう 1 つの数値をカウントアップします。出力にスパイクが発生しているため、このコードはうまく機能していないようです。これは、CS が高いはずのクロックが CS を低い値として読み取るため (図 1)、DAC が 17 ビットで読み取る (つまり、現在の数値の MSB を前の数値の LSB として読み取る) ためです。スパイク (図 2)。

このタイミングの問題が発生するリスクを最小限に抑えるために、このコードをより適切に編成するにはどうすればよいでしょうか?

module DAC_Control(
  input [15:0]data_in,
  input counter_enable,
  input clk,
  input rst,
  output data_out,
  output reg cs,
  output reg enable
  );

//bit counter
  reg [3:0] bit_counter;

//to help with shifting
  reg [15:0] shifter;

//shifter
  always @(posedge (clk)) begin
    if (rst) begin
      bit_counter <= 4'b0;
      shifter <= 0;
      end
    else if (counter_enable == 1) begin
        shifter <= data_in;
        bit_counter <= 4'b0;
    end
    else begin
      shifter <= shifter << 1; // shifting
      bit_counter <= bit_counter + 1'b1; // counter
    end
  end

  reg cs_hold;

  always @(posedge (clk)) begin
    if (rst) begin
      enable <= 1'b0;
      cs <= 1'b1;
      end
    else if (bit_counter == 4'b1110) begin
      enable <= 1'b1;
      cs <= 1'b0;
    end
    else if (bit_counter == 4'b1111) begin
      enable <= 1'b0;
      cs <= 1'b1;
    end
    else if (cs_hold == 1) begin
      enable <= 1'b0;
      cs <= 1'b1;
    end
    else begin
      enable <= 1'b0; // generate enable signals
      cs <= 1'b0;
    end
  end


  assign data_out = shifter[15];

endmodule

図 1. 黄色は DIN、青色は CS、緑色はクロック

図1

図 2. DAC の出力

図2

4

2 に答える 2

2

DAC は立ち上がりエッジを使用してデータをサンプリングしています。

http://www.analog.com/media/en/technical-documentation/data-sheets/AD5541A.pdf

Serial Data Input. This device accepts 16-bit words. Data is clocked into the serial input register on the rising edge of SCLK.  

clk の立ち下がりエッジで data_out と cs を生成してみてください。

于 2016-08-17T19:28:11.357 に答える
2

お使いの FPGA がどのベンダーのものかはわかりませんが、ほとんどの場合、クロックとデータの関係を定義できるタイミング制約があります。彼らは仮想時計のアイデアを使用しています。外部クロックがあり、クロック間の差分が何であるかを言うようになると考えてください。クロックが FPGA から直接生成され、外部ソースからではなく、いくつかの CLK 値を 0 に設定できると思います。

これらの種類の制約を設定することで、データ出力が clk に対して相対的に移動し、「一貫して制御される」ようになります。

+----------+                +--------+
| FPGA     |----Data_out--->|  DAC   |
+----------+                +--------+
     CLKs /\               CLKd /\
          |                      |
          +-------sys_clk--------+

これは、SDC を使用して出力の時間を計るアルテラ デバイスのソリューションです。

#specify the maximum external clock delay to the FPGA
set CLKs_max 0.200
#specify the minimum external clock delay to the FPGA
set CLKs_min 0.100
#specify the maximum external clock delay to the external device
set CLKd_max 0.200
#specify the minimum external clock delay to the external device
set CLKd_min 0.100
#specify the maximum setup time of the external device
set tSU 0.125
#specify the minimum setup time of the external device
set tH 0.100
#specify the maximum board delay
set BD_max 0.180
#specify the minimum board delay
set BD_min 0.120
#create a clock 10ns
create_clock -period 10 -name sys_clk [get_ports sys_clk]
#create the associated virtual input clock
create_clock -period 10 -name virt_sys_clk
#create the output maximum delay for the data output from the FPGA that
#accounts for all delays specified
set_output_delay -clock virt_sys_clk \
    -max [expr $CLKs_max + $BD_max + $tSU - $CLKd_min] \
    [get_ports {data_out[*]}]
#create the output minimum delay for the data output from the FPGA that
#accounts for all delays specified
set_output_delay -clock virt_sys_clk \
    -min [expr $CLKs_min + $BD_min - $tH - $CLKd_max] \
    [get_ports {data_out[*]}]

あるいは、データとクロックの関係を制約で制御できない場合は、提案するのも安っぽく思えます (もし本当なら、私が彼らから離れられるようにベンダーに教えてください)。次の提案に従って状況を改善できます。前の答え、posedge を negedge に変更します。出力が希望どおりに制限されない可能性があるため、これはビルドごとに柔軟になる可能性があることに注意してください。

于 2016-08-18T02:32:16.700 に答える