cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
521 Views
Registered: ‎08-21-2019

need to convert 200Mhz to 5Mhz or low frequency

Jump to solution

Hi,

Whats wrong with this code. Im using kc705 kintex7 FPGA board

`timescale 1ns / 1ps

module square_wave_gen(
input clk,
input rst_n,
output sq_wave
);

// Input clock is 100MHz
localparam CLOCK_FREQUENCY = 100000000;

// Counter for toggling of clock
integer counter = 0;

reg sq_wave_reg = 0;
assign sq_wave = sq_wave_reg;

always @(posedge clk) begin

if (rst_n) begin
counter <= 8'h00;
sq_wave_reg <= 1'b0;
end

else begin

// If counter is zero, toggle sq_wave_reg
if (counter == 8'h00) begin
sq_wave_reg <= ~sq_wave_reg;

// Generate 1Hz Frequency
counter <= CLOCK_FREQUENCY/10000 - 1;
end

// Else count down
else
counter <= counter - 1;
end
end

endmodule

 

constraints file 

set_property IOSTANDARD LVDS [get_ports clk]
set_property PACKAGE_PIN AD11 [get_ports clk]
set_property PACKAGE_PIN AG5 [get_ports rst_n]
set_property IOSTANDARD LVCMOS15 [get_ports rst_n]
set_property PACKAGE_PIN AG29 [get_ports sq_wave]
set_property IOSTANDARD LVCMOS25 [get_ports sq_wave]


set_property CLOCK_DEDICATED_ROUTE FALSE [get_nets {clk_IBUF}]

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Contributor
Contributor
433 Views
Registered: ‎10-25-2019

There is nothing wrong with your code. For 100Mhz clock input , your code generates 5khz square wave output . If you want to generate 5Mhz , then you should assign counter<=CLOCK_FREQUENCY/10000000-1; 
If you want to generate 5Mhz from 200Mhz however, just set CLOCK_FREQUENCY to 200000000 and counter<=CLOCK_FREQUENCY/10000000-1; 

As you experiment with your values, sq_wave output may have longer period than default 1000ns simulation time. In that case press F3 to continue running simulation and you'll see the changes .

Feel free to accept as solution is it solves your issue.

Regards,
jagannath@logictronix.com

View solution in original post

2 Replies
Highlighted
Xilinx Employee
Xilinx Employee
505 Views
Registered: ‎02-27-2019

Hi @bosechandran 

How about changing integer counter = 0; to reg [7:0] counter; ?

-------------------------------------------------------------------------
Don't forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
Highlighted
Contributor
Contributor
434 Views
Registered: ‎10-25-2019

There is nothing wrong with your code. For 100Mhz clock input , your code generates 5khz square wave output . If you want to generate 5Mhz , then you should assign counter<=CLOCK_FREQUENCY/10000000-1; 
If you want to generate 5Mhz from 200Mhz however, just set CLOCK_FREQUENCY to 200000000 and counter<=CLOCK_FREQUENCY/10000000-1; 

As you experiment with your values, sq_wave output may have longer period than default 1000ns simulation time. In that case press F3 to continue running simulation and you'll see the changes .

Feel free to accept as solution is it solves your issue.

Regards,
jagannath@logictronix.com

View solution in original post