Page 1 of 1

PWM real and calculated freq

Posted: Thu Oct 01, 2020 8:01 am
by viktor_au
Hello
PWM real and calculated frequency question.
When I setup (for Nano)
Chn 1, Timer 0 as suggested for freq: 30kHz
by calculation section:
Period - 81
Prescale - 8
FC8 shows - 30kHz
The scope shows: 3.906kHz
------------------------------------
When I change the Period to 111 and Prescale to 1
(photo below)
the freq is 31.25kHz
---------------------------------
PS The scope probe is 1x
---------------------------------
What do I do wrong?
-------------------------------

Re: PWM real and calculated freq

Posted: Thu Oct 01, 2020 12:52 pm
by Benj
Hello,

When compiling do you get a warning that the period register is unavailable on the device?

If so where you have the period set to 111 it's actually set to 256 as the hardware doesn't have the ability to change the period.

Re: PWM real and calculated freq

Posted: Thu Oct 01, 2020 10:23 pm
by viktor_au
You right Ben

It is.

Re: PWM real and calculated freq

Posted: Thu Oct 08, 2020 10:08 pm
by viktor_au
Any idea please?

Re: PWM real and calculated freq

Posted: Fri Oct 09, 2020 8:14 am
by medelec35
ATMEGA328 PWM is not that controllable as Ben stated:
Benj wrote:
Thu Oct 01, 2020 12:52 pm
it's actually set to 256 as the hardware doesn't have the ability to change the period.
The only thing you can do is make sure in the PWM Properties, Apply is set to NO in the calculations.
This will allow you to manually change prescale.
Set the period to 255(for indication only will not change hardware frequency)
Then actual frequency will be half of the indicated frequency of frequency_calc2.
E.g prescale is 64 & frequency_calc2 shows 976.562500 then PWM of hardware will run at about 488Hz
Reason requency_calc2 is showing double is you can't period to 256.
So for 31KHz just set prescale to 1.

Re: PWM real and calculated freq

Posted: Fri Oct 09, 2020 10:31 pm
by viktor_au
Thank you medelec35

Will try