Arduino UNO And SD Card Custom csPin
Pin 10 is special. It's the hardware chip select pin for SPI.  It is integral to the SPI peripheral in the chip.

That pin must be an OUTPUT for SPI to operate as master, or INPUT for it to operate as a slave.

It's a stupid design decision by Atmel if you ask me, but there you go.  So basically trying to use SPI at the same time as PWM on pin 10 is "undefined" and to be avoided.

Use a different pin for PWM or if you need more than there are PWM pins available then consider an external PWM control chip.



Just probing around to get more detail on exactly how it all works, this is what I have found:


digitalWrite() explicitly disables PWM on a pin.
The direction of pin 10 defines the SPI operation as master or slave.
analogWrite() sets pinMode(OUTPUT).
The SD library calls pinMode(OUTPUT) and digitalWrite(HIGH) on pin 10.


This means that:


SD.begin() will terminate any existing PWM on pin 10.
Using PWM on pin 10 will force the pin to output rendering SPI slave mode impossible


You should be able to use PWM on pin 10 if, and only if:


You use analogWrite() after using SD.begin(), and
You never want to use SPI slave mode.