Question about analogWrite() and pin 2

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download

Question about analogWrite() and pin 2

Postby DIYprogrammer » Mon Jun 13, 2011 8:57 pm

Hi,

I'm trying to build a quadrocopter and to write my own Arduino program to control it. For this project the code and the ideas of the MultiWii have been a great help. But right now I'm kind of stuck.
I'm using the 8mhz version of the Arduino pro mini (and therefore all the clock rates are only half as fast) and trying to control my ESCs (HobbyKing SS Series) via PWM (pins 3,5,6 and 9). On pins 5 and 6 this works fine (they have a refresh rate of 1000/2=500Hz), but on pins 3 and 9 I get weird results (maybe because of the clock rate 500/2=250Hz). However changing this rate is not an option as it would affect also the timers I need for SPI communication and other stuff.

But looking at the MultiWii-Code I noticed, that it also uses analogWrite() on pin 2 (which is no "native" PWM pin) (In the Code "MOTOR_ORDER" is defined as 3,5,6,2,7,8 and later it says "uint8_t PWM_PIN[6] = {MOTOR_ORDER}; and analogWrite(PWM_PIN[i], ...); )

Now I'm asking myself how this is possible, is there some kind of secret trick?

PS: Sorry for the bad English, I'm not a native speaker...
DIYprogrammer
 
Posts: 1
Joined: Mon Jun 13, 2011 8:34 pm

Re: Question about analogWrite() and pin 2

Postby Alexinparis » Wed Jun 15, 2011 12:49 pm

analogWrite on PIN 2 in only used for mega boards.
on this board, this PIN can be an hardware PWM output
Alexinparis
 
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm


Return to Software development

Who is online

Users browsing this forum: No registered users and 2 guests