Skip to content

Instantly share code, notes, and snippets.

@gibiansky
Created December 9, 2012 21:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gibiansky/4247200 to your computer and use it in GitHub Desktop.
Save gibiansky/4247200 to your computer and use it in GitHub Desktop.
Verilog Fibonacci Module
module fib(input clock, reset, input [5:0] n, output reg ready, output [31:0] value)
reg [31:0] previous, current;
reg [5:0] counter;
// Reset the circuit
always @(posedge reset)
begin
previous <= 32'd0;
current <= 32'd1;
counter <= 32'd1;
end
// Compute next Fibonacci number
always @(posedge clock)
begin
// Increment current index
counter <= counter + 1;
// Efficient adders are automatically inferred
current <= current + previous;
previous <= current;
if (counter == n)
ready <= 1;
end
// Read the value of the nth fibonacci number from the internal register
assign value = current;
endmodule
@cahuja2
Copy link

cahuja2 commented Apr 13, 2017

This will have multiple driver issues while synthesizing.

@Satjpatel
Copy link

This will have multiple driver issues while synthesizing.

Where exactly would the error may occur?

@ZiyadMousa-99
Copy link

sorry, but the code has an error:

Error (10161): Verilog HDL error at fibonacci.v(21): object "ready" is not declared. Verify the object name is correct. If the name is correct, declare the object.
Error: Quartus Prime Analysis & Synthesis was unsuccessful. 1 error, 2 warnings
Error: Peak virtual memory: 4752 megabytes
Error: Processing ended: Sat Oct 09 14:56:34 2021
Error: Elapsed time: 00:00:06
Error: Total CPU time (on all processors): 00:00:14
Error (293001): Quartus Prime Full Compilation was unsuccessful. 3 errors, 2 warnings

@adarshtg610
Copy link

image

This will have multiple driver issues while synthesizing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment