PWM problem and DC motors

Hello everyone,

I have a problem with the pwm of arduni nano to control two DC motors.
First my PWM pins are 6 and 9, their performance frequencies as I read on the arduino page are different, except the default is 490Hz, but I need between 4kHz and 10 KHz.

Problem 1 being different OCs the pre-scale does not respond the same so I can not make them match except the one that is by default.

Any idea how to configure that parameter in 4kHz frequency for both pins of PWM?

Thanks in advance.

Cool, a Arduni, does that differ much from an Arduino? :wink:

And, a typical XY-problem. Why do you need 4kHz? And 4kHz exactly? Or will 3,8kHz for example also work?

And why not take two pins on the same timer? Makes it a lot easier. Also, pin 6 (and pin 5) are from timer 0. And that's the timer that runs millis() aka all the normal timing of the Arduino. So messing with that isn't advised.

Hi septillion,

Sorry but I made a typo when writing, I meant Arduino and not Arduini.

I can not use pins 5 and 6 because the hardware does not let me have to be 6 and 9.

As far as frequency is not necessary exactly 4kHz but so approximate.

a greeting

I can not use pins 5 and 6 because the hardware does not let me have to be 6 and 9.

I told you to NOT use pin 5 and 6 because that will give you trouble

As far as frequency is not necessary exactly 4kHz but so approximate.

Then it's about time you DO explain what you really want. And I mean details. And yes, that's going to be more than the 51 words you used... At least 300 I guess :wink:

Forgive me if I have been a bit brief with the definition of the problem.

I have a robot whose mission is through a sensor to perform a PID to the motors, since the hardware is unmovable the PWM pins are 6 and 9 and I want to change the switching frequency of them above the 490 generics And use 4kHz and according to the info of the page of arduino there is another pre-scale in which it can be configured to 4kHz to both, that is to say that they coincide.
The question is if there is another solution to do it, I do not know if through libraries or changing some other parameter of the OCs.

Now we're talking. :slight_smile:

But then you're in a pickle... Changing the frequency of pin 6 means changing the frequency of timer 0 which means all the timing on the Arduino will be messed up... So I don't think it's worth it. But you can change the frequency of pin 9 to be also 960Hz. Just Google for "Arduino PWM" and the first couple of pages will tell you which registers to change.

And because I'm a nice guy, a more in depth article.

Then the solution that you suggest to me is to change the pin 9 to 960Hz like this the pin 6 of standard way no?

You could tell me how to complete that record.

Thank you for everything and greetings!

Yes, that's the easiest way to have the same and higher then 480Hz frequency for both..

But sorry, don't know the registers from the top of my head. I'll have to read the same stuff I suggested to you so I'll leave that for you to read :wink: