数字IC设计学习笔记
分频器
1 占空比50%偶分频
2 占空比50%奇分频
3 任意占空比为50%的整数分频
1 占空比50%偶分频
(1). 原理图
① D-FF:Qn+1 = D
② JK-FF: Qn+1 = JQ’+K’Q (易实现并行式同步工作应用于较高频的应用场合)
(2)Verilog 代码
1. module div24_r1
2. #(
3. parameter DIVIDER_NUM = 3'd4
4. )
5. (
6. input clk,
7. input rst,
8.
9. output reg en
10. );
11. reg [2:0] cnt;
12. always@(posedge clk or negedge rst)begin
13. if(!rst)
14. cnt <= 3'd0;
15. else if(cnt == DIVIDER_NUM -1)
16. cnt <=3'd0;
17. else
18. cnt <= cnt + 1'd1;
19. end
20. always@(posedge clk or negedge rst)begin
21. if(!rst)
22. en <= 0;
23. else if(cnt == (DIVIDER_NUM /2)-1)
24. en <= 1'd1;
25. else if(cnt == DIVIDER_NUM -1)
26. en <= 1'd0;
27. end
28. endmodule
(3). Modelsim仿真
2 占空比50%奇分频
(1). 原理图
(2). Verilog 代码
1. module div_odd_r1#(
2. parameter DIVIDER_ODD = 5
3. )
4. (
5. input wire clk,
6. input wire rst,
7. output wire en_odd
8. );
9. reg clk_pos;
10. reg clk_neg;
11. reg [2:0] cnt;
12.
13. always@(posedge clk or negedge rst)begin
14. if(!rst)
15. cnt <= 3'd0;
16. else if(cnt == DIVIDER_ODD-1)
17. cnt <= 3'd0;
18. else
19. cnt <= cnt +1;
20. end
21. always@(posedge clk or negedge rst)begin
22. if(!rst)
23. clk_pos <= 1'd0;
24. else if(cnt == (DIVIDER_ODD-1)/2)
25. clk_pos <= 1'd1;
26. else if(cnt == (DIVIDER_ODD-1))
27. clk_pos <= 1'd0;
28. end
29. always@(negedge clk or negedge rst)begin
30. if(!rst)
31. clk_neg <= 1'd0;
32. else if(cnt == (DIVIDER_ODD-1)/2)
33. clk_neg <= 1'd1;
34. else if(cnt == (DIVIDER_ODD-1))
35. clk_neg <= 1'd0;
36. end
37. assign en_odd = clk_pos | clk_neg;
38. endmodule
(3). Modelsim 仿真
3 任意占空比为50%的整数分频
(1). Verilog 代码
1. module div_random#(
2. parameter DIVIDER_NUM = 5
3. )
4. (
5. input wire clk,
6. input wire rst,
7. output wire out
8. );
9. reg clk_pos;
10. reg clk_neg;
11. reg [3:0] cnt;
12. wire div_odd;
13. wire div_even;
14.
15. always@(posedge clk or negedge rst)begin
16. if(!rst)
17. cnt <= 4'd0;
18. else if (cnt == DIVIDER_NUM-1)
19. cnt <= 4'd0;
20. else
21. cnt <= cnt +1;
22. end
23. always@(posedge clk or negedge rst)begin
24. if(!rst)
25. clk_pos <= 1'd0;
26. else
27. if(cnt == (DIVIDER_NUM-1)/2)
28. clk_pos <= 1'd1;
29. else
30. if(cnt == DIVIDER_NUM-1)
31. clk_pos <= 1'd0;
32. end
33. always@(negedge clk or negedge rst)begin
34. if(!rst)
35. clk_neg <= 1'd0;
36. else
37. if(cnt == (DIVIDER_NUM-1)/2)
38. clk_neg <= 1'd1;
39. else
40. if(cnt == DIVIDER_NUM-1)
41. clk_neg <= 1'd0;
42. end
43. assign div_odd = clk_pos | clk_neg;
44. assign div_even = clk_pos;
45. assign out = ((DIVIDER_NUM%2)==3'd0)? div_even:div_odd;
46. endmodule
(2). Modelsim 仿真
ex. 5-分频
ex. 6-分频
(3). 可能存在的问题:
1>. 低速系统:不易察觉
2>. 高速系统:可能会有时钟偏斜(skew)和抖动(jitter)问题
原因:FPGA中,所有时钟信号连接在全局时钟树上。为了使到达每个寄存器的时间尽可 能相同,保证更低的时钟偏斜(skew)和抖动(jitter)。分频器产生的时钟信号,并没有连接到全局时钟树上。
解决方法:使用flag标志信号。Ex. 6分频。产生一个用于标记6分频的clk_flag信号,这样相邻两个clk_flag脉冲间的频率是原时钟频率(sclk)的6分频,相当于把out的上升沿信号变成clk_flag的脉冲电平信号,为后级模块实现相同的降频效果,能够使系统更加稳定。
部分内容转自达尔文说: https://mp.weixin.qq.com/s/xl5tzPO6N-hiCXi5Z5EdJg
【注】:个人学习笔记,如有错误,望不吝赐教,这厢有礼了~~~