PWM real and calculated freq

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
viktor_au
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

Post 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?
-------------------------------
Attachments
ArdFreqSetUpNotRealFreq-1.jpg
ArdFreqSetUpNotRealFreq-1.jpg (77.29 KiB) Viewed 2982 times

User avatar
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

Post 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.

viktor_au
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

Post by viktor_au »

You right Ben

It is.
Attachments
warning_255+1.jpg
warning_255+1.jpg (20.81 KiB) Viewed 2941 times

viktor_au
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

Post by viktor_au »

Any idea please?

medelec35
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

Post 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.
Martin

viktor_au
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

Post by viktor_au »

Thank you medelec35

Will try

Post Reply