Using TC capture mode to count input pulse

Dear forks, I'm trying to count input pulse by using TC capture function. But I found strange behavior. Please look at the code. If you have DUE, you can try this. (connect DigitalPin7 to DigitalPin30)

Why does first line show zero ? It must be one.

thanks. --- head of result ---- hello world 0 1 2 3 4 5

// connect DigitalPin7 to DigitalPin30
static void startTC8() { // pulse capture counter
  // TCLK8 PD9 Peri-B
  uint32_t maskbit = 1 << 9;
  PIOD->PIO_PDR = maskbit; // enables peripheral control of the pin
  PIOD->PIO_ABSR |= maskbit; // Assigns the I/O line to the Peripheral B function
    TC_CCR_CLKDIS; // disables the clock
    TC_CMR_TCCLKS_XC2 | // == TCLK8
    0; // CLKI: rising edge of the clock
    TC_CCR_CLKEN | // enables the clock if CLKDIS is not 1
    TC_CCR_SWTRG; // the counter is reset and the clock is started
void setup() {
  Serial.println("hello world");
void loop() {

I wish I could help you with your issue, but in the meantime, could you check out my post:


You seem to understand a good amount about the timers and their registers on the Due AT91SAM3X8E processor. I've found little documentation about the code needed to modify these timers. Any help or information you can provide would be especially useful.

And good karma is often rewarded ;)

Thanks elevine, I read your post and I got Atmel Software Framework (ASF). But unfortunately I have not gotten exact answer yet. It seems that people usually use TC capture mode with TC_RAx and/or TC_RBx. I want to count input pulse simply with only TC_CVx.


In page 873 of the doc11057.pdf,(37.6 Functional Description\37.6.2 32-bit Counter)

"The current value of the counter is accessible in real time by reading the Counter Value Register, TC_CV. The counter can be reset by a trigger. In this case, the counter value passes to 0x0000 on the next valid edge of the selected clock."

Hope the above text will relieve your concern. :)

Thanks jt6245, it seems that first positive edge after "TC2->TC_CHANNEL[2].TC_CCR = TC_CCR_CLKEN |TC_CCR_SWTRG;" clears the TC_CV register. I feel uncomfortable about this specification. regards,