+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Newbie level 4
    Points: 44, Level: 1

    Join Date
    Sep 2013
    Posts
    5
    Helped
    0 / 0
    Points
    44
    Level
    1

    Verilog hdl code 1hz

    hello, can someone explain to me the following codes below?i really don't understand these. please help


    module progdiv(clk,rst,clk1Hz);
    parameter WIDTH=25; // default 25-bit counter
    input clk; // 50MHz
    input rst;
    output clk1Hz;
    reg clk1Hz;
    reg [WIDTH-1:0] cnt;
    always @(posedge clk, posedge rst)
    begin
    if (rst) begin
    cnt <= 0;
    clk1Hz <= 0;
    end else if (cnt == 25000000) begin
    cnt <= 0; // wrap around
    clk1Hz <= ~clk1Hz; // toggle
    end else begin
    cnt <= cnt + 1;
    end
    end

    •   AltAdvertisment

        
       

  2. #2
    Member level 5
    Points: 550, Level: 4

    Join Date
    Apr 2013
    Location
    India
    Posts
    83
    Helped
    7 / 7
    Points
    550
    Level
    4

    Re: Verilog hdl code 1hz

    What exactly you didn't understand in this code? Are you familiar with verilog syntax and logic?



    •   AltAdvertisment

        
       

  3. #3
    Full Member level 6
    Points: 3,296, Level: 13
    Achievements:
    7 years registered
    imbichie's Avatar
    Join Date
    Jul 2010
    Location
    Cochin/ Kerala/ India or Bangalore/ Karnataka/ India
    Posts
    381
    Helped
    55 / 55
    Points
    3,296
    Level
    13

    Re: Verilog hdl code 1hz

    This is nothing but just a clock divider code.
    If the input clock is 50MHz, then the output will be 1Hz,
    means its a divide by 50,000,000.

    But there are mistakes here
    1. If you really want 1Hz, then you should give 24999999, instead of 25000000, because the counter includes the zero, or you can put the less than (< ) operator instead of equal to (==)
    2. You should specify the base of the counter, means the base should be decimal. Other wise count will change, i think default it will take it as hexadecimal (i don't remember the default base), so here you can put 25'd2500000 or 25'd24999999.
    Thanks & Regards,
    Shibin Bose Kavara

    " Take chances, make mistakes. That's how you grow. Pain nourishes your courage. You have to fail in order to practice being brave "


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  4. #4
    Full Member level 6
    Points: 3,296, Level: 13
    Achievements:
    7 years registered
    imbichie's Avatar
    Join Date
    Jul 2010
    Location
    Cochin/ Kerala/ India or Bangalore/ Karnataka/ India
    Posts
    381
    Helped
    55 / 55
    Points
    3,296
    Level
    13

    Re: Verilog hdl code 1hz

    Quote Originally Posted by imbichie View Post
    2. You should specify the base of the counter, means the base should be decimal. Other wise count will change, i think default it will take it as hexadecimal (i don't remember the default base), so here you can put 25'd2500000 or 25'd24999999.
    Here i am mistaken, the default base in verilog is decimal, so if the base is not specified its treated as decimal.
    Thanks & Regards,
    Shibin Bose Kavara

    " Take chances, make mistakes. That's how you grow. Pain nourishes your courage. You have to fail in order to practice being brave "



--[[ ]]--