timer library for arduino due

hi...
I am using arduino due.i want to use the timer of arduino due..but i have not found the timer libraries required for arduino due.so please suggest me what i have to do?

Hi,

I think that the following topic could be of your interest: http://arduino.cc/forum/index.php/topic,130423.0.html

Kind Regards

Hi....i want to calculate the total count pulses from the counter value register TC_CV.but i am not able to intialiaze the command. can i directly write long z = REG_TC0_CV0 ?as i wrote this, it is not showing me any value.Please suggest me

Hi Guys!
Try this at home!
Working fine for me - check my documentation inline.
Also SimonCino's link is very helpfult at this point, there is some essential information specially about channels and clocks you don't want to miss. If you really want to understand what is happening: http://www.atmel.com/Images/doc11057.pdf
Any "Refs" in my documentation are pagenumbers from the link above.

//TC_CV address for Clock 1, Channel 1
//Ref: 911
int *TC_CV = (int *)(0x40084050);

void setup() {  
  Serial.begin(115200);
  //configure the Timer
  configureTimer();
  startTimer();  
}

void loop() {
  // put your main code here, to run repeatedly: 
  Serial.println(*TC_CV);
  if(*TC_CV > 1000000){
    stopTimer();
    Serial.println("Timer stopped");
    delay(5000);
    startTimer();
  }
}


void configureTimer(){
  //remove writeprotection from timer registers so i am allowed to make modifications on them
  pmc_set_writeprotect(false);
  //enable the peripheral ID_TC4 - due to power saving terms this is turned off initially
  pmc_enable_periph_clk(ID_TC4);
  //define clock, timerclock 1, channel 1, and some fancy stuff i did't understand at all
  TC_Configure(TC1,1,TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | 2);
  //define the frequency. this signal is 50% on 50% off
  uint32_t rc = VARIANT_MCK/128/1000000;
  TC_SetRA(TC1,1,rc/2);
  TC_SetRC(TC1,1,rc);  
}

void startTimer(){
  //start Clock 1, Channel 1
  TC_Start(TC1,1);
  Serial.println("Timer started");
}

void stopTimer(){
  //stop Clock 1, Channel 1
  TC_Stop(TC1,1);
}

What is happening?
Open your serial monitor. You will notice TC_CV counting up to 100000. Then counting stops for few secs - then TC_CV counting up again.
What is happening behind?
In setup the timer is defined and started. In loop is checked if the timer has already reached 100000. If so - he is stopped and execution pauses for 5secs. Afterwards the timer starts again.
Some interesting facts:
There is no reason(can't imagine one) to check a TC_CV register in loop like in this example - this is very bad practice! There are timer interrupts which come in handy...
The numbers you will see will differ more than one, the first number is not 0, the last is not 99999: The timer runs parallel to serial printing and loop(). And these two are very slow compared to the timer.

If someone finds out more about the waveform-magic (TC_CMR_WAVSEL_UP_RC, TC_SetRA) plz let us know!
Hope this helped! Have fun arduinoing!