RenHao

freq_dividor

Nov 7th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module f_d(clk_in , mod2 , mod10);
  2. //assume that clk_in is 25MHz
  3.  
  4. reg [24:0] freq_cnt ; //register bit numbers must more than the frequency you want to divide
  5.  
  6. always@(posedge clk_in) begin
  7.     //this is how to deal with power of 2
  8.     mod2 <= ~mod2;
  9. end
  10.  
  11. always@(posedge clk_in) begin
  12. if(freq_cnt == 9) begin //mod 10-1
  13.     freq_cnt <= 0;
  14.     mod10 <= ~mod10;
  15. end
  16. else begin
  17.     freq_cnt <= freq_cnt + 1;
  18. end
  19.  
  20. end
  21.  
  22.  
  23. endmodule
Advertisement
Add Comment
Please, Sign In to add comment