hi every one ...
can any one help me please...
I want to generate frequency using pwm ports in range from 2 khz to 10 khz ...
if it possible ...
if not just help me to generat 5 khz wave .../
thanks and regards..
hi every one ...
can any one help me please...
I want to generate frequency using pwm ports in range from 2 khz to 10 khz ...
if it possible ...
if not just help me to generat 5 khz wave .../
thanks and regards..
Do you need your Arduino to do anything else at the same time? How accurate do you need it?
If the answers are 'no', and 'less accurate than the Arduino clock' then you could produce the pulses in software quite easily.
There are several tone libraries that can generate square wave frequencies of arbitrary value.
https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation
mr peter I don't need too much accurate ..
and the board will not do any thing else at the same time ...
and what is the software you are talking about that can generate that pulse ??
thanks and regards
mr retrolefty
thanks alot but the tone library don't support more than about 160 hz ...
as maximum
thanks again
The_Under_Taker:
hi every one ...can any one help me please...
I want to generate frequency using pwm ports in range from 2 khz to 10 khz ...
if it possible ...
if not just help me to generat 5 khz wave .../
thanks and regards..
10 khz isn't all that high. You could simply do a "digitalWrite HIGH, delay, digitalWrite LOW, delay" loop.
Of course, that's terribly inefficient, the Arduino couldn't do anything else and the exact timing would be a fudge due to the overhead of translating "digitalWrite" into port commands.
A better way would be to setup a free running timer and a compare to toggle an output each time the timer overflowed, underflowed or matched the compare (depending on how it's setup). This method would give you a nice, clean accurate square wave with no perceptible processing overhead (i.e. you could run other code at the same time).
The_Under_Taker:
mr retroleftythanks alot but the tone library don't support more than about 160 hz ...
as maximum
thanks again
That is simply not true. From the link below maximum frequency is 65,573 Hz.
https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation#Constants
After all is said and done, because play() only accepts unsigned integers for frequency, the maximum frequency that can be produced is 65535 Hz - which, after rounding, results in a 65573.77 Hz "tone" on a 16 MHz part. Even if play accepted larger values for frequency, you couldn't achieve better than around 80KHz with the Tone library because the pin toggling is done in software. Each toggle, in software, requires AT LEAST 50+ cycles.
thanks alot for you two
appreciated I think that is more than enough for me to have a good start ..
if I face any problem later I will ask again sorry
thanks and regards
If you get really ambitious you could look directly at controlling the pin using the hardware timers. This will free up your system from doing anything else. However, you would need to learn that by reading the datasheet for your uC from atmel's website. Its relatively easy to set up once you understand how it works. I do not have much time to explain it.