Forum Discussion

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

clock division in verilog

I'd like some help to understand why this code didn't work.

----------------------------------------------

module emissao2(

clk,

enable_in,

over_temp_in,

MSB_in,

LSB_in,

enable_led,

over_temp_led,

MSB_led,

LSB_led,

enable_out,

over_temp_out,

MSB_out,

LSB_out,

ctrl_p_1,

ctrl_n_1,

ctrl_p_2,

ctrl_n_2,

ctrl_p_3,

ctrl_n_3,

ctrl_p_4,

ctrl_n_4);

//---Input Ports---

input clk;

input enable_in;

input over_temp_in;

input MSB_in;

input LSB_in;

//---Output Ports---

output enable_led;

output over_temp_led;

output MSB_led;

output LSB_led;

output enable_out;

output over_temp_out;

output MSB_out;

output LSB_out;

output ctrl_p_1;

output ctrl_n_1;

output ctrl_p_2;

output ctrl_n_2;

output ctrl_p_3;

output ctrl_n_3;

output ctrl_p_4;

output ctrl_n_4;

//---Input Ports Data Type---

wire clk;

wire enable_in;

wire over_temp_in;

wire MSB_in;

wire LSB_in;

//---Output Ports Data Type---

reg enable_led;

reg over_temp_led;

reg MSB_led;

reg LSB_led;

reg enable_out;

reg over_temp_out;

reg MSB_out;

reg LSB_out;

reg ctrl_p_1;

reg ctrl_n_1;

reg ctrl_p_2;

reg ctrl_n_2;

reg ctrl_p_3;

reg ctrl_n_3;

reg ctrl_p_4;

reg ctrl_n_4;

reg [3:0]count;

initial begin

count = 4'd0;

ctrl_p_1 = 1'b0;

end

always @(posedge clk)

begin

if(count==4'd10)

begin

count<=3'd0;

ctrl_p_1 <= ~ctrl_p_1;

end

else

begin

count<=count+1;

end

end

endmodule

----------------------------

It compile but does not work. I made the assignments correctly, and i will use all this ports, this is just a inicial code just to see if works.

I'm using Quartus II 13.0, to program Altera DE2 (EP2C35F672C)

2 Replies

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

    Initial blocks are not synthesizable. Change it to a reset condition of your always @(posedge clock)

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

    You missed to say what "didn't work" in your code. In the present code, ctrl_p_1 will be toggled after each 10 clock cycles.

    --- Quote Start ---

    Initial blocks are not synthesizable. Change it to a reset condition of your always @(posedge clock)

    --- Quote End ---

    They are synthesized as initialization during power on reset. Initializing to 0 is redundant, because this is the default register state without additional initializations. A reset condition can be repeated at will, in contrast to POR which is only performed once.