VoCore2 has four PWM port, so with GPIOs, we can drive up to four motors or two stepper motors.
The picture shows the four ports.
To use PWM2, PWM3, we need switch this pin group from “uart2” to “pwm”, I have added this to github vocore2 patch.
PS: I use uart2 as console port, but not this group, so no conflict. This group named “uart2” but my real UART2 is using group “spis”, this is defined in Linux kernel source in arch folder, search mt7620.c
And we also need necessary driver for pwm port, openwrt already have it. We just need to select it from openwrt menuconfig => Kernel modules => Other modules => kmod-pwm-mediatek-ramips.
Now everything require for firmware is ready. Latest firmware (>20190624) already have pwm support.
Now we can try PWM, for example, I use PWM3 as output.
echo 3 > /sys/devices/platform/10000000.palmbus/10005000.pwm/pwm/pwmchip0/export
/sys/devices/platform/10000000.palmbus/10005000.pwm/pwm/pwmchip0/, you will find a new folder named “pwm3”, in it, there are some files.
root@OpenWrt:/sys/devices/platform/10000000.palmbus/10005000.pwm/pwm/pwmchip0/pwm3# ls capture duty_cycle enable period polarity uevent
‘duty_cycle’ is how much high in one period, and ‘period’ is the time of one period, from my test, period unit is 1ns. and its value range is 10000~100000(10K~100KHz), ‘enable’ is use to enable PWM output, these three interface are enough to control simple PWM wave.
echo 10000 > period echo 5600 > duty_cycle echo 1 > enable
PS: its output is exactly 5.6us, just this analyzer do not good enough to show that. 🙂
To be continue…