Page 1 of 1

Increasing PWM frequency on Arduino Uno for sumo bot — anyone done direct register manipulation?

Posted: Tue May 05, 2026 10:56 am
by jm_robotics
Bumubuo ng 1kg sumo bot for inter-college comp soon. Default Arduino

Code: Select all

analogWrite()
runs PWM at around 490Hz on most pins, kaya may audible whine yung motors namin. More importantly, hindi maganda ang ramp-up ng speed.

Alam ko kayang i-manipulate yung AVR timer registers directly —

Code: Select all

TCCR0B
,

Code: Select all

TCCR1B
,

Code: Select all

TCCR2B
— change yung prescaler, bump PWM up to 31kHz. Catch is each timer also drives

Code: Select all

delay()
and

Code: Select all

millis()
, so pag tinangal mo Timer 0, sira na yung timing functions mo.

Plan ko ngayon: gamitin yung Timer 1 (pins 9 + 10) for motor PWM, leave Timer 0 alone. Pero mawawala na yung

Code: Select all

analogWrite()
sa pins 9/10, kelangan i-write directly yung OCR values.

May nakapag-try na ba nito sa sumo or line-follower? Mainly:
  • Did the higher PWM frequency actually improve motor smoothness, or placebo lang?
  • Any L298N gotchas? Baka nga hindi ito tumatanggap ng PWM above 10kHz nang maayos.
  • Mas okay ba mag-Mega na lang for the dedicated timer pins?
Posting late kasi night testing namin. Reply niyo whenever, basahin ko bukas.

Re: Increasing PWM frequency on Arduino Uno for sumo bot — anyone done direct register manipulation?

Posted: Tue May 05, 2026 11:07 am
by tito_elmer
Dating embedded engineer dito. Ginawa ko ito noong AVR pa lang yung choice for hobbyists. Tama yung plan mo: Timer 1 for motor PWM, leave Timer 0 alone for delay/millis.

Things worth knowing:
  • Timer 2 free din for 8-bit PWM (pins 3 and 11). Less granular than Timer 1's 16-bit, pero kung 0-255 duty lang kelangan mo, OK na. Mas madali pa — walang OCR1A/OCR1B juggling.
  • Phase-correct vs Fast PWM mode — Phase-correct gives you ~half the frequency pero cleaner motor control (walang glitching at 0% and 100%). For motor control usually phase-correct yung gusto mo.
  • Frequency that matters — for brushed DC motors, 8-20kHz yung sweet spot. Higher than that, lugi ka sa switching losses ng L298N (BJT-based, slow yung switching).
Yung guess mo re: L298N + high PWM, tama. Above ~20kHz, yung BJT switching transitions take a meaningful fraction ng period at bumababa yung efficiency. 16kHz yung sinettle ko dati for hobby motor control.

Re Mega — sure pero hindi yan yung problem ng Uno. Same timer constraints kahit Mega. Sa code yung fix, hindi sa chip.

Re: Increasing PWM frequency on Arduino Uno for sumo bot — anyone done direct register manipulation?

Posted: Tue May 05, 2026 11:07 am
by sam_python
Sa C++/AVR register side, kabisado ni Tito. From the other side — kung gusto mong tuluyang umalis sa AVR timer Tetris, yung Pi Pico's PIO (Programmable I/O) lets you write hardware-level PWM at any frequency you want, walang timer manipulation kelangan.

Para sa sumo-bot context maybe overkill (invested ka na sa AVR for the comp). Pero next year's bot, worth a look. PIO is a tiny state machine na tumatakbo in parallel sa main cores — outputs precise PWM, reads encoders, drives WS2812 LEDs, walang CPU overhead.

Sa MicroPython, parang 4 lines yung syntax:

Code: Select all

from machine import Pin, PWM
pwm = PWM(Pin(15))
pwm.freq(20000)  # 20kHz, walang register hacking
pwm.duty_u16(32768)  # 50% duty
Yung native PWM API exposes lang what's possible. Worth knowing for your toolbox kahit hindi sa current bot.