集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
楼主: longt

求助三分频verilog代码

[复制链接]
 楼主| longt 发表于 2010-6-28 11:50:23 | 显示全部楼层
无语,随便搜一下,满地都是!
FFT 发表于 2010-6-28 12:02:54 | 显示全部楼层
占空比1/3  2/3的很简单  50%的就比较复杂了 论坛里有50%的
VVC 发表于 2010-6-28 12:23:26 | 显示全部楼层
module (clkin,clkout,reset)<br>
input clkin;<br>
input reset;<br>
output clkout;<br>
<br>
//internal signal<br>
reg [1:0] cnt1;<br>
reg [1:0] cnt2;<br>
reg clk_generate1;<br>
reg clk_generate2;<br>
always @(posedge clkin or posedge reset)<br>
begin<br>
&nbsp;&nbsp;if (reset)<br>
&nbsp; &nbsp;begin<br>
&nbsp; &nbsp;&nbsp;&nbsp;cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp;&nbsp;clk_generate&lt;=0;<br>
&nbsp; &nbsp;end<br>
&nbsp;&nbsp;else<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp; if (cnt==2)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;clk_generate1&lt;=1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end<br>
&nbsp; &nbsp;&nbsp; &nbsp;else <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;cnt&lt;=cnt+1;<br>
end<br>
<br>
always @(negedge clk or negedge reset)<br>
begin<br>
if(~reset)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; cnt2&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; clk_gererate2&lt;=0;<br>
&nbsp; &nbsp; end<br>
else if(cnt2==2)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;clk_generate2&lt;=1;<br>
&nbsp; &nbsp;&nbsp;&nbsp;end<br>
else<br>
&nbsp; &nbsp;&nbsp;&nbsp;cnt2&lt;=cnt2+1;<br>
end<br>
<br>
assign clkout=clk_generate1&amp;clk_generate2;<br>
endmodule<br>
<br>
这段程序貌似可以实现占空比为50%的分频,但是由于中间使用了clk的上升沿和下降沿两个不同的时钟特性,<br>
估计在做时序分析时回有问题。
ICE 发表于 2010-6-28 13:12:47 | 显示全部楼层
module (clkin,clkout,reset)<br>
input clkin;<br>
input reset;<br>
output clkout;<br>
<br>
//internal signal<br>
reg [1:0] cnt1;<br>
reg [1:0] cnt2;<br>
reg clk_generate1;<br>
reg clk_generate2;<br>
always @(posedge clkin or posedge reset)<br>
begin<br>
&nbsp;&nbsp;if (reset)<br>
&nbsp; &nbsp;begin<br>
&nbsp; &nbsp;&nbsp;&nbsp;cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp;&nbsp;clk_generate&lt;=0;<br>
&nbsp; &nbsp;end<br>
&nbsp;&nbsp;else<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp; if (cnt==2)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;clk_generate1&lt;=1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end<br>
&nbsp; &nbsp;&nbsp; &nbsp;else <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;cnt&lt;=cnt+1;<br>
end<br>
<br>
always @(negedge clk or posedge reset)<br>
begin<br>
if(reset)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; cnt2&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; clk_gererate2&lt;=0;<br>
&nbsp; &nbsp; end<br>
else if(cnt2==2)<br>
&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;cnt&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;clk_generate2&lt;=1;<br>
&nbsp; &nbsp;&nbsp;&nbsp;end<br>
else<br>
&nbsp; &nbsp;&nbsp;&nbsp;cnt2&lt;=cnt2+1;<br>
end<br>
<br>
assign clkout=clk_generate1&amp;clk_generate2;<br>
endmodule<br>
<br>
这段程序貌似可以实现占空比为50%的分频,但是由于中间使用了clk的上升沿和下降沿两个不同的时钟特性,<br>
估计在做时序分析时回有问题。
encounter 发表于 2010-6-28 13:55:20 | 显示全部楼层
错了,应该是:assign clkout=clk_generate1||clk_generate2;
CHA 发表于 2010-6-28 15:30:50 | 显示全部楼层
自己用计数器编一个,很easy的
ups 发表于 2010-6-28 16:31:58 | 显示全部楼层
对,可以用计数器编写,占空比得自己考虑了
CTT 发表于 2010-6-28 17:50:40 | 显示全部楼层
我有VHDL的任意N进制的半占空比分频器代码,自己写的已经通过了硬件测试,不只有兴趣没
UFO 发表于 2010-6-28 18:43:57 | 显示全部楼层
看不懂啊!!!!!!
usd 发表于 2010-6-28 19:28:35 | 显示全部楼层
bucuoa&nbsp;&nbsp;woxihuang
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-5-6 14:17 , Processed in 0.063010 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表