这几天刚刚看到了三段状态机写法,使用写了一个程序锻炼以下,但是出了很多问题.希望高手帮忙,以下是我写的程序:
`definedelay_max19 //采样脉冲的宽度
module dengxiao(
input _200MHz_clk,//系统时钟
input chufa,
output reg ad_clk,
output reg[7:0] count_max, //count_max,count,delay设置为输出口,方便仿真观察
output reg[8:0] count,
output reg[5:0] delay
);
reg rest;
reg k,c_en; //触发控制 k为屏蔽触发控制端,c_en为触发等待控制
reg[5:0] current_state,next_state;
parameter [5:0]
wait_chufa = 6'b000001,
count_200 = 6'b000010,
count_finish= 6'b000100,
delay_count= 6'b001000,
delay_finish = 6'b010000,
clr = 6'b100000;
//*******************时序状态转换******************//
[email=always@(posedge]always@(posedge[/email] _200MHz_clk or posedge rest)
begin
if(rest) current_state<=clr;
elsecurrent_state<=next_state;
end
//*******************触发状态控制*******************//
[email=always@(posedge]always@(posedge[/email] chufa or negedge k )
begin
if(!k)c_en<=1;
else begin c_en<=0;end
end
//************状态的逻辑转换条件**************//
[email=always@(count]always@(count[/email] or delay or c_en or count_max or current_state)
begin
next_state=3'bx;
case(current_state)
wait_chufa: if(c_en) next_state=count_200;
else next_state=wait_chufa;
count_200: if(count==199+count_max) next_state=count_finish;
else next_state=count_200;
count_finish:next_state=delay_count;
delay_count:if(delay==`delay_max) next_state=delay_finish;
else next_state=delay_count;
delay_finish:if(count_max==199) next_state=clr;
else next_state=wait_chufa;
clr: next_state = wait_chufa;
endcase
end
//**********每个状态的输出********//
[email=always@(posedge]always@(posedge[/email] _200MHz_clk)
begin
case(next_state)
wait_chufa:
begin
k<=0;
rest<=0;
end
count_200:
begin
k<=1;
count<=count+1;
end
count_finish:begin count<=0; count_max<=count_max+8'd1; end
delay_count:
begin
ad_clk<=1;
delay<=delay+1;
end
delay_finish:
begin
ad_clk<=1'd0;
delay<=6'd0;
end
clr:
begin
count_max<=0;
ad_clk<=0;
count<=0;
delay<=0;
end
endcase
end
endmodule
这个程序是顺序等效采样的.触发到来时开始采样,每次采样都比上一次采样延迟一个时钟周期(由于采样200MHz时钟,故延迟5ns),采样够200个点之后(即count_max=199),count_max清零,又重新开始采样.而采样时钟限制在1MHz,故计数时count至少每次要计数200次..
最终结果是ad_clk第一次输出是在count=199时,第二次在count=200,第3次在201....
但是出不了结果..郁闷!请高手帮忙 |