奇数分频代码如下
module div_odd #
(
parameter integer DIV_NUM = 7 , // 分频数
parameter integer DIV_NUM_WIDTH = 3 // 分频计数位宽
)
(
input rst,
input clk,
output clk_out
);
reg clk_rise;
reg clk_fall;
reg [DIV_NUM_WIDTH - 1:0] cnt;
always@(posedge clk) begin
if(rst)
cnt <= 'h0;
else if(cnt== DIV_NUM-1'b1 )
cnt <= 'h0;
else
cnt <= cnt + 1'b1;
end
always@(posedge clk) begin
if(rst)
clk_rise <= 1'b0;
else if(cnt== 'h0)
clk_rise <= 1'b1;
//若此处判断条件为 else if(cnt== (DIV_NUM+1)/2)
//则 clk_out= clk_rise && clk_fall;
else if(cnt== (DIV_NUM+1)/2 - 1)
clk_rise <= 1'b0;
else
clk_rise <= clk_rise;
end
always@(negedge clk) begin
if(rst)
clk_fall <= 1'b0;
else
clk_fall <= clk_rise;
end
assign clk_out= clk_rise || clk_fall;
endmodule
2. fork join
fork join 用于仿真,不可综合。其中的语句并行执行。
3. 任务 函数函数特点 :
1 、至少存在一个输入 , 只能存在一个输出 //若不存在输入,可以使用parameter
2、函数不能存在延时,一般用于描述组合逻辑电路计算 或 对参数进行计算得到某个常数
3、可以综合 ,但需要function内的语句本身是可综合的
任务特点:
1、可以存在多个输入和多个输出
2、可以存在延迟
3、可以调用其他函数或任务
4、可以综合 ,但需要task内的语句本身是可综合的



