SetPinFrequency

Hey guys,

I'm pretty new to controlling motors with arduino, so please have that in mind when reading.

I'm using analogWrite together with SetPinFrequency in the PWM.h library, to get a certain RPM on a nidec motor which is driven by input frequency - and it is working quite well. My program reads feedback RPM and then increases or decreases the frequency with SetPinFrequency until the wanted RPM is found.

However, there is one thing that I don't understand fully. It does not stop if I set the frequency to 0. The range of input frequency is supposed to be 50 - 382 Hz but if I put it to 0, the RPM is weirdly enough bigger than if it's just 50 Hz. It's the same thing with all frequencies below 50.

Does anyone know what the method does when the input is below, in this case, 50 Hz? And is the only way to stop the motor to use digitalWrite(pin, 0)?

Thanks in advance

(Arduino UNO if that matters)

Did you try it? What happens?

The motor stops, so that solution is fine. The program is as said working well, I just want to understand! :slight_smile:

It due to timer resolution limitation.
The freq range depends from the pin you using.
Please read the comments in the PWM.ino example:

The library allows for a frequency range from 1Hz - 2MHz on 16 bit timers and 31Hz - 2 MHz on 8 bit timers.

On Uno pins 3, 5, 6 & 11 are outputs of 8bit timers0 & 2, and pins 9 & 10 - output of 16bit Timer1. So if you want to control you motors with freq as low as 1 Hz - use pins 9 or 10.

Thank you so much, that definitely made it more clear.

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