jinlilijin的个人空间 https://blog.eetop.cn/81 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

div

热度 1已有 1448 次阅读| 2020-7-9 19:10 |系统分类:芯片设计


module div2(fi, div, rst_, fo); // Programmable frequency divider

parameter size = 2; //divider counter bit length, division ratio from 1 to 8

input fi; //input signal with frequency fi to be divided

input[size-1:0] div; //division ratio from 1 to 7, div=0 corresponds to divide by 8

input rst_; //active-low reset

output fo; //output signal with frequency fo = fi/div

reg[size-1:0] p; //p=1+integer(div/2) determines the falling edge of fo

reg[size-1:0] counter; //counter value;

reg p0, fout; //output buffer

wire ctr;

// Down counter: counter = counter - 1:

always @(posedge fi or negedge rst_)

if (!rst_) //reset to div = 1

begin

counter[size-1:0] <= {{(size-1){1'b0}},1'b1};

//The above line can be simplified as counter <= {{(size-1){1b0}},1b1}.

//But, its a good practice to specify clearly the every word range

p[size-1:0] <= {{(size-1){1'b0}},1'b1};

p0 <= 1'b1;

end

else if ( counter[size-1:0] == {{(size-1){1'b0}},1'b1} )


begin //load new division ratio when counter=1

counter[size-1:0] <= div[size-1:0]; //load new division ratio

p0 <= ( div[size-1:0] == {{(size-1){1'b0}},1'b1} ); //p0=1, if div=1

if(div[size-1:0] == {size{1'b0}})

p <= {1'b1,{(size-2){1'b0}},{1'b1}}; //div=0 is used to divide by 8

else

p <= {1'b0,div[size-1:1]} + {{(size-1){1'b0}},1'b1}; //p=1+integer(div/2)

end

else //otherwise counter-1

counter[size-1:0] <= counter[size-1:0] - {{(size-1){1'b0}},1'b1};

// Output pulse generator:

always @(posedge fi or negedge rst_)

if (!rst_) fout <= 1'b0;

else if(counter[size-1:0] == {{(size-1){1'b0}},1'b1}) fout <= 1'b1;

else if(counter[size-1:0] == p) fout <= 1'b0;

assign fo = p0 ? fi : fout; //if div=1, pass fi to fo





endmodule 


1

点赞

刚表态过的朋友 (1 人)

发表评论 评论 (1 个评论)

回复 jackzhang 2022-6-24 15:11
测试

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 1

    关注
  • 9

    粉丝
  • 6

    好友
  • 1

    获赞
  • 8

    评论
  • 3559

    访问数
关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-21 21:03 , Processed in 0.025948 second(s), 16 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部