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.pdfAny "Refs" in my documentation are pagenumbers from the link above.

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); }

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!