PWM uses the analogWrite() function. I would just use analogRead() and analogWrite() unless there is a compelling reason to use the registers (ie speed faster than 100us for a read or changing PWM frequency).
"Best practice" is hard to define without knowing, in detail, what you are trying to do.
groundFungus:
PWM uses the analogWrite() function.
Of course...
groundFungus:
I would just use analogRead() and analogWrite() unless there is a compelling reason to use the registers (ie speed faster than 100us for a read or changing PWM frequency).
"Best practice" is hard to define without knowing, in detail, what you are trying to do.
As i'm changing the pwm frequency to 20KHz, i have to use registers. The pwm-signal is used to control a 4-pin dc fan.
So, would you write to TCCR1 and use analogWrite() along or stick to writing to registers?
Is there any significant difference in using the Arduino functions over writing to registers or even mixing both up?
septillion:
Any reason to use such a particular frequency for just a fan?
Yes.
4-Pin fans with a separate pwm-wire need a frequency of ~25KHz (Intel specs).
The fan is use, accepts a frequency of 18-30KHz.
Anything below 20KHz is hearable and results in a humming motor.