K
Konx
Guest
Hi everyone.
I'm trying to write a piece of code that generates a signal, according
to a specific value in a clk_counter signal. the logic would be:
- if "reset" is high: set the clk_counter to zero
- if "reset" is low: at every positive edge of the clk, increment the
clk_counter
- when clk_counter = 7, set the "trigger" signal to 1 (or high)
- when clk_counter = 50, set the "trigger" to 0 (or low)
- when clk_counter = 100, set the clk_counter to zero and
automatically start again another cycle
(so, basically, if the reset is low I should see a "periodic" trigger
coming out). I want my code synthesizeable (it is not a testbench).
This is what I wrote:
module logic_gen(
clk_40,
reset,
trigger);
input clk_40;
input reset;
output trigger;
reg [31:0] clk_counter;
reg trigger;
always@(posedge clk_40)
if(reset)
begin
clk_counter <= 32'b00000000000000000000000000000000;
end else
begin
clk_counter <= clk_counter+1;
if(clk_counter == 7)
trigger <= 1'b1;
if(clk_counter == 50)
trigger <= 1'b0;
if(clk_counter == 100)
clk_counter <= 32'b00000000000000000000000000000000;
end
endmodule
I know that the coding style is awful (I'm learning-by-doing by
myself) but is this logic suppose to work? do you see big mistakes?
For reference: I'm using this code as one module inside a big design
that target a Xilinx FPGA; I can synthesize the code using the Xilinx
ISE and I can produce the bitstream, so I guess that I'm not seeing
the signal coming out because the code is logically wrong.
I hope I've explained well enough the problem, if you need other
informations just ask
Thank you very much in advance for any help
Francesco.
I'm trying to write a piece of code that generates a signal, according
to a specific value in a clk_counter signal. the logic would be:
- if "reset" is high: set the clk_counter to zero
- if "reset" is low: at every positive edge of the clk, increment the
clk_counter
- when clk_counter = 7, set the "trigger" signal to 1 (or high)
- when clk_counter = 50, set the "trigger" to 0 (or low)
- when clk_counter = 100, set the clk_counter to zero and
automatically start again another cycle
(so, basically, if the reset is low I should see a "periodic" trigger
coming out). I want my code synthesizeable (it is not a testbench).
This is what I wrote:
module logic_gen(
clk_40,
reset,
trigger);
input clk_40;
input reset;
output trigger;
reg [31:0] clk_counter;
reg trigger;
always@(posedge clk_40)
if(reset)
begin
clk_counter <= 32'b00000000000000000000000000000000;
end else
begin
clk_counter <= clk_counter+1;
if(clk_counter == 7)
trigger <= 1'b1;
if(clk_counter == 50)
trigger <= 1'b0;
if(clk_counter == 100)
clk_counter <= 32'b00000000000000000000000000000000;
end
endmodule
I know that the coding style is awful (I'm learning-by-doing by
myself) but is this logic suppose to work? do you see big mistakes?
For reference: I'm using this code as one module inside a big design
that target a Xilinx FPGA; I can synthesize the code using the Xilinx
ISE and I can produce the bitstream, so I guess that I'm not seeing
the signal coming out because the code is logically wrong.
I hope I've explained well enough the problem, if you need other
informations just ask
Thank you very much in advance for any help
Francesco.