Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

About DCValue in setPWM_manual #2

Answered by khoih-prog
laflaf3d asked this question in Q&A
Discussion options

You must be logged in to vote

HI @laflaf3d

It's good that you've done some tests and now I can explain more what's wrong in your assumption and code

  1. The minimum frequency for PWM depends on the resolution (8 or 16-bit => 256 or 65536) of the Timer you're using. In this case of pin 9 or 10, Timer 1 is 16-bit timer (65536 resolution). The min PWM freq. for UNO/Nano with 16MHz clock is 16,000,000 / 65,536 = 244.140Hz

Your use of freq = 60.0f is wrong, and some other freq is used by using the wrong overflowed data => random 480.0192 Hz as you saw. You can calculate yourself and see why and how 480.0192Hz is used as an exercise to master the PWM

If you'd like to use low-frequency PWM, use my AVR_Slow_PWM library

  1. The PWM…

Replies: 6 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@laflaf3d
Comment options

Comment options

You must be logged in to vote
1 reply
@laflaf3d
Comment options

Answer selected by laflaf3d
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1 on January 19, 2023 00:37.