I have connected DRV8835 with 2 DC motors with 11 power supply. Arduino nano.

When I for loop like i from 0 to 1024 for analogWrite(i,Motor1) for the DC Motor1 it's accelerating from 0 to 200 and it's stopping. When I becomes 250 it's starting at higher speed. When it becomes 500 it's stopping again. And 550 we have our power again.

Now I tried to run analogWrite(1000, ***) but it's not working. When I change the value from 1000 to 1005 it's not working again. But at 1024 we have the maximum speed and it is working?

 #define LEFT_PWM 9
 #define RIGHT_PWM 10
 #define LEFT_DIR 5
 #define RIGHT_DIR 6

void setup() {
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

void loop() {
  digitalWrite(LEFT_DIR, HIGH);
  analogWrite(LEFT_PWM, 1000);

1 Answer 1


analogWrite has the following prototype

void analogWrite(uint8_t, int);

which means that its first parameter has [0, 256) range and follows the rules of modulo arithmetic, with 256 as the modulo. If you supply arguments outside of [0, 256) range, they will be interpreted % 256. 1000 is the same as 232 (1000 % 256 == 232), 500 is the same as 244, 550 is the same as 38 and so on.

This is not fully consistent with the symptoms you describe (if your description is accurate), which might imply that something else is a factor here. Are sure you are using your DRV8835 in PHASE/ENABLE mode (pin 11 pulled high)?

  • The pin MOD was the real problem. Soldered it to VCC with a wire and problem is solved. Before that the motors behavior was very random.
    – Lary
    May 8, 2019 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.