Arduino PWM

When I researched a bit about PWM generation using arduino, I came to know that this is made possible using the internal timers on the arduino. But I see that not all pins support PWM. analogRead() makes use of PWM to generate analog signals by creating square waves of a particular duty cycle. So my question is can't I switch the outputs of ordinary digital pins in sync with the timer to produce precise PWM and analog voltages??
Thanks and regards.

analogRead() makes use of PWM to generate analog signals by creating square waves of a particular duty cycle

No analogWrite does that, the read is something seprate.
Only 6 pins can be controlled by the timers directly. You can write a program that uses one timer as an interrupt and then handles any other pin with PWM but it is processor intensive. Look for soft PWM some one has written a libary to do this.

http://code.google.com/p/rogue-code/wiki/SoftPWMLibraryDocumentation

Sorry, I meant analogWrite()

sreedevk:
So my question is can't I switch the outputs of ordinary digital pins in sync with the timer to produce precise PWM and analog voltages??

Not precisely, no, and anyway, why bother when you can use the actual (timer) pins? For precise PWM the hardware timers will continue to run even if the processor is servicing an interrupt. To switch "in sync" (and again, why?) you would need something like a pin-change interrupt to detect when the other pins change, and then wait for the interrupt to mirror the new pins to the old ones. I don't see what you gain by doing this.

You can switch digital pins and get PWM:

void loop()
{
  digitalWrite(led_pin, HIGH);   
  delayMicroseconds(ontime);          
  digitalWrite(led_pin, LOW);    
  delayMicroseconds(alltime-ontime);
}

Where alltime is time of one cycle (I'd take 1000 microseconds = 1 ms for example)
ontime is the time pin is HIGH, so to have 50% duty cycle set alltime to 1000 and ontime to 500