[quote author=Sebastian Vik link=topic=130423.msg984328#msg984328 date=1352148520]
Here is the table of parameters:
| ISR/IRQ | TC | Channel | Due pins |
| - | - | - | - |
| TC0 | TC0 | 0 | 2, 13 |
| TC1 | TC0 | 1 | 60, 61 |
| TC2 | TC0 | 2 | 58 |
| TC3 | TC1 | 0 | none <- this line in the example above |
| TC4 | TC1 | 1 | none |
| TC5 | TC1 | 2 | none |
| TC6 | TC2 | 0 | 4, 5 |
| TC7 | TC2 | 1 | 3, 10 |
| TC8 | TC2 | 2 | 11, 12 |
A brief explanation:
The SAM3X8E CPU has 3 Timer Counters (TC) they are called TC0, TC1, TC2.
Every Timer Counter contains 3 Channels numbered 0, 1 and 2 (this give us a total of 9 Channels).
Every Channel has its own counters and interrupt handler that are independent from other Channels.
In other words each Channel can be considered as a separate "Timer", and is like having 9 separate timers.
To initialize a Channel you need the following parameters:
TC0/TC1/TC2 - The Timer Counter instance
0 / 1 / 2 - The Channel number inside Timer Counter
If you want to use interrupts you must enable the NVIC (Nested Vector Interrupt Controller) for that channel with:
where TCx_IRQn is the ID of the interrupt to enable. These id are listed in the following table together with the ISR handler function name:
| TC | Chan | NVIC "irq" | IRQ handler function | PMC id |
| - | - | - | - | - |
| TC0 | 0 | TC0_IRQn | TC0_Handler | ID_TC0 |
| TC0 | 1 | TC1_IRQn | TC1_Handler | ID_TC1 |
| TC0 | 2 | TC2_IRQn | TC2_Handler | ID_TC2 |
| TC1 | 0 | TC3_IRQn | TC3_Handler | ID_TC3 |
| TC1 | 1 | TC4_IRQn | TC4_Handler | ID_TC4 |
| TC1 | 2 | TC5_IRQn | TC5_Handler | ID_TC5 |
| TC2 | 0 | TC6_IRQn | TC6_Handler | ID_TC6 |
| TC2 | 1 | TC7_IRQn | TC7_Handler | ID_TC7 |
| TC2 | 2 | TC8_IRQn | TC8_Handler | ID_TC8 |
(note that TC*2*_IRQn is the irq id for TC0-channel-2 not for TC2...)
but this is still not enough! Every peripheral in the SAM3X is off by default (to save power) and should be turned on. To turn on you need to run the following command:
where id is found on the last column of the above table (ID_TCx). It happened that ID_TCx constant equals TCx_IRQn, so Sebastian Vik has simplified a bit the function using TCx_IRQn as input for pmc_enable_periph_clk:
Hope this helps to decode whats happening with timers inside SAM3X.
Are there any ready-to-use-libs (like http://www.arduino.cc/playground/Code/Timer1) for using Hardware Timer on Due?
Or is there a beginner-friendly How-To (like http://www.engblaze.com/microcontroller-tutorial-avr-and-arduino-timer-interrupts/) for the Due?
Nope, there are no libs neither tutorials.
I've planned a SAM3Timer library (to simplify implementation of Arduino Core and some libraries) but I didn't started it yet.