Page 2 of 2

Re: Pulse counter support

Posted: Thu Aug 01, 2019 8:40 pm
by OutoftheBOTS_
pidou46 wrote:
Thu Aug 01, 2019 5:53 am
It seems able to handel encoders: ... /pcnt.html
- it count rising and/or falling edge
- a filter can be set to avoid glinches
- up to 8 counter are availables, not as much as STM32, but it enable quite sophisticated projects.

But now the hardest part is how to bring it to esp32 micropython port ?
My C skills dates from ages, and I have no idea where to start with ? I guess setting up a toolchain (GCC, ESP-IDF, ect...)
Is there somewhere a tutorial or even a sample of ported fonctionality ?
Thanks for the link to the info. The info isn't detailed but from what I read it won't read an quadrature encoder. It does have a 2 pin mode but from what I can gather it works by 1 pin is the counter pin and the other pin is a direction pin (something like a stepper motor driver). A quadrature encoder works differently were both pins are counter pins but depending on the order of the rising and falling of the 2 pins whether it is counting up or down.

The PCNT would be great to have added for reading single channel encoder but not sure if it will be capable of reading a quadrature encoder

see STM32F407 encoder mode that is capable of both single and quadrature encoders ... %2Cnull%5D

Re: Pulse counter support

Posted: Sat Aug 03, 2019 6:55 am
by OutoftheBOTS_
If you really want to use ESP and need to count a number of Quadrature encoders then you might be interested in this ... /LS7366RSh it has 6 32bit quadrature counters and is read by SPI. It is an ardunio shield made by the manufacturer of the LS7366R chip

Re: Pulse counter support

Posted: Wed Dec 04, 2019 8:14 am
by elliotwoods
Hah interesting
I was looking into this exact same thing today.
I implemented to C side of things: ... master/src

Now I'm looking into making it a MicroPython module for my own use

To note : you can use the ESP32's hardware counter.
It works perfectly.
If A rises high and B is low, count up
If A rises high and B is high, count down

Look at the states of A and B to get an 'addition factor' to multiply your resolution by 4 (check Encoder.cpp at link above)

Re: Pulse counter support

Posted: Tue Dec 24, 2019 9:57 am
by pidou46
Hi elliotwoods,

Did you complete the python side ?

I think you are really close to bring this functionality to MP.
If you can post it here, maybe someone (maybe me) would be able to implement it in esp32 branch in time for 2.0 release ?

Anyhow, thanks to have shared.

Re: Pulse counter support

Posted: Tue Dec 24, 2019 11:54 pm
by mcauser
Here's how I attempted to add the SigmaDelta peripheral: ... 5452/files
It's a very simple peripheral, but shows you the pieces needed.

The Pulse Counter peripheral is much more complex. ... /pcnt.html
It uses interrupts, so might be able to pinch some code from: ... ne_timer.c

Something I'm going to look into further after the holidays.

Re: Pulse counter support

Posted: Mon Feb 03, 2020 11:39 am
by sengp

micropython already supports interfacing to quadrature encoded signals, e.g. rotary encoders, based on the pulse counter unit available on ESP32.
See: ... er/1509/20

My software (polling) and pin interrupt based approaches to implement a rotary encoder interface on the ESP32, all failed. But this hardware based approach works very well when on rotary encoders like e.g. ALPS EC11 or BOURNS PEC11L.

Have fun :),