always @(posedge sysclk or negedge rst_b)
begin
if(!rst_b)
begin
div_cnt <= 7'h0;
ad_clk <= 0;
end
else if(div_cnt == 7'd49)
begin
div_cnt <= 7'h0;
ad_clk <= ~ad_clk;
end
else
begin
div_cnt <= div_cnt + 1;
ad_clk <= ad_clk;
end
end
//ad7658配置
assign ad_cs = 0;
always @(posedge ad_clk or negedge rst_b)
begin
if(!rst_b)
begin
ad_reset <= 1;
data1 <= 12'h000;
data2 <= 12'h000;
data3 <= 12'h000;
data4 <= 12'h000;
data5 <= 12'h000;
data6 <= 12'h000;
state <= 4'd0;
end
else
case(state)
4'd0:
begin
ad_reset <= 0;
ad_convsta <= 0;
ad_convstb <= 0;
ad_convstc <= 0;
ad_rd <= 1;
state <= 4'd1;
end
4'd1:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
state <= 4'd2;
end
4'd2://开始采样
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
if(ad_busy == 0)
state <= 4'd3;
else
state <= 4'd2;
end
4'd3:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 0;//50MHz晶振20分频,T=400ns > t9=6ns
data1 <= ad_data; //第一路
state <= 4'd4;
end
4'd4:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
state <= 4'd5;
end
4'd5:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 0;
data2 <= ad_data; //第二路
state <= 4'd6;
end
4'd6:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
state <= 4'd7;
end
4'd7:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 0;
data3 <= ad_data; //第三路
state <= 4'd8;
end
4'd8:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
state <= 4'd9;
end
4'd9:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 0;
data4 <= ad_data; //第四路
if(sel == 1) //共6路
state <= 4'd10;
else //共4路
state <= 4'd14;
end
4'd10:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
state <= 4'd11;
end
4'd11:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 0;
data5 <= ad_data; //第五路
state <= 4'd12;
end
4'd12:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
state <= 4'd13;
end
4'd13:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 0;
data6 <= ad_data; //第六路
state <= 4'd14;
end
4'd14:
begin
ad_convsta <= 1;
ad_convstb <= 1;
ad_convstc <= 1;
ad_rd <= 1;
state <= 4'd0;
end
default:
begin
ad_convsta <= 0;
ad_convstb <= 0;
ad_convstc <= 0;
ad_rd <= 1;
end
endcase
end