Arduino Mega PWM Frequency Change

Hey all!

I think this is something that is simple in Arduino IDE but not so much in XOD.

is there a simple way to change the speed registers on a mega? I know if you do it on a uno/mini it’ll mess up the timing but a mega it wont.

I was able to do this on a Due by changing the variant.h file but can’t see it in the same thing for a mega

I’ve found Wiring_digital.c which has some timer stuff in it cant find where TCCRnB is located.

Ive been able to switch the frequency in Arduino IDE with 2 lines of code in Void Setup but those changes do not stay active once its reflashed with XOD

void setup ()
{
TCCR2B &= ~ _BV (CS22); // cancel pre-scaler of 64
TCCR2B |= _BV (CS20); // no pre-scaler
analogWrite (9, 50); // 19.6 % duty cycle
analogWrite (10, 200); // 78.4 % duty cycle
} // end of setup

void loop () { }

was able to change the PWM Prescaler by using show code then copy and pasting the above code into it and using arduino IDE to upload it.

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