I currently have a Spartan-6 FPGA in a Digilent Nexus 3 board. I am using Xilinx 14.6 Project Navigator to write the code and program the FPGA.
My code for the top (and only) module is the following:
21 module blinker( 22 input clk, 23 output reg led_state 24 ); 25 26 reg [31:0] count; 27 wire count_max = 32'd50000000; 28 29 assign count_next = (count_next > count_max) ? 32'd00000000 : count + 32'd00000001; 30 assign led_next = (count == count_max) ? ~led_state : led_state; 31 32 always @(posedge clk) 33 begin 34 count <= count_next; 35 led_state <= led_next; 36 end 37 38 endmodule
According to the Nexus 3 reference manual, the board has a 100MHz Oscillator at pin V10, and so in my User Constraints File, I mapped the V10 pin to the clk input signal of my module.
Since the oscillator is at 100MHz, I set count_max to be 50,000,000, so that the led_state should invert every 50 x 10^6 clk edges, or every half-second assuming 100MHz.
When I attempted Synthesis using XST in the Project Navigator, I get these warning messages:
WARNING:HDLCompiler:413 - "C:\Users\Public\Documents\Xilinx Projects\blinker\blinker.v" Line 29: Result of 32-bit expression is truncated to fit in 1-bit target. WARNING:Xst:2404 - FFs/Latches <count<31:1>> (without init value) have a constant value of 0 in block <blinker>. WARNING:Xst:2170 - Unit blinker : the following signal(s) form a combinatorial loop: n0011<0>.
However, I am still able to go ahead and build the .bit file and program the Nexus 3. The result, however, is that the LED, which I designated to by the output, simply stayed on the entire time (unless it is blinking so rapidly that I do not notice it blinking).
I thought that maybe it has to do with the Warning where the Synthesizer truncated the expression in Line 29, so I tried declaring count_next as a 32-bit vector [31:0], both as a reg and a wire, and also initializing its value. Tried the Synthesizer and I get errors instead.
Declaring and initializing count, led_state, count_next, led_next didn't work either.
I was wondering if someone can look at this and tell me what's wrong with the code. There's also a combinatorial loop for the signal "n0011<0>" which I don't recognize.