Search code examples
verilogfpgayosysiverilog

Why I can not copy a content of register to another one in "always" block in Verilog?


well, I have this code, that is working perfectly:

module syncRX(clk, signal, detect);
    input clk, signal;
    output reg [7:0] detect = 0;
    reg [7:0] delay = 0;
    
    //wire clk_1khz;
    freq_div div(.clk(clk), .clk_1khz(clk_1khz));
    
    always @(posedge signal)
     begin
        detect <= detect + 1;
        delay <= 0;
     end
    
    always @(posedge clk_1khz)
     begin
        delay <= delay + 1;
     end
    
endmodule // top

module freq_div(input clk, output reg clk_1khz);
    reg [12:0] count = 0;
    always @(posedge clk)
     begin
        if(count == 6000)
            begin
                clk_1khz <= ~clk_1khz;
                count <= 0;
            end
        else
            count <= count + 1;
     end
    
endmodule

The problem appears when I change the line "detect <= detect + 1;" to "detect <= delay;". The intention is calculate the period of the signal, but I get this warning message of Icestorm: Warning: No clocks found in design

And the FPGA stop working... Please, anyone have an idea what is going bad? Thanks to all!

By the votes of the question I could see that is not good one, maybe because community consider it that there is already documented, but I still can not find solution to the problem, I did some improvements and I will try again to find help here, I have this code now, that syntethize perfectly:

module syncRX(clk, signal, detect);
    input clk, signal;
    output [7:0] detect;
    
    reg [7:0] detect_aux = 8'b0;
    reg rst;
    assign detect = detect_aux & ~rst;
    
    freq_div div(.clk(clk), .clk_1khz(clk_1khz));
    
    always @(posedge signal)
        rst <= 1;
        
    always @(posedge clk_1khz)
        detect_aux <= detect_aux + 1;
     
endmodule // top

module freq_div(input clk, output reg clk_1khz);
    reg [12:0] count = 0;
    always @(posedge clk)
     begin
        if(count == 6000)
            begin
                clk_1khz <= ~clk_1khz;
                count <= 0;
            end
        else
            count <= count + 1;
     end
endmodule

The problem is that

    reg rst;
    assign detect = detect_aux & ~rst;

Seams do nothingh. Any suggestion? Thanks


Solution

  • The problem is that delay is multiply driven (driving from multiple always blocks is not allowed in synthesis) which is undefined behaviour (in this case I believe the constant '0' will be used). It should also be at least a warning.