I believe that there is a lot of confusion as to what the original author was trying to say.
According the the library TimerOne.h you can set certain pins to do whatever frequency you want (within capability of the board).
He is referring to this - Arduino Playground - HomePage
using the coding from the website directly I had a lot of problems. You have to download the timer files, leave them in the zip and put them directly into the libraries folder, no subfolders, dont extract them. Once you are done doing this open up your sketch and import the libraries (ZIP FILE NEED TO BE IN THE LIBRARIES FOLDER) - I say all caps because I messed up several times and once I did this, everything worked perfectly. then... "#Include <TimerOne.h> which you type in or click "Sketch" and Import Library --> click file and it will automatically add it.
Mine looks like this
#include <TimerOne.h>
void setup() {
// put your setup code here, to run once:
pinMode(9, OUTPUT);
Timer1.initialize(11230); // Intialize timer1, and set a 89hz frequency
Timer1.pwm(9,300); // setup pwm on pin 9, with a 50% duty cycle
}
void loop() {
// put your main code here, to run repeatedly:
}
** In my sketch it says 50% Duty cycle in the notes but right now its actually at something else i just didnt change the notes on it. It is using 10 bits so instead of 255 its like 1054 or something like that.
** Also
Figuring out HERTZ
- go to: Convert hertz to milliseconds - frequency converter
- Enter in desired hertz and it outputs how many milliseconds you need
- take your milli seconds and conver them to microseconds by going to google and saying "convert milliseconds to microseconds" it will then give you a google calculator and does the calculations for you
- Use these calculations in your sketch, for example mine says 11230 - that is the microseconds needed to create an 89hz frequency because herz is how many cycles per second the signal is 1000000(1 second in Microseconds) / 11230 = 89.04 hz
AND it works. My pin 9 is outputting an 89hz frequency.
I could not be more excited.
The the original Author, I hope you got it working... I dont know anything about creating advanced algorithms, but I hope this helps.
The arduino CAN make its own PWM frequency and is not limited like most of the posters have said. Using the Timer1 for Uno and Timer3 for Mega, you can unlock the PWM potential
Hope this helps someone.