The written PWM frequency is inconsistent with the actual measurement

I’m trying to control the camera’s XHS horizontal sync signal (changing the frequency from 83kHz to 86.31kHz) using PWM on an Orin NX device, but the XHS period and duty cycle I set are completely inconsistent with what I actually measured with an oscilloscope:

XHS_PERIOD_NS = 11586;
XHS_DUTY_NS   = 11007;

This is my environment:

$ uname -a
Linux agi 5.15.148-tegra #1 SMP PREEMPT Wed Jul 8 14:13:27 UTC 2026 aarch64 aarch64 aarch64 GNU/Linux

$ cat /etc/nv_tegra_release
# R36 (release), REVISION: 4.3, GCID: 38968081, BOARD: generic, EABI: aarch64, DATE: Wed Jan  8 01:49:37 UTC 2025
# KERNEL_VARIANT: oot
TARGET_USERSPACE_LIB_DIR=nvidia
TARGET_USERSPACE_LIB_DIR_PATH=usr/lib/aarch64-linux-gnu/nvidia

I reused the Orin NX pin as GP_PWM3:

GPIO14(PWM)/GPIO3_PX.03 --> GP_PWM3(pwm3)

PWM controller:

$ sudo cat /sys/kernel/debug/clk/pwm3/clk_parent
pllp_out0

Parent clock:

$ sudo cat /sys/kernel/debug/clk/pwm3/clk_possible_parents
pllp_out0 clk_32k clk_m
$ sudo ls -l /sys/kernel/debug/bpmp/debug/clk/pwm3
total 0
-r-------- 1 root root 0 Jan  1  1970 dvfs
-r-------- 1 root root 0 Jan  1  1970 dvfs_table
-r-------- 1 root root 0 Jan  1  1970 flags
drwxr-xr-x 2 root root 0 Jan  1  1970 fmon
-r-------- 1 root root 0 Jan  1  1970 hz_off
-r-------- 1 root root 0 Jan  1  1970 max_rate
-r-------- 1 root root 0 Jan  1  1970 min_rate
-r-------- 1 root root 0 Jan  1  1970 mrqcount
-rw------- 1 root root 0 Jan  1  1970 mrq_rate_locked
-rw------- 1 root root 0 Jan  1  1970 parent
-r-------- 1 root root 0 Jan  1  1970 possible_parents
-r-------- 1 root root 0 Jan  1  1970 pto_counter
-rw------- 1 root root 0 Jan  1  1970 rate
-r-------- 1 root root 0 Jan  1  1970 refcount
-rw------- 1 root root 0 Jan  1  1970 state
drwxr-xr-x 2 root root 0 Jan  1  1970 vdd_core
$ sudo cat /sys/kernel/debug/bpmp/debug/clk/pwm3/rate
22666667

pwmchip1 does indeed correspond to 32a0000.pwm, and the kernel does indeed accept period=11586 and duty=11007.

$ readlink -f /sys/class/pwm/pwmchip1/device
/sys/devices/platform/bus@0/32a0000.pwm
$ sudo cat /sys/kernel/debug/pwm
platform/39c0000.tachometer, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

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

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

platform/32a0000.pwm, 1 PWM device
 pwm-0   (sysfs               ): requested enabled period: 11586 ns duty: 11007 ns polarity: normal

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

 sudo grep -i pwm /sys/kernel/debug/clk/clk_summary
    pwm8                              0        0        0    19200000          0     0  50000         Y
    pwm2                              0        0        0    19200000          0     0  50000         Y
    pwm3                              1        1        0    22666667          0     0  50000         Y
    pwm7                              1        1        0   408000000          0     0  50000         Y
    pwm6                              0        0        0   204000000          0     0  50000         Y
    pwm5                              1        1        0   408000000          0     0  50000         Y
    pwm4                              0        0        0   204000000          0     0  50000         Y
    pwm1                              1        1        0     3187500          0     0  50000         Y
$ sudo find /sys/kernel/debug/bpmp/debug/clk \
    -maxdepth 1 -type d -iname '*pwm*' -printf '%f\n'
pwm8
pwm7
pwm6
pwm5
pwm4
pwm3
pwm2
pwm1

Because the ratio of the actual frequency to my target frequency is approximately 1.846.

159.37 ➗ 86.31 = 1.846

Therefore, I assume there is a frequency deviation of approximately 1.846 times, and set the period and duty cycle as follows:

PWM3_PERIOD_NS=21393
PWM3_DUTY_NS=20324

However, after modifying PWM3_PERIOD_NS=21393 and PWM3_DUTY_NS=20324, the frequency changed to 88.54kHz.

So I continued to increase PERIOD_NS and DUTY_NS. The measured frequency remained at 88.54kHz.

PWM3_PERIOD_NS = 21946;
PWM3_DUTY_NS   = 20849;

Could you please help me understand what this means? How do I modify it?

Thanks

Hi 2450732921,

Are you using the devkit or custom board for Orin NX?

Based on your posted pwm3/rate = 22666667, the measured 88.54 kHz exactly matches 22666667 / 256, which suggests the PWM is effectively running with PWM_DEPTH=255 and PFM=0.
That means this is not a fixed 1.846x deviation. If changing the requested period from 11586 ns to 21393 ns or 21946 ns still keeps the output at 88.54 kHz, then either the new PWM period is not actually taking effect, or the probed signal is not the real PWM3 output.
Please dump the readback values of period, duty_cycle, /sys/kernel/debug/pwm, and clk_rate immediately after each write.

Hello,

I’ve confirmed that the write cycle and duty cycle are working correctly, but I just can’t accurately generate the 86.31kHz I want.

Thanks for confirming. In that case, this is not a write/readback issue.

On Orin NX (Tegra234), PWM frequency is limited by the hardware divider design, so not every target frequency can be generated exactly. With your current PWM clock setting, 86.31 kHz is likely not an exactly achievable point, so the output can only land on the nearest supported frequency.

If an exact 86.31 kHz XHS is required, Tegra PWM may not be suitable and another clock source/generator would be needed.

Hello, thank you for your reply.

I would like to ask, on Orin NX (Tegra234), what does it mean that the PWM frequency is limited by the hardware divider design? How is it calculated?

On Tegra234, PWM frequency is generated by hardware dividers:

f_out = clk_rate / ((1 + PWM_DEPTH) * (1 + PFM))

Here, PWM_DEPTH is fixed at 255 and PFM is an integer divider, so the output frequency can only move in discrete steps, not to any arbitrary value.

With your current pwm3 clk_rate = 22666667 Hz, the output becomes 22666667 / 256 = 88.54 kHz when PFM = 0, which matches your measurement. So 86.31 kHz is simply not an exactly achievable frequency with the current PWM clock setting.

Can we modify the PFM integer divider? If so, what are the limitations of such modifications?

Yes. PFM is the integer divider programmed by the driver.

On Tegra234, PWM_DEPTH is fixed at 255, and PFM is a 13-bit integer (0~8191), so the output frequency can only change in discrete steps. If the requested period needs PFM beyond that range, the driver will reject it with -EINVAL.

I apologize for bothering you again, but I still have a few questions:

1. What is the directory of the source file for modifying PFM variables?

2. Is clk_rate=22666667 Hz fixed? If it can be modified, what is the directory of the source file to be modified? Are there any restrictions on modifications?

I am very much looking forward to and grateful for your reply.

PFM is not a standalone DT variable on Tegra234.
It is calculated/programmed by drivers/pwm/pwm-tegra.c at runtime based on the requested period.
If you want to change the PFM selection logic, please check that driver.

clk_rate=22666667 is also not a universal fixed value; it depends on the selected parent clock.
For PWM3 on Tegra234, only supported parent clocks can be used, and the driver sets the selected parent to its supported max rate at probe time, so it is not usually an arbitrary value you can tune freely.

Is drivers/pwm/pwm-tegra.c also the driver file for clk_rate configuration? I want to configure its parent clock, Is this the file? Does it support configuration? Or does the hardware support modification?

drivers/pwm/pwm-tegra.c is the PWM driver, but the parent clock is normally selected through the PWM node in DTS using assigned-clock-parents, not by directly editing a clk_rate variable in that driver.

For Tegra234 PWM3, the supported parent clocks are limited to PLLP_OUT0, CLK_M, and CLK_32K, so yes, configuration is supported, but only within those hardware-supported choices.

Also, the driver forces the selected parent clock to its maximum supported rate at probe time, so if you need a rate outside those supported parent/rate combinations, that is a hardware/clock-tree limitation rather than a simple PWM driver change.

Are you using Orin or Thor?
You mentioned Orin NX(T234) in original post but this snippet is the configuration for Thor(T264).

I’m using Orin NX; I only took screenshots from the Thor project.

  1. Could you please tell me the maximum speeds of the parent clocks PLLP_OUT0, CLK_M, and CLK_32K supported by the Tegra 234 PWM3? If I were to modify them, could I arbitrarily change them at the maximum speed, or are there fixed steps?

  2. Because the XVS/XHS signals output by Orin are not edge-aligned, we want to manually calibrate them in the driver, compensating for the measured fixed time offset. Is this supported? Is it also done by modifying the drivers/pwm/pwm-tegra.c file?

I look forward to your reply and thank you very much.

Please note that Orin NX and Thor are the different and have their own pwm nodes/addresses.

For Tegra234 PWM3, the supported parent clocks are PLLP_OUT0 (~408 MHz), CLK_M (~19.2 MHz), and CLK_32K (32768 Hz).
You can select the parent in DTS, but the driver sets the selected parent to its max supported rate at probe time, so it is not typically a freely tunable arbitrary `clk_rate` in `drivers/pwm/pwm-tegra.c`.
The final PWM output is still limited to discrete divider steps because Tegra234 uses fixed PWM_DEPTH=255 plus integer PFM division.

For XVS/XHS offset compensation, I do not see a documented phase-alignment control in the public Tegra234 PWM documentation; only frequency/duty update at boundary is described, so this is not a standard supported PWM-driver calibration feature from what we can see.