//功能:采集10个数据,找出最大的和最小的数据<br>
<br>
//McuStart 单片机输入信号,要求FPGA开始工作<br>
//McuReset 复位AD0809<br>
<br>
//Write 开始AD0809转换<br>
//Read 读取AD0809转换结果<br>
//EOC AD0809是否转换完成标志<br>
//Data 0809数据口<br>
<br>
//我省略了0809de的ALE 和时钟输入 引脚 <br>
//只要不断有McuStart脉冲,就可以不断进行AD转换 ,不过脉冲周期长度要考虑<br>
module AD0809(McuStart, McuReset, Write, Read, EOC, Data, TempA);<br>
<br>
input[7:0] Data;<br>
input McuStart, McuReset, EOC;<br>
<br>
output Write, Read ;<br>
output TempA;<br>
reg[7:0] TempA;//, TempB; <br>
<br>
reg[2:0] state, NextState;<br>
<br>
reg Write, Read, ALE;<br>
<br>
parameter state0 = 3'b000, state1 = 3'b001, state2 = 3'b011, state3= 3'b010, state4 = 3'b110, state5 = 3'b111;//, state6 = 3'b101;//状态编码<br>
<br>
always @(McuReset) //复位<br>
begin<br>
if(McuReset == 1'b0)<br>
begin<br>
state = state0;<br>
// Write = 0;<br>
// Read = 0;<br>
// ALE = 0;<br>
// TempA = 8b'00000000;<br>
// TempB = 8b'00000000;<br>
end <br>
else <br>
state = NextState;<br>
<br>
end<br>
<br>
always @(McuStart or EOC or state) <br>
begin<br>
<br>
case (state)<br>
state0:<br>
begin<br>
if(McuStart == 1'b0)<br>
NextState = state1;//state1: ALE = 1<br>
else<br>
NextState = state0; <br>
end<br>
<br>
state1:<br>
begin<br>
if(ALE == 1'b1)<br>
NextState = state2;//ALE = 0; WR = 1;<br>
else<br>
NextState = state0; <br>
end <br>
<br>
state2:<br>
begin<br>
if(Write == 1'b1)<br>
NextState = state3;//WR = 0;ADC start convert<br>
else<br>
NextState = state2; <br>
end <br>
<br>
state3:<br>
begin<br>
if(EOC == 1'b1)<br>
NextState = state4;//EOC = 1; AD convert have finished <br>
else<br>
NextState = state3;//EOC = 0,wait AD convert finish<br>
end<br>
<br>
state4:<br>
begin<br>
if(Read == 1'b1)<br>
NextState = state5; //RD = 1; <br>
else<br>
NextState = state4;<br>
end <br>
<br>
state5:<br>
begin<br>
if(Read == 1'b0)//AD转换结束<br>
NextState = state0;<br>
else<br>
NextState = state5; <br>
<br>
end <br>
<br>
default: NextState = state0;<br>
endcase<br>
<br>
<br>
end<br>
<br>
<br>
always @(state)<br>
begin<br>
case (state)<br>
state0: begin Write = 0; Read = 0; ALE = 0; end //起始状态<br>
state1: begin ALE = 1; end // <br>
state2: begin ALE = 0; Write = 1; end //<br>
state3: begin Write = 0; end<br>
state4: begin Read = 1; end<br>
<br>
state5: begin TempA[7:0] = Data[7:0]; Read = 0; end<br>
endcase<br>
end<br>
endmodule |