Using PCNT and MCPWM from arduino (for motor control with encoder)

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Using PCNT and MCPWM from arduino (for motor control with encoder)

Postby Greg Corson » Tue Jun 05, 2018 4:43 pm

I'm a little confused about using ESP32 APIs from Arduino. I am trying to control two brushed DC motors and read their quadrature encoders so I can sense the speed/movement of the motors. I've seen all kinds of posts about using either the PCNT or MCPWM hardware on ESP32 to do this, but no discussion about how to use these from Arduino.

I guess I'm generally a bit confused about if I can directly call ESP32 APIs from Arduino or if there has to be a special library setup?

If anyone can give me a hand here or point me to an example it would be very helpful. I already have the motor drive working using the LEDPWM calls. I need a way to get the encoders read now. If there is a way to move it all to the MCPWM hardware that would be great.

To be specific, what I'm stuck on is how to use ESP32 hardware to read the quadrature encoder outputs (2 per motor) and implement a counter that counts up/down as the motor rotates forward/reverse. This is a 300rpm gearmotor but the encoder is attached before the gearbox, so I am probably getting at least 150 counts/second at full speed.

Who is online

Users browsing this forum: Bing [Bot] and 93 guests