# Arduino Mega PWM Frequency Change

**URL:** <https://forum.xod.io/t/arduino-mega-pwm-frequency-change/4226>\
**Category:** Uncategorized\
**Created:** [July 16, 2020, 2:40pm UTC](https://forum.xod.io/t/arduino-mega-pwm-frequency-change/4226 "2020-07-16T14:40:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnaride](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@magnaride](https://forum.xod.io/u/magnaride)\
**Post date:** [July 16, 2020, 2:40pm UTC](https://forum.xod.io/t/arduino-mega-pwm-frequency-change/4226/1 "2020-07-16T14:40:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![magnaride](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@magnaride](https://forum.xod.io/u/magnaride)\
**Post date:** [July 16, 2020, 4:19pm UTC](https://forum.xod.io/t/arduino-mega-pwm-frequency-change/4226/2 "2020-07-16T16:19:09Z")

</div>

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 () { }

---

<div class="post-metadata">

**Author:** ![magnaride](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@magnaride](https://forum.xod.io/u/magnaride)\
**Post date:** [July 17, 2020, 9:18pm UTC](https://forum.xod.io/t/arduino-mega-pwm-frequency-change/4226/3 "2020-07-17T21:18:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [July 19, 2020, 9:18pm UTC](https://forum.xod.io/t/arduino-mega-pwm-frequency-change/4226/4 "2020-07-19T21:18:40Z")

</div>

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