always @(posedge clk_in ornegedge rst) begin// 输入时钟计数 if (~rst) begin cyc_clk <= 'b0; end elsebegin cyc_clk <= (cyc_clk==M_N-1)? 'b0 : cyc_clk+'b1; end end
always @(posedge clk_in ornegedge rst) begin// 分频时钟计数器 if (~rst) begin clk_cnt <= 'b0; end elsebegin if (~div_flag) begin clk_cnt <= (clk_cnt==div_e-1)? 'b0 : clk_cnt+'b1; end elsebegin clk_cnt <= (clk_cnt==div_o-1)? 'b0 : clk_cnt+'b1; end end end
always @(posedge clk_in ornegedge rst) begin// 分频系数切换 if (~rst) begin div_flag <= 'b0; end elsebegin div_flag <= (cyc_clk==(M_N-1) || cyc_clk==c89-1)? ~div_flag : div_flag; end end
always @(posedge clk_in ornegedge rst) begin// 生成分频时钟 if (~rst) begin clk_out_tmp <= 'b0; end elsebegin if (~div_flag) begin clk_out_tmp <= (clk_cnt<=((div_e>>2)+1)); end elsebegin clk_out_tmp <= (clk_cnt<=((div_o>>2)+1)); end end end