-
我设计的扫频信号发生器,是直接利用FPGA的分频器+rom表设计的,我定义了4个按键,前3个控制频率控制字,我想怎么输入一定的值,是不是只能表示高低电平呢?
-
module sine(clock,swept_clk,select,data,dout,da_clk,da_mode);input clock; //系统时钟input swept_clk; //扫描时钟input select; //功能选择,波形产生&扫频input[11:0]data; //频率控制output [9:0]dout; //数据输出output da_clk; //D/A时钟output da_mode; //D/A数据模式选择
reg[11:0] load_count; //数控分频器重装值reg[11:0] scan_data; //扫频控制值reg[11:0] count; //数控分频计数器reg rom_clk; //ROM波表时钟reg[7:0]addr; //ROM地址
assign da_clk = rom_clk; //D/A时钟输出assign da_mode = 1'b0; //D/A数据模式选择以二进制输入
always @(posedge clock) //选择数控分频器初值begin if(select == 1'b1) load_count <= data; //由外部输入 else load_count <= scan_data; //由内部扫频产生end
always @(posedge clock) //数控分频器begin if(count == 12'hfff) begin count <= load_count; rom_clk <= 1'b1; end else begin count <= count + 1'b1; rom_clk <= 1'b0; endend
always @(posedge clock) //产生ROM地址begin if(rom_clk) addr <= addr + 8'd1;end
always @(posedge swept_clk) begin scan_data <= scan_data + 8'd1;end
sine_rom rom( //调用生成的ROM宏单元。 .address(addr), .clock(rom_clk), .q(dout)); endmodule
-
module sine_test(clock,key,select,data,seg,dig);input clock; //系统时钟(48MHz)input[3:0] key; //按键输入(KEY1~KEY4)output select; //发送数据使能output[11:0]data; //要发送的数据output[7:0]seg; //数码管段码输出output[7:0]dig; //数码管位码输出//I/O寄存器reg[11:0] data; reg select;reg[7:0]seg; reg[7:0]dig; //内部寄存器reg[16:0]count; //时钟分频计数器reg[3:0]dout1,dout2,dout3; //消抖寄存器reg[3:0]buff; //边沿检测寄存器reg[1:0] cnt; //数码管扫描计数器 reg[3:0]disp_dat; //数码管扫描显存 reg div_clk; //分频时钟wire[3:0] key_edge;
//时钟分频部分always @(posedge clock)begin if (count < 17'd120000) begin count <= count + 1'b1; div_clk <= 1'b0; end else begin count <= 17'd0; div_clk <= 1'b1; endend
//按键消抖部分always @(posedge clock)begin if(div_clk) begin dout1 <= key; dout2 <= dout1; dout3 <= dout2; end end
//按键边沿检测部分always @(posedge clock)begin buff <= dout1 | dout2 | dout3;end
assign key_edge = ~(dout1 | dout2 | dout3) & buff;
always @(posedge clock) //按键1begin if(key_edge[0]) //下降沿检测 data[11:8] <= data[11:8] + 1'b1;end
always @(posedge clock) //按键2begin if(key_edge[1]) //下降沿检测 data[7:4] <= data[7:4] + 1'b1;end
always @(posedge clock) //按键3begin if(key_edge[2]) //下降沿检测 data[3:0] <= data[3:0] + 1'b1;end
always @(posedge clock) //按键4begin if(key_edge[3]) //下降沿检测 select <= ~select;end
//数码管扫描显示部分always @(posedge clock) //定义上升沿触发进程begin if(div_clk) cnt <= cnt + 1'b1;end
always @(posedge clock) begin if(div_clk) begin case(cnt) //选择扫描显示数据 2'd0:disp_dat = data[11:8]; //第一个数码管 2'd1:disp_dat = data[7:4]; //第二个数码管 2'd2:disp_dat = data[3:0]; //第三个数码管 2'd3:disp_dat = {3'b0,select}; //第八个数码管 endcase case(cnt) //选择数码管显示位 2'd0:dig = 8'b01111111; //选择第一个数码管显示 2'd1:dig = 8'b10111111; //选择第二个数码管显示 2'd2:dig = 8'b11011111; //选择第三个数码管显示 2'd3:dig = 8'b11111110; //选择第八个数码管显示 endcase endend
always @(disp_dat)begin case(disp_dat) //七段译码 4'h0:seg = 8'hc0; //显示0 4'h1:seg = 8'hf9; //显示1 4'h2:seg = 8'ha4; //显示2 4'h3:seg = 8'hb0; //显示3 4'h4:seg = 8'h99; //显示4 4'h5:seg = 8'h92; //显示5 4'h6:seg = 8'h82; //显示6 4'h7:seg = 8'hf8; //显示7 4'h8:seg = 8'h80; //显示8 4'h9:seg = 8'h90; //显示9 4'ha:seg = 8'h88; //显示a 4'hb:seg = 8'h83; //显示b 4'hc:seg = 8'hc6; //显示c 4'hd:seg = 8'ha1; //显示d 4'he:seg = 8'h86; //显示e 4'hf:seg = 8'h8e; //显示f endcaseend
endmodule
-
我是准备在学校的实验箱上通过测试的,老师给了些程序,看着不是很懂,在网络上搜了搜,有的要用到单片机,那用不用这个单片机都对DDS产生正弦波无影响?
-
这个必须要顶啊
-
这个设计要用到MCS-51系列单片机不?
-
好,谢谢啊
-
我有个问题,我用的是cyclone的EP1C6Q240C8的,这个芯片的逻辑门数是多少?我在网上查不到
-
哈哈,楼主就是5楼的,看来我明白了,谢谢你哈,等遇到问题在向你请教
-
说简单点就是用fpga设计出来一个DDS,而这个dds可以差生20-20khz的正弦信号。我这样说对不?
-
那用FPGA完成DDS设计之后怎么实现扫频信号呢?