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.

40KHz square wave in "Verilog"

Status
Not open for further replies.

heart

Newbie level 3
Joined
Jan 7, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
Hi everyone,

I want to generate a square wave signal with 40khz frequency in verilog. Can someone please tell me how I can achieve this??

Thank you!
 

hi heart, to gnerate 40khz wave signal in verilog, first convert 40khz frequency to time i.e, t=1/f, so for 40khz it will be 25000ns. 25000ns is the period of signal, for 50% duty cycle it will on for 12500ns on and 12500ns off(as my time directive is in ns).

`timescale 1ns/1ns
initial
begin
signl=1'b0;
forever #12500 signl= ~signl;
end

i hope my answer will help u....:)

---------- Post added at 11:00 ---------- Previous post was at 10:59 ----------

hi heart, to gnerate 40khz wave signal in verilog, first convert 40khz frequency to time i.e, t=1/f, so for 40khz it will be 25000ns. 25000ns is the period of signal, for 50% duty cycle it will on for 12500ns on and 12500ns off(as my time directive is in ns).

`timescale 1ns/1ns
initial
begin
signl=1'b0;
forever #12500 signl= ~signl;
end

i hope my answer will help u....:)
 

yep , i agree with aijaz .. just one question , wondering tht can we write above code like this :

'timescale 10ns/10ns // i changed 1ns to 10 ns ...
.
.
.
.
.
forever #1250 signl = ~signl ; // changed 12500 to 1250(since 1250 * 10 = 12500)
end

?????
 
Last edited:

Yup u can do dat, we can even change d timescale to 100ns instead 10ns:)
 

wondering tht can we write above code like this
You can, but why you should?

It hasn't been mentioned, that generating a square wave this way is restricted to simulation. But it's a problem about asking clear questions in the first place.
 

You can, but why you should?

It hasn't been mentioned, that generating a square wave this way is restricted to simulation. But it's a problem about asking clear questions in the first place.

Hi FvM well I wanted to implement this on hardware as well.. I am sorry for not specifying clearly I want to modulate and send the 40KHZ to the the spartan 3E board. So will this approach mentioned above by Aijaz still work in hardware if I wish to generate a 40KHZ square wave?
 

No, it won't work in hardware.

You can use a simple clock divider to generate a 40 KHz. Look in your board's manual to see what the frequency of its system clock is. Connect a counter to this clock. Divide the fast clock by 40 kHz to calculate how many cycles you need to wait. Divide that figure by two, then each time the counter hits that value, toggle an output register between high and low.
 
  • Like
Reactions: heart

    heart

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top