Electronic – arduino – Does changing PWM frequency in arduino affects SPI and I2C communication and helps controlling DC motor

arduinodc motorfrequencypwm

I'm using L293D based motor shield for controlling two dc-motors from Arduino Mega 2560.
I use 5 and 6 PWM pin for setting speed of each motor. I have two questions:

  1. Does increasing frequency of PWM (from default 500Hz to maximum 31KHz) will make the motors more sensitive? With default frequency (apart from noise) the motors are working above 130-140 PWM level. Below 130 they are not rotating, only giving the "BEEP" noise. There is also little difference between 130 and 255 level. Does increasing pulse frequency will make them more sensitive, so I could run them at like 32 level (1/8 max speed)?

  2. If so: Does changing the divisor in timer0 (as described here http://arduino.cc/playground/Code/PwmFrequency and here http://www.mythic-beasts.com/~markt/ATmega-timers.html ) will affect SPI and I2C interface? Will (and how) it affect the pulseIn function? (I know it will affect the delay function, but I guess it I will need to rescale function argument).

Best Answer

1) 31KHz is a much more reasonable PWM frequency than 500Hz. Motors will act like a low-pass-filter and generally give you the DC equivalent of your PWM but with very low frequency PWM that gets dicey - as you've seen. In general, you should increase the frequency of the PWM above the bandwidth of the motor - otherwise it sees a square wave rather than a DC voltage. 31KHz is right in the range of most motor controllers I've seen. You generally want it high but not too high (HF noise may couple into other parts of the circuit, etc.). It looks like you're in a good range with 31KHz.

2) It shouldn't affect those bit rates. The peripherals ought to have their own dividers and scalers and should be driven off of the main clock and not a peripheral timer. I can't speak to the pulseIn function though.