💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
https://www.icourse163.org/learn/UESTC-1205788811?tid=1450474442#/learn/content?type=detail&id=1233293349&cid=1252197791 ![](https://img.kancloud.cn/cd/72/cd723d83428896f9b38811ce8befb26c_678x547.png) ![](https://img.kancloud.cn/c8/ba/c8bad9771485a77ed56c803bb01b9bad_786x535.png) ![](https://img.kancloud.cn/e0/47/e047ddea21228db25cbe03bf23e4eae1_718x534.png) 1、偶数分频 偶数倍分频相对简单,可以通过计数器对预分频的脉冲沿计数实现,如果要进行N倍(N为整数)偶数分频,可由预分频的时钟触发计数器计数,当计数器从0计数到N/2—1时,输出时钟进行翻转,并给计数器一个复位信号,使得下一个时钟从零开始计数,以此循环下去。分频的主体程序如下: ``` module freq_div_even(input clk_in, input reset, output reg clk_out ); reg[2:0] count; parameter N=8; always@(posedge clk_in) begin if(!reset) begin count<=0; clk_out<=0; end else if(count==(N/2-1)) begin clk_out<=~clk_out; count<=0; end else begin count<=count+1; end end endmodule ``` 2、奇数分频 对于对占空比没有特殊要求的奇数分频,需要对上升沿和下降沿脉冲进行计数,利用下降沿产生的波形移相半个输入脉冲的作用,最后用错位“异或”法实现。一个13分频的程序如下: module count_num( input clk, input reset, output cout//这里是wire型变量 ); reg[4:0] m,n; reg cout1,cout2; assign cout = cout1 | cout2//**口诀:模块输入端必须用wire,模块输出端可以用wire,reg,assign必须用wire,always必须用reg** ``` always@(posedge clk) begin if(!reset) begin cout1<=0; m<=0; end else begin if(m=NUM-1) m<=0; else m<=m+1; if(m<(NUM-1)/2) cout1<=1; else cout1<=0; end end always@(negedge clk) begin if(!reset) begin cout2<=0; n<=0; end else begin if(n=NUM-1) n<=0; else n<=n+1; if(n<(NUM-1)/2) cout2<=1; else cout2<=0; end end endmodule ```