Skip to content

Conversation

BerranRemzi
Copy link

@BerranRemzi BerranRemzi commented Sep 6, 2025

Problem

analogWrite() on CH32V003 produces occasional glitches when updating the PWM duty cycle. Changes take effect mid-cycle, rather than at cycle boundaries.

Solution

Enable timer preload registers (shadow registers) for PWM channels to synchronize compare value updates with timer overflow events.

Changes

  • Enable TIM_OCPreload_Enable for timer channels in PWM mode
  • Ensures duty cycle updates only take effect at start of next PWM cycle
  • Prevents mid-cycle glitches during analogWrite() calls

Fixes: #223

Enable shadow registers for timer compare values to ensure updates
only takes effect at timer overflow, preventing mid-cycle glitches
in PWM and other output compare modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant