Electronic – Arduino AnalogWrite and its frequency and effectiveness

arduinopwm

Reading about the arduino analogWrite function I have come to understand that it uses PWM for the variable DC voltage. (by controlling the width of the pulse)

However how do we control the frequency of the pulse? I came across a few articles about the same but couldn't get them. Any help is appreciated.

Moreover how effective is it to use that analogWrite voltage as say a biasing voltage? Or maybe as a variable Vcc itself. Does the fact that DC is obtained via PWM will effect underlying circuitry expected working (where the underlying circuitry is anything one can do with a transistor)

Best Answer

Changing PWM frequency is not directly supported by Arduino command set, but it can be done. For this you need to know a couple of things:

  • find the datasheet for the exact microcontroller (ATmega..) that is on your Arduino
  • which Arduino pin you want PWM frequency to change;
  • which pin on the controller it is connected to (this is described on http://arduino.cc/ );
  • find the chapter on PWM in the datasheet that discusses the controller pins you are interested in.

On top of that, some of the PWM pins are attached to timer0, which is heavily relied upon for other system tasks (like delay();). So fiddling with PWM may change the execution speed of some code.