always @(posedge clk ornegedge rstn) begin if(!rstn) begin cnt <= 0; endelsebegin if(cnt == (DIV-1)) begin cnt <= 0; end elsebegin cnt <= cnt + 1; end end end
always @(posedge clk ornegedge rstn) begin if(!rstn) begin clko <= 1'b0; endelsebegin if(cnt == (DIV-1)/2) begin clko <= ~clko; end elseif(cnt == (DIV -1)) begin clko <= ~clko; end elsebegin clko <= clko; end end end
always @(posedge clk ornegedge rstn) begin if(!rstn) begin pos_cnt <= 0; endelsebegin if(pos_cnt == (DIV-1)) begin pos_cnt <= 0; endelsebegin pos_cnt <= pos_cnt + 1; end end end
always @(posedge clk ornegedge rstn) begin if(!rstn) begin pos_clk <= 0; endelsebegin if(pos_cnt == (DIV-1)/2) begin pos_clk <= ~pos_clk; end elseif(pos_cnt == (DIV-1)) begin pos_clk <= ~pos_clk; end elsebegin pos_clk <= pos_clk; end end end
//negedge clk reg [DIV-1:0] neg_cnt; reg neg_clk;
always @(negedge clk ornegedge rstn) begin if(!rstn) begin neg_cnt <= 0; endelsebegin if(neg_cnt == (DIV-1)) begin neg_cnt <= 0; endelsebegin neg_cnt <= neg_cnt + 1; end end end
always @(negedge clk ornegedge rstn) begin if(!rstn) begin neg_clk <= 0; endelsebegin if(neg_cnt == (DIV-1)/2) begin neg_clk <= ~neg_clk; end elseif(neg_cnt == (DIV-1)) begin neg_clk <= ~neg_clk; end elsebegin neg_clk <= neg_clk; end end end
reg [3:0] cnt; always @(posedge clk ornegedge rstn) begin if(!rstn) begin cnt <= 0; endelsebegin if(cnt == (M-1)) begin cnt <= 0; endelsebegin cnt <= cnt + 1; end end end
reg [3:0] cnt2; reg [3:0] cnt3;
parameter CHANGE = 4;
always @(posedge clk ornegedge rstn) begin if(!rstn) begin cnt2 <= 0; cnt3 <= 0; endelsebegin if(cnt <= (CHANGE-1)) begin cnt3 <= 0; if(cnt2 == (DIV_M-1)) begin cnt2 <= 0; endelsebegin cnt2 <= cnt2 + 1; end end elseif(cnt > (CHANGE -1)) begin cnt2 <= 0; if(cnt3 == (DIV_N -1)) begin cnt3 <= 0; endelsebegin cnt3 <= cnt3 + 1; end end end end
always @(posedge clk ornegedge rstn) begin if(!rstn) begin clko <= 0; endelsebegin if(cnt < CHANGE) begin if(cnt2 == 0 || cnt2 == DIV_M/2) begin clko <= ~clko; end elsebegin clko <= clko; end end elsebegin if(cnt3 == 0 || cnt3 == (DIV_N-1)/2) begin clko <= ~clko; end elsebegin clko <= clko; end end end end