Using this code, you can set a timer for any of the ISRs TC0_Handler through TC8_Handler, see table of parameters below. It is possible to use the timers without a physically mapped pin, such as TC1 channel 0 (TC3_Handler) shown here:

Using this code, you can set a timer for any of the ISRs TC0_Handler through TC8_Handler, see table of parameters below. It is possible to use the timers without a physically mapped pin, such as TC1 channel 0 (TC3_Handler) shown here:

Using this code, you can set a timer for any of the ISRs TC0_Handler through TC8_Handler, see table of parameters below. It is possible to use the timers without a physically mapped pin, such as TC1 channel 0 (TC3_Handler) shown here:

-What is the purpose of TC3_Handler() and how does it interact with startTimer()?-Once startTimer() is called, how do I stop the timer(how do I disable PWM)?-There's a few lines that I don't understand in startTimer():

TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4); <--- How does TC_Configure() work? Where can I find reference about this? uint32_t rc = VARIANT_MCK/128/frequency; <---------- is VARIANT_MCK the frequency of arduino DUE(84MHz)? What does rc do? TC_SetRA(tc, channel, rc/2); //50% high, 50% low<----sets the duty cycle? TC_SetRC(tc, channel, rc);<---------- what is this line for? TC_Start(tc, channel);<---------------enables PWM? How does it work? tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;<----------What does this line do? tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;<--------What does this line do? NVIC_EnableIRQ(irq); <-----enables interrupt?

StartTimer starts the timer. this function needs to be called once. after Starttimer is finished, the (hardware) timer keeps running on it's own, without any need for code. the timer counts up to a certain value, then generates an interrupt, starts with 0 and continues counting.

TC3_handler is called each time the interrupt of Timer/Counter TC3 (=timer 1 channel 0) is generated by the timer. "TC3_handler" is a pre-determined functionname just like "setup" and "loop" because TC3_handler is called for each interrupt, it is called as often as the timer hits that "certain value". The lower that value the more often the TC3_handler is executed.

uint32_t rc = VARIANT_MCK/128/frequency; <---------- is VARIANT_MCK the frequency of arduino DUE(84MHz)? What does rc do?Serial.Println(VARIANT_MCK,DEC) will enlighten. spoiler : yes rc is the value the timer counts towards. it is that "certain value" I mentioned above.

TC_SetRC(tc, channel, rc);<---------- what is this line for?it sets the value the timer counts towards. so it defines the frequency of the interrupts generated by the timer

TC_Start(tc, channel);<---------------enables PWM? How does it work?no, it starts the timer. the timer begins incrementing now.

tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;<----------What does this line do?I'm not sure but I think it sets the flag that specifies an interrupt is desired when timer = rc. IER = interrupt Enable Register

tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;<--------What does this line do?IDR = interrupt disable register, all other interrupt-types supported by TC3 are disabled and will not occur.

NVIC_EnableIRQ(irq); <-----enables interrupt?yes. it is the overall enabler, allowing interrupts to be generated by TC3.

Using this code, you can set a timer for any of the ISRs TC0_Handler through TC8_Handler, see table of parameters below. It is possible to use the timers without a physically mapped pin, such as TC1 channel 0 (TC3_Handler) shown here:

I got frequency between 1-21KHz to work, but I found another problem. I can't get 2 timers to run simultaneously. I ran the startTimer function twice with different handlers, but they refuse to work. Anyone know how to fix this problem?

Hello everybody.I am trying to generate a square wave using timer counters but I do not want to use an interrupt, rather I would like to output to go directly to TIOA0. I have the following configuration of the registershttp://paste.ubuntu.com/5703102/

Where exactly is a function like TC_Configure() or TC_GetStatus() actually defined? Right now, I'm just trying to figure out how to write to specific registers in the Arduino IDE. I may need to do this to change the frequency of a PWM.

If you include #include <Arduino.h> you should have access to them.The source code can be found in:arduino-1.5.2\hardware\arduino\sam\system\libsam\include\tc.harduino-1.5.2\hardware\arduino\sam\system\libsam\source\tc.c