Using PWM_D on VIM2

Hi!
I am trying to use PWM (pin 35 - PWM_D) on VIM2. I follow instructions from docs https://docs.khadas.com/vim2/HowToUseHardwarePWM.html except for using “pwmchip4”.
As result I type:
root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip0/export
root@Khadas:~# echo 1000000 > /sys/class/pwm/pwmchip0/pwm1/period
root@Khadas:~# echo 500000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable
But I don’t see PWM meander on pin 35.
What I do wrong?

Hello @parumsancto

Which image you used to test ?

@Frank Help to check this issue.

VIM2_Ubuntu-xfce-bionic_Linux-4.9_arm64_EMMC_V20190830

@parumsancto Ihave test it just now . It work fine . Maybe you should use the least release firmware

https://dl.khadas.com/Firmware/VIM2/Ubuntu/EMMC/VIM2_Ubuntu-xfce-bionic_Linux-4.9_arm64_EMMC_V20191231.7z

and check with those command

khadas@Khadas:~$ fdtget /boot/dtb/kvim2_linux.dtb /pwm@c1108640 status
okay  
khadas@Khadas:~$ fdtget /boot/dtb/kvim2_linux.dtb /pwm@c11086c0 status
okay 
2 Likes

OK, I install VIM2_Ubuntu-xfce-bionic_Linux-4.9_arm64_EMMC_V20191231.img.
Then enable pwm@c1108640

root@Khadas:~# fdtput -t s /dtb.img /pwm@c1108640 status okay

and reboot.
After that

root@Khadas:~# fdtget /boot/dtb/kvim2_linux.dtb /pwm@c1108640 status
okay
root@Khadas:~# fdtget /boot/dtb/kvim2_linux.dtb /pwm@c11086c0 status
okay

Then I try:

root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip4/export
root@Khadas:~# echo 1000000 > /sys/class/pwm/pwmchip4/pwm1/period
root@Khadas:~# echo 500000 > /sys/class/pwm/pwmchip4/pwm1/duty_cycle
root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip4/pwm1/enable

but nothing changed - no meander on pin 35!

@parumsancto not /sys/class/pwm/pwmchip4 , it’s /sys/class/pwm/pwmchip0

root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip0/export
root@Khadas:~# echo 1000000 > /sys/class/pwm/pwmchip0/pwm1/period
root@Khadas:~# echo 500000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable

No meander.

Is it normal?

gpio pwm 18 512
warn : (pwmWrite):THis function is not supported by KHADAS Board.

Command “gpio write [pin] [1\0]” works normal.

Are your physical pins surely connected? I have test it yesterday, It work fine . How did you confirm whether it took effect ?

I was connected an oscilloscope to pins 40 and 35. And in parallel was connected LED through resistor (200 Ohm).
After “echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable” no meander on oscilloscope and LED don’t light. If connect anode to pin 20 (not 35) then LED light britely.

@parumsancto You can’t see the light flickering at this frequency, you should only connect an oscilloscope to view.If you can’t adjust the parameters of the oscilloscope, you can use the auto mode

Yes, but I can see different brightness on different duty cycle. Now I see nothing: no light and no meander on oscilloscope.
What other ways to control PWM_D pin?

@parumsancto

root@Khadas:/home/khadas# echo 1 > /sys/class/pwm/pwmchip0/export 
root@Khadas:/home/khadas# echo 1000000 > /sys/class/pwm/pwmchip0/pwm1/period
root@Khadas:/home/khadas# echo 500000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
root@Khadas:/home/khadas# echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable

Did you follow my steps to test ?

1 Like

I do same.



@parumsancto Do your oscilloscope and the board share the same GND?

Yes. I can see some signals on other pins, but not on pin 35.

@parumsancto Have you made any changes to the board? Except for the hardware problem, I can’t think of other reasons

No. I just install VIM2_Ubuntu-xfce-bionic_Linux-4.9_arm64_EMMC_V20191231.img via USB_Burning_Tool_v2.2.0, then boot to ubuntu, connect via ssh, tunrn on pwm “fdtput -t s /dtb.img /pwm@c1108640 status okay”, reboot and do Using PWM_D on VIM2 - #13 by parumsancto

I’ll get a new one VIM2 in a couple of weeks. I’ll try the same actions on new one board.
Is there any way to control PWM_D pin width wiringPI library functions?

@parumsancto
https://mega.nz/file/595DFQaC#WGV7v8NPGQrkJVJIFAt9lD64yYHBu45fbEYa4qYJINw
Can you download this deb package and install , then try again after reboot .

Upload linux-dtb-amlogic-4.9_0.9.2_arm64.deb to /home/khadas and install

root@Khadas:/home/khadas# dpkg -i linux-dtb-amlogic-4.9_0.9.2_arm64.deb
(Reading database … 108291 files and directories currently installed.)
Preparing to unpack linux-dtb-amlogic-4.9_0.9.2_arm64.deb …
Unpacking linux-dtb-amlogic-4.9 (0.9.2) over (0.8.1) …
Setting up linux-dtb-amlogic-4.9 (0.9.2) …
root@Khadas:/home/khadas# reboot now

Trying use PWM_D

root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip0/export
root@Khadas:~# echo 1000000 > /sys/class/pwm/pwmchip0/pwm1/period
root@Khadas:~# echo 500000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable

and I see


Trying change duty cycle

root@Khadas:~# echo 800000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle

Looks like working.

2 Likes