I have just installed the grinch 19.3.8 kernal on my Jetson board and got PWM to work. I can modify the period and duty cycle of the PWM pin just fine but I am interested in figuring out how many pulses have actually been outputted so that I can tell the position of a stepper motor with some decent accuracy. Knowing the number of pulses that have occurred is important because one pulse may be equal to 1 degree of rotation for the stepper motor as an example. Does anyone have any idea as to a function or library that would allow me to do this? I have considered keeping time with a clock function but this does not seem like the best way of doing things. Any help is appreciated.
When we use pwm, the output is continuous with frequency of 1/period and pulse time is duty cycle * period_time/100. Are you referring to one period PWM signal? Suppose we have 1ms pwm period, we will have 1KHz PWM signal at output. As this is continuous, there is no mechanism to know how any pulses going by accurately.
I have never found the PWM counter register in NVIDIA TRM, so I take the interrupt routine of GPIO_PU5 to count how many pulse was generated. You can take a try to loop-back PWM0(PIN49 of J3A2) to GPIO_PU5(PIN55 of J3A2) then apply the two patch on 21.2 (https://drive.google.com/folderview?id=0B_gyM-9kR2Qjfnh0U0ZoNkJ3WkE1Zmg4YWZJakJYUzJ6TjBuVGU3ZFVLQ0xQRnhoUWpOajQ&usp=sharing). This is not very accurate, because of the GPIO interrupt latency. Maybe the accuracy is sufficient to your control system. Do you want to take the pulse count to be the feed back signal in close loop control system? What is the sampling rate in your system?
Here is an example in 100 pulse per second.
sudo su
echo 163 >/sys/class/gpio/export
echo out >/sys/class/gpio/gpio163/direction
echo 1 >/sys/class/gpio/gpio163/value
echo 0 >/sys/class/gpio/gpio163/value
echo 163 >/sys/class/gpio/unexport
cd /sys/class/pwm/pwmchip0
echo 0 >export
echo 10000000 >pwm0/period
echo 5000000 >pwm0/duty_cycle
echo 1 >pwm0/enable
I tried to to enable the pwm modules by looking at the examples and removing the GPIO pins as well us adding the pinmux pwm0, pwm2 and pwm3 as told in “Jetson/PWM - eLinux.org”