// state transfer
always @ (posedge clk_100M or negedge rst_n)//异步复位
begin
if(!rst_n)
current_state <= idle;
else
current_state <= next_state;//注意,使用的是非阻塞赋值
end
// transfer condition
always @ (* )
begin
case(current_state)
idle:
next_state = write;
write:
if (write_over)
next_state = start;
else
next_state = write;
start:
if (start_flag1)
next_state = acq;
else
next_state = start;
acq:
if (start_flag2)
next_state = read;
else
next_state = acq;
read:
if (!counter_channel)
next_state = over;
else
next_state = read;
over:
next_state = idle;
default:
next_state = idle;
endcase
end
//output
always @ (posedge clk_100M or negedge rst_n)//异步复位
begin
if(!rst_n)
begin
//counter <= counter+1;
SHDN <= 0;
CHSHDN_L <= 0;
convst <= 1;
RD_L <= 1;
WR_L <= 1;
CS_L <= 1;
counter <= 0;
counter_channel <= 1;
write_over <= 0;
start_flag2 <=0;
led0<=0;
led1<=0;
end
else
begin
case(next_state)
idle:
begin
end
write:
begin
if(counter <= 'd6)
begin
///ok led0<=1;
convst <= 1;
WR_L <= 0;
RD_L <= 1;
CS_L <= 0;
write_over <= 0;
ADI1S <= 8'b0001_0000;
counter_channel <= 1;
counter <= counter+1;
end
else
begin
WR_L <= 1;
CS_L <= 1;
convst <= 1;
write_over <= 1;
ADI1S <= 8'b0001_0000;//note
counter <= 0;
//ok led1<=1;
end
end
start:
begin
//if(counter <= 'd3)
over_flag <=0;
//led1<=1;
end
acq:
begin
//led1<=1;
if(counter<100)//data acquisition
begin
convst <=0;
CS_L <= 1;
RD_L <= 1;
WR_L <= 1;
counter <= counter+1;
start_flag2 <= 0;
//ok led0<=1;
end
else
begin
convst <=1;
RD_L <= 1;
WR_L <= 1;
counter <= 0;
start_flag2 <= 1;
// ok led1<=1;
end
end
read:
begin
// ok led0<=1;
if(!EOC_L)
begin
//led0<=1;
if(counter <= 'd5)//tRDL
begin
CS_L <= 0;
WR_L <= 1;
RD_L <= 0;
ADbuf[7:0]<=ADI1;
ADbuf[11:8]<=ADI2;
counter <= counter+1;
led0<=1;
end
else
begin
RD_L <= 1;
WR_L <= 1;
CS_L <= 1;
counter <= 0;
counter_channel <= counter_channel-1;
led1<=1;
end
end
else
;//led1<=1;
end
over:begin
over_flag <=1 ;
//led1<=1;
end
default:
;
endcase
end
end
endmodule
其中ADIS是写AD转换通道的寄存器,ADI1是AD转后后的低8位数据(用的是双向口),ADI2是AD转后后的高4位数据,ADbuf是读AD转换结果的缓冲寄存器,ADO是将AD转换后给经FPGA输出给DA的12位数据;
看了下QUARTUS的警告:
Warning: Tri-state node(s) do not directly drive top-level pin(s)
Warning: Converted the fan-out from the tri-state buffer "ad1308:inst|ADI1[4]" to the node "ad1308:inst|ADbuf[4]" into an OR gate
Warning: Open-drain buffer(s) that do not directly drive top-level pin(s) are removed
Warning: Converted the fanout from the open-drain buffer "ad1308:inst|ADI1[7]" to the node "ad1308:inst|ADbuf[7]" into a wire
Warning: Converted the fanout from the open-drain buffer "ad1308:inst|ADI1[6]" to the node "ad1308:inst|ADbuf[6]" into a wire
Warning: Converted the fanout from the open-drain buffer "ad1308:inst|ADI1[5]" to the node "ad1308:inst|ADbuf[5]" into a wire
Warning: Converted the fanout from the open-drain buffer "ad1308:inst|ADI1[3]" to the node "ad1308:inst|ADbuf[3]" into a wire
Warning: Converted the fanout from the open-drain buffer "ad1308:inst|ADI1[2]" to the node "ad1308:inst|ADbuf[2]" into a wire
Warning: Converted the fanout from the open-drain buffer "ad1308:inst|ADI1[1]" to the node "ad1308:inst|ADbuf[1]" into a wire
Warning: Converted the fanout from the open-drain buffer "ad1308:inst|ADI1[0]" to the node "ad1308:inst|ADbuf[0]" into a wire