Motor Encoder Counter with only direction pin (no A / B / Z), Interrupt-less solution

We are controlling a brushless motor with the nRF52840. This motor has an integrated motor controller, feedback is only:

- Single Encoder Pulse (no A / B or even Z)

- Directional Pin (which is actually not feedback because this pin is used to control the motor direction, but still this pin indicates the motors spinning direction)

Based on these two pins, I would like to configure a counter which shall count up / down without the use of an Interrupt. 

Currently we solve this by issuing an interrupt on the rising edge of the encoder pulse. In the ISR we query for the level of the directional pin and adjust the counter accordingly. 

It appears to me, that QDEC is made for regulator A / B / Z encoder and not something like this.

Has someone an approach for an interrupt-less solution?

Thanks

  • Hi,

    How about using two TIMERs (e.g. timer3 and timer4) and two GPIOTE channels (to start and stop timers), maybe that can work.

    You need to connect the encoder pulse to two inputs (used for each TIMER configured to counter mode from pin (using GPIOTE.IN -> PPI -> TIMER.COUNTER (so likely need two additional GPIOTE channels for this)). 

    You connect the directional pin to two inputs (one input used to trigger GPIOTE. IN[x] event to START timer3 and STOP timer4 on rising edge (using PPI channel n), the other used to trigger GPIOTE. IN[y] event to STOP timer3 and START timer4 on falling edge (using PPI channel m)).

    This way TIMER3 will only increment when the directional pin is high, and TIMER4 when the direction pin is low. The timers will not clear here, but only count depending on the state of the direction pin, but the application can get an interrupt for instance when the direction changes on GPIOTE.IN event or read the timer values at given intervals to observe changes. 

    GPIOTE, PPI and pin change interrupt examples are likely good starting points.

    Best regards,
    Kenneth

Related