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?
-------------------------------
PWM real and calculated freq
Moderator: Benj
-
- Posts: 367
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 45 times
- Been thanked: 63 times
- Contact:
PWM real and calculated freq
- Attachments
-
- ArdFreqSetUpNotRealFreq-1.jpg (77.29 KiB) Viewed 2982 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: PWM real and calculated freq
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 367
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 45 times
- Been thanked: 63 times
- Contact:
Re: PWM real and calculated freq
You right Ben
It is.
It is.
- Attachments
-
- warning_255+1.jpg (20.81 KiB) Viewed 2941 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: PWM real and calculated freq
ATMEGA328 PWM is not that controllable as Ben stated:
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.
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.
Martin