Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help Plz about freq divison

Status
Not open for further replies.

stuntmaster

Newbie level 4
Joined
Apr 15, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
i am new to verilog and i need to get 160Hz form my clock oscillator which is
25.17Mhz using verilog i tried with this code


always @(posedge clk25mhz)
begin : process_2
if (count2 < 160)
begin
count2 <= count2 + 1;
end
else
begin
count2 <= 0;
end
if (count2 < 80)
begin
clk_160hz <= 1'b 0;
end
else
begin
clk_160hz <= 1'b 1;
end
end
 

In your code you are assuming that your 25MHz reference clk has a time period of 1 second. So you assume that if your counter counts to 80 and inverts the polarity of your clk160hz signal you get 80Hz and invert again at count = 160 and that gives you 160Hz which is incorrect.
Your clk25mhz has a time period of 40ns and not 1s. You want a 160Hz clock with a time period of 6.25ms. You'll probably need a PLL which divides down your frequency from 25MHz to 160Hz and takes care of your phase (if that's important to you).
If this code is aimed towards a FPGA you can use one of the PLL ips available with your vendor. If not you could search this forum and you'll see lots of posts talking about implementing a PLL in verilog.
Your current code will give you a clock with frequency = 155.27MHz.
 
thx for ur reply do u have any idea how to make this code generates 160Hz form 25.17MHz
 

160Hz is not an integer multiple of 25.17MHz, so you won't be able to directly divide the 25.17MHz clock down. You'll need some sort of PLL, like ckaa suggested.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top