Hello,
I've been working on a code for a quadcopter, and I've met alot of problems along the road. Seems like when I fix one thing, another problem occurs..
However, the problem I have now is the refresh rate output to the ESC.
Until now I have been using the servo library, but it only generates a frequency of 50hz, which is way to low for a quadcopter (I believe that's why my quad won't stabilize itself good enough), my ESC (turnigy trust 55A) can handle upto 433hz refresh rate.
I've been looking around for a couple of hours, reading at the playground section about changing the PWM frequency to make my own "library" instead.
1.
Now to the fact. There are three timers that I can adjust, timer0 (pin 5,6), timer1 (pin 9,10) and timer2(pin 11,3).
If you change TCCR0B, it affects millis() and delay(). They will count time faster or slower than normal if you change the TCCR0B settings.
So I will skip the timer0, and only set timer 1 and 2 (4 pins, enough for a quadcopter).
And to set the desired frequency, I've found an example code:
http://playground.arduino.cc/Code/PwmFrequency
The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
o The base frequency for pins 5 and 6 is 62500 Hz.The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 256, and 1024.
The divisors available on pins 3 and 11 are: 1, 8, 32, 128, 256, and 1024.
But these divisors wont give me a frequency of 400hz. Any suggestion on how I can accomplish that?
2.
We assume that the PWM refresh rate 400Hz = 2500micros.
The pulse that we want to send to the engine = 1500micros.
How would this routine look like?
It's soon 6 am, hard to sleep when you have all these kind of questions in your head!
Hope that some1 will be able to help me
Cheers!
Edit:
Sorry for misspelling alot, really tired