How does timer encoder mode work?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: How does timer encoder mode work?

Post by mattyt » Tue Jul 04, 2017 11:10 pm

Not sure if you're using the timers to interface to a Rotary Encoder but, if so, I've found Spotlight Kid's Encoder library works great...

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How does timer encoder mode work?

Post by pythoncoder » Wed Jul 05, 2017 10:49 am

[quote="evidlo"]I modified the code as pythoncoder said and tested successfully with a quadrature encoder...[/url]

If you've no objection I'll update the original to reflect these changes which should provide portability to any MicroPython platform.
Peter Hinch
Index to my micropython libraries.

evidlo
Posts: 5
Joined: Tue Jul 04, 2017 5:47 pm

Re: How does timer encoder mode work?

Post by evidlo » Fri Jul 07, 2017 2:16 am

pythoncoder wrote:If you've no objection I'll update the original to reflect these changes which should provide portability to any MicroPython platform.
That's fine.

I've also discovered an issue. It seems the callback routine is around 800μs, which is a bit too slow for my application and is causing me to lose counts.

Here is the scope view of one of my magnetic encoder pins:

http://i.imgur.com/vB9ofHb.png

Also, I've seen other people use code tags, but they don't seem to work for me. Is there some way to turn BBcode on?
Last edited by evidlo on Sat Jul 08, 2017 10:09 pm, edited 1 time in total.

evidlo
Posts: 5
Joined: Tue Jul 04, 2017 5:47 pm

Re: How does timer encoder mode work?

Post by evidlo » Fri Jul 07, 2017 2:36 am

mattyt wrote:Not sure if you're using the timers to interface to a Rotary Encoder but, if so, I've found Spotlight Kid's Encoder library works great...
Callback function here takes also close to 800μs and I'm seeing similar results.
Last edited by evidlo on Sat Jul 08, 2017 10:09 pm, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How does timer encoder mode work?

Post by pythoncoder » Fri Jul 07, 2017 4:46 am

I think the problem you're hitting here is the interrupt latency of the ESP8266 which is frankly appalling. See https://github.com/micropython/micropython/issues/2972.

This will limit the performance of any solution as far as I can see.

[EDIT]
I've posted your modification here https://github.com/peterhinch/micropyth ... ortable.py. I made one change to ensure that setting the position and reading it back are mutually consistent. I also removed my reset method as this is made redundant by the position setter.
Peter Hinch
Index to my micropython libraries.

evidlo
Posts: 5
Joined: Tue Jul 04, 2017 5:47 pm

Re: How does timer encoder mode work?

Post by evidlo » Sat Jul 08, 2017 10:06 pm

I think the problem you're hitting here is the interrupt latency of the ESP8266 which is frankly appalling.
Does this still apply to the ESP32?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How does timer encoder mode work?

Post by pythoncoder » Sun Jul 09, 2017 5:32 am

Peter Hinch
Index to my micropython libraries.

Post Reply