//有符号数转化为无符号数输出到DA
always @(posedge clk)
begin
if(sine[7]==1'b1)
dadata_o<=sine-128;
else
dadata_o<=sine+128;
end
//控制DDS输出不同的频率
always @(posedge clk)
begin
//dds_we<=dds_we_req;
case(dds_freq)
2'b11:begin
//timer_trig <= 1'd1;
if (timer<11'd2046)
begin
dds_we<=1'd1;
dds_data <= 29'd53687091; //5MHz: (dds_data*2^29)/(50*1000000)
timer <= timer +1'd1;
end
else if (timer == 11'd2046)
begin
dds_we<=1'd0;
timer<=11'd2046;
end
end
default begin
// dds_we<=1'd0;
// timer<=11'd2046;
// dds_we<=dds_we_req;
end
endcase;
end
//按钮处理程序, 改变DDS的输出频率
always @(posedge clk)
begin
if (key1==1'b1) //如果按钮没有按下,寄存器为0
key1_counter<=0;
// dds_freq<=1'b0;
// dds_we_req<=1'b0;
// dds_freq<=dds_freq;
else if ((key1==1'b0)&& (key1_counter<=16'hc350)) //如果按钮按下并按下时间少于1ms,计数
key1_counter<=key1_counter+1'b1;
if (key1_counter==16'hc349) begin //一次按钮有效,改变DDS频率
dds_freq<=2'b11;
//dds_we_req<=1'b1;
end
else begin