Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

First verilog program problems.

Hey

I am working on my first verilog program, Basically it is a clock divider which divides the main clock 25mhz down to create a new slower clock this part is working ok. But I am trying to delay another pulse off the second clock and all I get it the output going low and nothing happens. I will post the code below if someone could tell me where I went wrong it would be great.

    module Detector(clk,clk_out,clk_second);
    input clk ;
    output reg clk_out;
    output reg clk_second;
    reg  counter;
    reg  counter1;
    
   
    always @(posedge clk) 
    begin
    if (counter==16'd0)
    begin
    clk_out <= ~clk_out;
    end
    if (counter==16'd750)
    begin
    clk_out <= ~clk_out;
    end  
    if(counter==16'd6500)
    begin
    counter<=16'd0;
    end
    else
    begin
    counter<=counter+1;
    end
    end
    
    always @ (posedge clk_out)
    begin 
    if (counter1==16'd1000)
    begin
    clk_second <= ~clk_second;
    end  
    else if (counter1==16'd1250)
    begin
    clk_second <= ~clk_second;
    counter1<=16'd0;
    end  
    else
    begin
    counter1<=counter1+1;
    end
    end 
    endmodule 

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Perhaps this isn't the right forum for this question if so could someone perhaps point me towards one ?. Thanks

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    In the second always block, counter1 is not changed when it equals 16'd1000, so it just counts to 1000 and stops.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your replay, I cant believe I missed that I added

    counter1<=counter1+1;

    in the "if 1000" loop and now it works as expected. Thanks Again