我做了一个计数器,在两个信号的控制下启动和停止计数
并且在计数完成后,输出一个脉冲信号,如果clk直接接外部50M晶振的话,输出没有问题,但如果接PLL的话(甚至倍频到80M),计数完成后输出的脉冲就直接输出杂声(高频),请高手指教一二.....,谢谢!
module counter(clk_in,start,stop,rst,count_num,count_over);
input clk_in,start,stop,rst;
output[7:0] count_num;
output count_over;
reg count_over;
reg [7:0] count_num;
reg [32:0] count_over_wide;
reg [32:0] count_out_wide;
parameter pulsewide=80;
reg count_flag;
reg count_over_flag;
always@(negedge start or posedge stop or negedge rst)
 begin
  if(!rst)
   count_flag<=0;
  else if(stop)
   begin
   count_flag<=0;
   end
  else  count_flag<=1;
 end
always@(posedge clk_in )
begin
 if(!rst)
  begin
   count_num<=0;
  end
    else if(count_flag==1)
  begin
   count_num<=count_num+1;
   end   
   
end
 always@(posedge clk_in)
  begin
   if(!rst)
    begin
     count_over_flag<=0;
     count_over_wide<=0;
     count_over<=0;
    end
   else if((stop)&(!count_over_flag))
     count_over_flag<=1;
   else if(count_over_flag==1)
    begin
     if(count_over_wide<=pulsewide)
      begin
       count_over<=1;
       count_over_wide<=count_over_wide+1;
      end
     else
      begin
       count_over_flag<=0;
       count_over_wide<=0;
      end
    end
   else
    count_over<=0;
  end
endmodule

 
					
				
 
			
			
			
						
			 
					
				 
					
				 
					
				 我要赚赏金
 我要赚赏金 STM32
STM32 MCU
MCU 通讯及无线技术
通讯及无线技术 物联网技术
物联网技术 电子DIY
电子DIY 板卡试用
板卡试用 基础知识
基础知识 软件与操作系统
软件与操作系统 我爱生活
我爱生活 小e食堂
小e食堂

