How do I setup a Due to count rising edges on a pin automatically without having to waste time on an ISR?

I have some wheel encoders, the simplist implementation is direction less where you only count rising edges.

I went the Due to count rising edges automatically and an ISR on a timer will periodically pole the current count

  • what does this mean? ... waste time on an ISR
    – jsotola
    Sep 21, 2021 at 23:50
  • what does this mean? ... timer will periodically pole
    – jsotola
    Sep 21, 2021 at 23:51
  • encoder questions have been asked, and answered many times ... this site is not a tutorial forum, so please do research first, then ask questions about any problems that you encounter
    – jsotola
    Sep 21, 2021 at 23:53
  • 1
    From what I understand the Due has a counter with internal circuity instead of an ISR using to count. Sep 22, 2021 at 0:05
  • Have you a reference for that claim?
    – PMF
    Sep 22, 2021 at 8:25

1 Answer 1


You need to pick a timer that isn't being used for anything else and configure it as a simple counter with the clock source set to the external clock pin for that timer.

At block level, input clock signals of each channel can either be connected to the external inputs TCLK0, TCLK1 or TCLK2, or be connected to the internal I/O signals TIOA0, TIOA1 or TIOA2 for chaining by programming the TC Block Mode Register (TC_BMR). See Figure 36-2. Each channel can independently select an internal or external clock source for its counter:

  • External clock signals(1): XC0, XC1 or XC2
  • Internal clock signals: MCK/2, MCK/8, MCK/32, MCK/128, SLCK This selection is made by the TCCLKS bits in the TC Channel Mode Register (TC_CMR).

I am not personally familiar with the peripherals of the Due, but chapter 36 of the SAM3X datasheet details the workings and registers that you need to set.

Your encoder signal then connects to that clock input pin and the counter then counts every incoming pulse until you reset the count from your other periodic timer ISR.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.