How to program PWM frequency (period) for Apalis T30?

Dear team,

With pointers from High performance, low power Embedded Computing Systems | Toradex Developer Center we can test the duty cycle on PWM using the provided method.

Could team please share some pointers how can we configure the frequency for PWM_1 & PWM_2 ?

We can test the duty cycle using the default setup.

We aim to get an PWM signal of 24KHz with pulse width of 2uSec.

Thanks,

Ashish Kumar Mishra.

For T30 you’ll have to modify kernel.

Look for static struct tegra_i2c_platform_data apalis_t30_i2c*_platform_data in:

<kernel_src>/arch/arm/mach-tegra/board-apalis_t30.c

field bus_clk_rate specifies frequency.

Sorry, I guess @dominik.tx mixed up I2C and PWM. He was correct about having to modify the kernel sources but it would be the following structure. Information about how to compile/deploy may be found here.

Thanks for pointers Marcel & Dominik , i am using above mentioned pointers
Will share the update

Thanks ,

Ashish Kumar Mishra.

Dear Team ,

Please note that the frequency of PWM doesn’t change evenafter changing the .pwm_period_ns

Below is the observation :-

a) PWM_1
Value configured by .pwm_period_ns = 41666 (as per our requirement of 24KHZ)
Observed frequency on pin was 12.35KHZ

b) PWM_2
Value configured by .pwm_period_ns = 19600 (default of 51KHZ)
Observed frequency on pin was 12.20KHZ

c) With uname-a & changing default max-brightness parameter i verified the the kernel running is the latest

Concluding , i observe an frequency of 12.2KHZ on PWM , ir-respective of the pwm_period_ns value set on board file of apalis T30

Attached here is the relevant snapshots
alt text
alt text

Thanks
Ashish Kumar Mishra.

Dear Team ,
Any inputs or pointers on same.

On parallel i am planning to look at the driver code of led today.
Thanks
Ashish Kumar Mishra.

On current kernel 12.45kHz is a maximum PWM frequency. You can increase it to ~100kHz with this patch http://git1.toradex.com/cgit/linux-toradex.git/commit/?h=tegra-next&id=f7ba7321464f68293d47223f53a7211ff0d9ec10

Thanks Dominik …will apply the patch & share the result.

Dear Dominik ,

The patch works & we are getting the changes on the PWM.

Could you please let me know if there is any internal round-off / adjustment of the value being passed because for 24KHZ we got value of 41666.66ns .

I had configured .pwm_period_ns = 41666 & on CRO we are getting 24.9KHZ

(Also i am not sure of option to mark comment as solution hence writing separately below to help any member going ahead )
Thanks
Ashish Kumar Mishra

The path provided by dominik solve the problem ( of PWM frequency being fixed to 12KHZ)

Thank You,
Ashish Kumar Mishra

This is how pwm clocking works on T30:

We’re starting with 408MHz PLL_P clock that can be divided my N (N has a 0.5 resolution) to pwm input clock (in my patch N=16 for 25.5MHz, minimum value of N that can be used with pwm peripheral is 8.5 for 48MHz clock)
pwm input clock is divided by 256 giving base pwm clock (99.6kHz) this clock is divided by M (M is always an integer so 1,2,3,4…) that gives 99.6 kHz, 49.8kHz, 33.2kHz, 24.9kHz…
As you can see 24.9kHz is an expected value in this case.
If you require very specific frequency it can still be possible to get it modifying pwm peripheral clock.
For example you can get 24.15kHz with N=22 (18.55) and M=3 (M is calculated automaticaly from period). And probably even closer to 24kHz with other values