Using TC of Arduino Due

Hi everyone,

I’m a newbie to Arduino Due and working hard to get the TC working. In order to measure frequency’s around 40kHz with a resolution of about 100Hz, I would like to use the TC. I thought to use a Timer in Capture Mode which saves the current value of the timer when a rising edge at TIOA occurs.
Here is my porblem: I didn’t get the timer counting :frowning: … there are only zeros in the serial monitor

Could someone help me, please :slight_smile:

My code:
void setup() {
Serial.begin(115200);
while (!Serial) {
;
}
}

void loop() {

REG_TC1_WPMR = 0x54494D00; //WPKEY, disable
REG_TC1_CCR0 = ((1 << 2) | (1 <<0)) ; //reset, enable clock
REG_TC1_CMR0 = ((1 << 16) | (1 << 10) | (1 << 8)); //LOAD REG A, TIOA, RISIGNG_EDGE
while(1){
Serial.println(REG_TC1_SR0);
};
}

You have to turn on clock for all peripherals first - they don't do anything
until they get their clocks.

  pmc_enable_periph_clk (TC_INTERFACE_ID + 0*3+0) ;  // clock the TC0 channel 0

For TC1 change the first 0 to a 1, then the second 0 selects which channel...

That works!
Thank you :wink:

I just got one more question:
pmc_enable_periph_clk() is a function, isn't it?
I suppose there are more functions like that so you don't have to set the bits everytime ?
If yes where can I find a reference for that?

Best regards

I found the reference for all that stuff, this makes it al lot easier :wink:

taaank:
I just got one more question:
pmc_enable_periph_clk() is a function, isn’t it?
I suppose there are more functions like that so you don’t have to set the bits everytime ?
If yes where can I find a reference for that?

Best regards

You do look at the code in the Arduino system don’t you? It is open-source for a reason!

/hardware/arduino/sam/system/libsam/source/...

has all the libsam stuff (with a lot of useful functions - there are #defines in

/hardware/arduino/sam/system/libsam/include/...

Isn’t grep useful!

Yes, it is.
Thank you!