1

I'm newbie in arduino due. I need to reduce the default PWM frequency of arduino Due. Anyone have any tutorial to do this? (Frequencys like 25hz, 50Hz for example)

I read in some posts, if i change the PWM frequency, i make changes in internal timers of arduino and i loss functions like delay(), millis(), etc.

Exits any form to not lose these functions?

Thanks a lot!

1
  • 25 and 50 hz square wave can be generated by software easily Sep 11, 2017 at 20:22

1 Answer 1

-1

The Palatis Softpwm library can generate PWM on any digital pin with (almost) any frequency. Example for 25Hz:

#include <SoftPWM.h>
SOFTPWM_DEFINE_CHANNEL(0, DDRB, PORTB, PORTB2);  //Arduino pin 10
void setup() {
  // begin with 25Hz pwm frequency
  Palatis::SoftPWM.begin(25);
  Palatis::SoftPWM.set(0, value); // value is 0 to 255 just like normal Arduino analogWrite
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.