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!
-
25 and 50 hz square wave can be generated by software easilyratchet freak– ratchet freak2017年09月11日 20:22:09 +00:00Commented Sep 11, 2017 at 20:22
1 Answer 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
}