Counter for hardware with Arduino due to use an encoder


I just made a pulse counter for hardware by arduino one. But I need to do with the arduino due. Because the account is greater than 70000 pulses im in need to do so with arduino due. I found very little information about this

I even read 36. Timer Counter (TC) SAM3X data sheet, but not if you go down the right path.

could you help me

unsigned long pulses;

void setup() {
TC_Configure ( TC0, 0, TC_CMR_TCCLKS_XC2| TC_CMR_ETRGEDG_FALLING | TC_CMR_ABETRG | TC_CMR_LDRA_FALLING ); //tratar deactivar la escritura con WAVE


void loop() {

const uint32_t pulses = TC_ReadCV ( TC2, 2 );
//Serial.print( TC_ReadCV(TC0,0));
Serial.print( REG_TC0_CV0, DEC);
Serial.print(" ");



counte_of_pulses_DUE.ino (640 Bytes)

Hi there @Gabriel_MX

You can do what you want with library tc_lib (GitHub - antodom/tc_lib: This is a library to take advantage of different functionalities available on Timer Counter (TC) modules in Arduino Due's Atmel ATSAM3X8E microcontrollers). Have a look to example capture_test.ino, it gives you the instantaneous duty and period of a digital signal. In your problem the signal would be coming from your encoder. The period given would be the duration of an encoder tick, so 1/period will give you the velocity in ticks per second.

I hope it helps.