Fast encoder sampling rate for nRF52xx

Omri F gravatar image

asked 2017-09-13 12:29:26 +0100

We need to sample two digital inputs GPIOs at rate of 100khz-1mhz. How can we do that? The QDEC is only good for up to 128us (~7khz) which is too slow for us. Is there a way to sample GPIO with DMA? If not, is there a way to do that without using interrupt every 10us?

edit retag flag offensive close delete report spam

1 answer

Sort by » oldest newest most voted
sigurdon gravatar image

answered 2017-09-14 12:29:26 +0100

updated 2017-09-14 12:32:37 +0100


You should be able to do this using GPIOTE, PPI and a TIMER in counter mode. See this post for some more information.

edit flag offensive delete publish link more


thanks you for the response. we need to sample 2 gpios that are inputs of a stepper motor encoder. We there for need to know per every rising or falling edge of each io compared to the other io. In other words we need a repeated pattern like this: io0 rise, io1 rise, io0 fall, io1 fall. We thus cannot sample count of events in 1 second. We need to sample the combination of BOTH io's every time each toggles. This is exactly what the QDEC does, but the QDEC is too slow for us. what i did is attached both to GPIOE interrupt and sample the data to a buffer in the interrupt context. This is working but very waste full in real time. Can i still use the link you added for these purposes some how?

Omri ( 2017-09-14 12:46:37 +0100 )editconvert to answer

Using the GPIOTE, PPI and a timer or two it should definitely be possible to implement something similar to the QDEC without requiring a lot of MCU involvement.

At the very simplest you could configure a timer in counter mode, and connect one of the encoder signals to the counter through the PPI. This would only require a single GPIOTE channel, one PPI channel, and one timer, but it would only give you the distance, not the direction. Also, it would only captures every other step.

To capture all the steps you would need a total of 2 PPI channels and 2 GPIOTE channels.

Capturing direction is a bit more complicated, but if you can spare 4 GPIOTE channels and 5 PPI channels (in total) it should be possible. Then you can configure the system so that you get an interrupt every time the direction changes, and you would have ...(more)

Sigurd ( 2017-09-14 15:46:02 +0100 )editconvert to answer

cant i clock the the counter in rising & falling mode instead of just rising edge? if i have to manually change direction then i may just as well use a simple interrupt every rising/falling and read the gpio's to a buffer in the interrupt (simulate DMA). The interrupt just reads io to buffer and thats it.

Omri ( 2017-09-15 06:21:25 +0100 )editconvert to answer

Yes, GPIOTE can generate an event on any change(rising & falling), and the event can trigger the TIMER task to increase the counter.

Sigurd ( 2017-09-20 13:37:58 +0100 )editconvert to answer

Assuming i connect GPIOTE to a encoder digital input (0/1) and i manage to increment a timer per every rising or falling, can i then sample either the 0/1 value or the timer counter into a DMA? I must find a way to track the timing of the encoder changes. Example: read 0 after 100us, then read 1 after 25us, then read 0 after 75us, etc. I need to know to pattern timing in resolution of 10us

Omri ( 2018-01-15 09:56:27 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools

1 follower


Asked: 2017-09-13 12:29:26 +0100

Seen: 91 times

Last updated: sep. 14 '17