PWM counter?? #12201
Replies: 5 comments 19 replies
-
There are a few pull requests outstanding which implement a counter for the ESP32. None of them is merged yet. Until then you could connect the PWM output to another Pin and use Pin.irq() to count pulses in a handler called by a transition at that pin. That should work up to a frequency of about 1 kHz. |
Beta Was this translation helpful? Give feedback.
-
Probably not. |
Beta Was this translation helpful? Give feedback.
-
I'm just curious. Why are you using the PWM output to generate N pulses ? It can't be too complicated to generate (and count) pulses on the GPIO output, either from a python function or using other means - the ULP processor comes to my mind. |
Beta Was this translation helpful? Give feedback.
-
Thanks everyone, I have many things I can try now. You guys are super helpful. |
Beta Was this translation helpful? Give feedback.
-
Another idea appeared: The PWM uses a prescaler and a counter base value to achieve the desired frequency. You might use an ordinary timer channel that uses the same prescaler (or a multiple of its value) and a counter base that also hase the same or better a multiple value of the PWM counter base. This way you have synchrony between the PWM and the timer up to multiplicity. In the case of multiplicity your interrupts can better cope with the high PWM frequency. |
Beta Was this translation helpful? Give feedback.
-
I wrote a program to drive a stepper motor. Every pulse on the PWM pin moves the motor one step. Is there a way to count the total number of pulses the I generated so that I can know the exact position? If not, I can estimate using some math. The chip I am using is the ESP32-D4-PICO. Thanks in advanced!
Beta Was this translation helpful? Give feedback.
All reactions