This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Read gpio state on event

Hi,

I'm implementing quadrature encoder to read motor speed/position. So far I configured a gpio pin where A channel of the quadrature encoder is connected to capture timer value on toggle using gpiote, ppi and timer.

Now I would like also to capture state of gpio pin where B channel of the quadrature encoder is connected on same event (toggle of A channel) to be able to resolve direction of the motor. I can't simply read the state of the B channel using nrf_gpio_pin_read in an event or interrupt routine as this is not guaranteed to be real time (softdevice is running).

Is that possible, using e.g. gpiote, ppi, dma ... ?

Parents
  • Hi,

    You can configure the GPIOTE to generate an event on GPIO rising edge, falling edge or any change. You can then configure an TIMER instance in counter mode, and use it to keep track of how many times the event has been generated. If you know the initial gpio state(high/low), then you also know the current GPIO state simply by looking at the counter value.

  • Actually, I found that this idea doesn't work - it has same effect as reading gpio state in interrupt routine (which has some latency due to softdevice). Now I'm trying this: on A channel's rising/falling edge I trigger SPI transaction (B channel connected to MISO). SPI samples B channel and stores it value (0xFF or 0x00) to RX buffer where it is accessible later. The same "principle" would probably work with ADC - to buffer B channel using ADC on A channel falling/rising edge.

Reply
  • Actually, I found that this idea doesn't work - it has same effect as reading gpio state in interrupt routine (which has some latency due to softdevice). Now I'm trying this: on A channel's rising/falling edge I trigger SPI transaction (B channel connected to MISO). SPI samples B channel and stores it value (0xFF or 0x00) to RX buffer where it is accessible later. The same "principle" would probably work with ADC - to buffer B channel using ADC on A channel falling/rising edge.

Children
Related