-->
Page 1 of 1

Accurate GPIO timing

PostPosted: Tue Sep 29, 2015 2:29 pm
by Lotus
Hello,

I still haven't been able to get this answered:

Is there a way for instance to deterministically set a GPIO output level e.g. 10 times a second without any interruptions?

Re: Accurate GPIO timing

PostPosted: Tue Sep 29, 2015 3:11 pm
by dkinzer
Lotus wrote:Is there a way for instance to deterministically set a GPIO output level e.g. 10 times a second without any interruptions?
The short answer is "no". The longer answer is more complicated.

The ESP has non-maskable interrupts. I don't know what part of the system uses them - perhaps the network interface. At any rate, unless you prevent non-maskable interrupts from occurring you will always have a possibility that your exquisitely planned timing will be disrupted. I have seen discussion of a technique to disable non-maskable interrupts but I haven't used it.

That said, you can still get pretty good accuracy and repeatability by configuring the RTC Timer1 to generate a periodic interrupt and then use the direct port manipulation registers to set/clear bits in the ISR. There will still be some interrupt latency that will introduce jitter in your timing but, depending on the application, it may be acceptable. If you look at the software PWM example code in earlier SDKs (v1.01 b2 and earlier) you can see how to use the RTC timer and how to manipulate I/O pins in the ISR. There will be a lot of code to cut away but the essence of what you need is there.

Re: Accurate GPIO timing

PostPosted: Wed Sep 30, 2015 8:48 am
by eriksl
Now my question is, where do you actually need accurate gpio timing for?