I'm working on learning Verilog and working with CPLDs and I'm stuck. The code I wrote toggles an LED, but I keep getting warnings during synthesis.
//toggles LED on and off after 1000000 clock cycles
module LEDON(
LED,
clk
);
output LED;
reg LED;
input clk ;
wire clk;
reg [31:0] count;
wire count_max = 32'd1_000_000;
assign count_nxt = (count >= count_max) ? 32'd0 : count + 32'd1;
assign led_state_nxt = (count == count_max) ? ~LED : LED;
always @(posedge clk)
begin
count <= count_nxt;
LED <= led_state_nxt;
end
endmodule
I get these warnings:
@W: MT420 |Found inferred clock LEDON|clk with period 1000.00ns. Please declare a user-defined clock on object "p:clk"
WARNING - map: C:/Documents and Settings/belo/Desktop/LedOn2/LedON2.lpf (4): Error in FREQUENCY NET "clk" 2.080000 MHz ;
WARNING - map: Preference parsing results: 1 semantic error detected
WARNING - map: There are errors in the preference file, "C:/Documents and Settings/belo/Desktop/LedOn2/LedON2.lpf".
WARNING - map: There are semantic errors in the preference file, "C:/Documents and Settings/belo/Desktop/LedOn2/LedON2.prf".
My LPF file looks like this:
BLOCK RESETPATHS ;
BLOCK ASYNCPATHS ;
LOCATE COMP "LED" SITE "41" ;
FREQUENCY NET "clk" 2.08 MHz ;
So does anyone know how to fix these clock warnings?
I'm not sure if this line: "wire count_max = 32'd1_000_000;" is synthesisable. It might be being ignored except in simulation (this could depend on your tool chain - it's not synthesisable for an ASIC, but for an FPGA ... maybe!!).
The line count>= count_max is comparing count to 0 (and not count max) and thus this is being optomised away (see warnings). This is why it's managed to synthesise but not do anything.
There are multiple solutions. 1) Use a parameter instead (it's like a const in C++ or #define in C):
parameter count_max = 32'd1_000_000;
2) Just use a smaller counter and toggle when it overflows
reg [16:0] count; // counts 131,072 cycles
assign led_next = (count == 0 ? ~LED : LED);
always @(posedge clk)
begin
count <= count + 1;
LED <= led_next;
end