I'm using Arduino nano and I'm struggling working with the DRV8870 IC on PWM mode.
When I use analogWrite(_pin, duty_cycle);
the motor makes weird noises.
I thought it's because of the PWM frequency so I tried to change it using
TCCR1B = TCCR1B & B11111000 | B00000011;
but it didn't work out.
Texas Instruments wrote this in their pdf: "When using PWM, switching between driving and braking typically works best. For example, to drive a motor forward with 50% of the maximum RPM, IN1 = 1 and IN2 = 0 during the driving period, and IN1 = 1 and IN2 = 1 during the other period."
-
Are you sure you are changing correct timer? Only pins 9 and 10 are generated by Timer1KIIV– KIIV2020年10月04日 07:36:47 +00:00Commented Oct 4, 2020 at 7:36
1 Answer 1
analogWrite(_pin, duty_cycle) will work properly only on pins that support PWM. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs. Check the following link to find yours: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/