Saeterncj / MX1508

Arduino library for MX1508 dual DC motor driver
MIT License
35 stars 15 forks source link

SLOW_DECAY mode and 1 pwm pin only. Example Mx1508Sample.ino #12

Open fanfanlatulipe26 opened 6 months ago

fanfanlatulipe26 commented 6 months ago

The configuration with SLOW_DECAY mode and only 1 pwm pin doesn't run as expected.

The documentation states:

  if using 1 pwm pin, make sure its pinIN1, then set pinIN2 to any digital pin. 

The example Mx1508Sample.ino, used also in the demo https://www.youtube.com/watch?v=jntVTbv9dD0&t=196s, using SLOW_DECAY and 1 pwm pin (NUMPWM = 1) contains

#define PINA 9
#define PINB 10  // Can be any digital pin. if using NUMPWM = 1

In fact pin 10 is also a pwm enabled pin on the Arduino UNO.

If you use a pure digital pin such 4 or 7 the example does not run as expected: the speed of the motor doesn't increase/decrease smoothly but change only between stopped and full speed.

The code in the library shows that in the case 1 pwm pin/slow_decay we still have an analogWrite on PINB: this will be equivalent to PINB set to 0 for pwm values \< 128 and set to 1 for pwm values > 128 if PINB is a pure digital pin.

In case of the UNO where pwm pins are scare resources, the 1_pwm mode may be useful, even if forward/backward spinning are not handle the same (SLOW_DECAY in one direction, FAST_DECAY for the other one)

FAST-DECAY/1 pin is OK (with the previous limitation)

Don't know if this library is maintained. If need be, I can try to make a pull request...