How to generate Precision PWM at 500kHz

Hello Ladies and Gentlemen,

I need to use a precision PWM output of 500khz from one of the pwms.
I was checking with the existing pwms exposed at userspace /sys/devices/32xxxpwm/

I set the period to 2000 ns and dutycycle to 1000ns which i expect PWM at 500k.
But the output is 533.3khz.

The small details in the datasheet also gives this formula :
Required frequency = (408M / 256) / (1 + PFM_0) = 150 kHz / (1 + PFM_0)
500 = 1600/(1+PFM_0)
PFM = (1600 / 500 ) - 1
PFM = 2

reusing the formula
freq = 1600/(1 + 2) = 533.3khz

Please dont tell me that such a powerful soc cannot precisely generate 500khz

Can anyone help me set the precise 500k pwm output?

Thanks

hello balchandracs010,

you should change the source clocks.

please access Xavier TRM from download center,
you may refer to Chapter-10.7 Pulse Width Modulator (PWM), and please check [10.7.2 Programming Guidelines] for more details.
thanks

Hi JerryChang,

Thanks for your response!!.

Let me put here what i got from that 10.7 section of the Xavier TRM manual.

There are only two clocks to chose from :
38.4Mhz or 408Mhz

first using the 408Mhz as input clock:
Required frequency = (408M / 256) / (1 + PFM_0) = 1.6MHz / (1 + PFM_0)
500 = 1600/(1+PFM_0)
PFM = (1600 / 500 ) - 1
PFM = 2
With the obtained PFM, recalculating the freq,
reusing the formula
freq = 1600/(1 + 2) = 533.3khz

If 38.4M is chosen as the clock :
Required frequency = (38.4M / 256) / (1 + PFM_0) = 150 kHz / (1 + PFM_0)
500 = 150/(1+PFM_0)
PFM = (150 / 500 ) - 1
PFM = -1

which is not possible.
Only choice is to use 408M which can only give certain freq.
because the 1.6M is divided by (1+PFM) can only give certain numbers like 1.6M, 800khz, 533.k, 400k etc

Is my understanding wrong somewhere?

hello balchandracs010,

did you probe the signaling? I’m wondering how you check and found the output is 533.3khz.
could you please also share the PWM status for reference,
for example,
$ sudo cat /sys/kernel/debug/pwm

I am attaching the screenshot of logic analyser that captured the waveform which is showing 533khz.

For the other thing:
sudo cat /sys/kernel/debug/pwm
platform/39c0000.tachometer, 1 PWM device
pwm-0 (generic_pwm_tachomet): requested period: 0 ns duty: 0 ns polarity: normal

platform/32f0000.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: normal

platform/32d0000.pwm, 1 PWM device
pwm-0 (pwm-fan ): requested enabled period: 45334 ns duty: 23020 ns polarity: normal

platform/32c0000.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: normal

platform/c340000.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: normal

platform/3280000.pwm, 1 PWM device
pwm-0 (sysfs ): requested enabled period: 2000 ns duty: 1000 ns polarity: normal

i am using the 3280000 pwm

Sorry, i am not able to attach screenshot here. But i have verified using the oscilloscope that it is 533khz. edit -Now i am able to attach.
Please refer the channel 0 data on the screenshot