The source code for the analogWrite
function looks like this:
void analogWrite(uint8_t pin, int val) {
...
sbi(TCCRnA, COM0x);
OCRnx = val;
...
}
Where n is which timer (0, 1, 2...) and x is which pin is controlled by that timer (A, B).
This doesn't make sense to me, because the ATmega328P datasheet says that the bits TCCRnA.WGM0[1:0]
, and TCCRnB.WGM0
need to be set up as well.
Obviously the above code works, but how, with the missing bit settings?