Verilog code

时间:2021-10-05 12:23:45

1、计数,用于对精度不高的计数

always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
div_cnt <= 'd0;
else
div_cnt <= div_cnt + 'b1;
end assign div_clk = div_cnt[]; //div_cnt < 100

2、检测边沿

//--------------------------------
//Funtion : detect start pos always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
pos_arr <= 'd0;
else
pos_arr <= {pos_arr[:] ,estart };
end assign start = pos_arr[] & ~pos_arr[]

3、声明的不同最好在注释上面体现出来,而不是在变量名

//localparam        BAUD_END        =        5207            ;        //9600bps
localparam BAUD_END = ; //115200bps

4、组合数据,少使用了寄存器资源

always @(posedge clk_24m or negedge rst_n)
begin
if(!rst_n)
ov7670_data_out <= 'd0;
else if(cnt_byte == 'b1)
ov7670_data_out <= {ov7670_data_out[:] , ov7670_data};
else
ov7670_data_out <= {ov7670_data , 'd0};
end

。。。。待续