Leonardo PWM configuration

Hi all,
i'm using two BTS7960 Motordriver on Pin 9/10 and Pin 3/11 (see Schematic Arduino_FFB_Yoke/Schematics.jpg at main · gagagu/Arduino_FFB_Yoke · GitHub)
and i've added two lines to the Setup() to speed up the PWN Frequency because of loud noise of the motors and they need more frequency to work better. I've got the two lines everywhere from the internet and it seems to work fine.

// timer 1B: pin 9 & 10
TCCR1B = _BV(CS00); // change the PWM frequencey to 31.25kHz - pins 9 & 10

// timer 0B : pin 3 & 11
TCCR0B = _BV(CS00); // change the PWM frequencey to 31.25 kHz - pin 3 & 11

Now, i've found out that the function millis() will not work correctly anymore. It's too fast. I know the reason for this is to change the Timer configuration and i guess i can live with that but i want to ask if there is a better way to speed up the PWM frequency for the BTS7960 or do i something wrong?

Thx forward.

If not mistaken, timer 0 on the Leonardo is used for millis(). In which case I'm not surprised (just like you).

Use a different pair instead of 3/11. You however will have to think it through as nearly all your pins are in use.

You might be able to use Timer3 (Pin 5) and Timer4 (Pin 13) in place of Timer0 (Pins 3 and 11). Try:

// Timer1: pins 9 & 10
TCCR1B = _BV(CS10); // change the PWM frequencey to 31.25kHz - pins 9 & 10

// Timer3: pin 5
TCCR3B = _BV(CS30); // change the PWM frequencey to 31.25kHz - pin 5

// Timer4: pin 13
TCCR4B = _BV(CS40); // change the PWM frequencey to 31.25kHz - pin 13

Hi,
i will test out some different Pins.
Thx for helping me!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.