2
\$\begingroup\$

I have a PWM pin that is configured to be at 40Khz but I am seeing it bounce around in my oscilloscope. It would read 40.045KHz and bounce ~ +/- 4Hz or so.

I have another module that is using Atmel MCU that is consistently(No bouncing/jittering) outputting PWM at 39.999Khz so I feel like the oscilloscope i'm using is not the problem.

I am Using internal clock(HSI) at 16MHz
Prescaler = 0
ARR = 399
TIM16->CC1 = 200 // ~50% duty cycle

Is there a way to make the PWM output frequency to be consistent?

Any help/feedback is appreciated.

enter image description here

brhans
15.1k3 gold badges37 silver badges51 bronze badges
asked Feb 16, 2023 at 2:24
\$\endgroup\$
2
  • 1
    \$\begingroup\$ The internal RC oscillator (HSI) may not be that stable or accurate. Use HSE, the external crystal oscillator instead \$\endgroup\$ Commented Feb 16, 2023 at 3:48
  • \$\begingroup\$ Thank you so much @RussellH. The external crystal oscillator works way better. \$\endgroup\$ Commented Feb 16, 2023 at 17:17

1 Answer 1

2
\$\begingroup\$

The datasheet defines HSI frequency in range 15.88-16.08MHz, or 0.5-0.75%. On top of that - temperature drift can be up to 2%. Observed error is about 0.1%, which is quite good. Keep in mind that under a different conditions the error might get much worse.

To minimize frequency error, you can use an external crystal oscillator, as RussellH proposed.

If the design can tolerate frequency errors about 0.3% and there is some external reference frequency, you can try to utilize HSI frequency trimming function. But single step here is about 0.3%, thus HSI trimming can help to keep frequency error within this step, but not better.

enter image description here

answered Feb 16, 2023 at 6:23
\$\endgroup\$
1
  • \$\begingroup\$ Thank you so much. That actually makes so much sense. I totally overlooked my clock configuration. \$\endgroup\$ Commented Feb 16, 2023 at 17:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.