簡易信號發生器的設計


     晚上寫了一個簡易的信號發生器的程序,上機驗證成功,通過了 Signal Tap II驗證。

     Mif 文件的數據是通過  mif_maker2010 這個軟件生成的,它的使用教程通過這個鏈接可以找到:https://www.cnblogs.com/qidaiymm/p/6007704.html

     硬件環境為:DE1-SOC

     軟件環境為:Quartus II_15.0

     可以通過四個撥碼開關來進行波形及頻率的切換,那個ROM-1 PORT的使用我就不介紹了

     實現的效果為:

     

    

  

代碼如下:

模塊1:

module control_freq(
  clk,
  rst_n,
  key_in,
  fout
);
input clk;
input rst_n;
input[1:0] key_in;
output fout;
reg[3:0] cnt;
reg clk_2,clk_4;
reg fout;
always@(posedge clk or negedge rst_n) 
  if(!rst_n)
    begin
      cnt<=4'd0;
  clk_2<=0;
  end
  else if(cnt==4'd1)
    begin
      cnt<=4'd0;
  clk_2<=~clk_2;
  end
  else
    cnt<=cnt+1'b1;
always@(posedge clk_2 or negedge rst_n)
  if(!rst_n)
    clk_4<=0;
  else
    clk_4<=~clk_4;
always@(posedge clk or negedge rst_n)
 begin
   if(!rst_n)
   fout<=0;
 else
   begin
    case(key_in)
      0:fout<=clk_2;
    1:fout<=clk_4;
    default:;
      endcase
     end
 end
 
endmodule
 
模塊2:
module sw_control(
  clk,
  rst_n,
  data_out,
  sw
);
input clk;
input rst_n;
input[1:0] sw;
output[7:0] data_out;   //數據輸出
reg[7:0] address;
wire[7:0] q1,q2,q3;       //地址寄存器
reg[7:0] data_out;
always@(posedge clk or negedge rst_n)
  if(!rst_n)
    address <= 8'd0;
  else if(address==255)
    address <=8'd0;
  else
    address <= address +1'b1;
 
san_jiao_xing san_jiao_xing(
 .address(address),
 .clock(clk),
 .q(q1)
);
sin sin(
   .address(address),
 .clock(clk),
 .q(q2)
);
fang_bo fang_bo(
   .address(address),
 .clock(clk),
 .q(q3)  
);
always@(posedge clk or negedge rst_n)
  begin
    if(!rst_n)
      data_out<=8'd0;
    else
      begin
        case(sw)
      0:data_out<=q1;
    1:data_out<=q2;
    2:data_out<=q3;
    default:data_out<=8'd0;
        endcase
      end
  end
endmodule
 
//頂層模塊
module AD_pulse_signal_generator(
  clk,
  rst_n,
  key_in,
  sw,
  data_out
);
input clk;
input rst_n;
input[1:0] key_in;
input[1:0] sw;
output[7:0] data_out;
control_freq u1(
  .clk(clk),
  .rst_n(rst_n),
  .key_in(key_in),
  .fout(fout)
);
sw_control u2(
  .clk(fout),
  .rst_n(rst_n),
  .data_out(data_out),
  .sw(sw)
);
endmodule
 
歡迎各位朋友批評指正~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM