I need to use both Usart0 and the Timer Counter Clock to generate an interrupt every 1 ms. However they both use the same pins, so they can't be enabled at the same time.
Right now I'm enabling TC0 and Usart1. Every 1 second I print out a character on Usart1. Once I enable Usart0 however, it stops printing out any characters. Because Usart0's pins are tied to the RS232 port thats on the eval board I can't change that one. So my question is, how do I make it use one of the other TC0's instead of that one? For instance, the TC0 Clk also exist as Peripheral B on PB12 and Peripheral C on PX20. How do I set up the TC to use these clks instead?
I'm currently setting up the timer exactly like it does in the framework Tc Example 3:
Code:
// Options for waveform genration.
static const tc_waveform_opt_t WAVEFORM_OPT =
{
MSTICK_TIMERCHANNEL, // Channel selection.
TC_EVT_EFFECT_NOOP, // Software trigger effect on TIOB. - bswtrg
TC_EVT_EFFECT_NOOP, // External event effect on TIOB. - beevt
TC_EVT_EFFECT_NOOP, // RC compare effect on TIOB. - bcpc
TC_EVT_EFFECT_NOOP, // RB compare effect on TIOB. - bcpb
TC_EVT_EFFECT_NOOP, // Software trigger effect on TIOA. - aswtrg
TC_EVT_EFFECT_NOOP, // External event effect on TIOA. - aeevt
TC_EVT_EFFECT_NOOP, // RC compare effect on TIOA: toggle. - acpc
TC_EVT_EFFECT_NOOP, // RA compare effect on TIOA: toggle (other possibilities are none, set and clear). - acpa
TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,// Waveform selection: Up mode with automatic trigger(reset) on RC compare. - wavsel
FALSE, // External event trigger enable. - enetrg
0, // External event selection. - eevt
TC_SEL_NO_EDGE, // External event edge selection. - eevtedg
FALSE, // Counter disable when RC compare. - cpcdis
FALSE, // Counter clock stopped with RC compare. - cpcstop
FALSE, // Burst signal selection. - burst
FALSE, // Clock inversion. - clki
TC_CLOCK_SOURCE_TC2 // Internal source clock 2 - connected to PBA/4 - tcclks
};
static const tc_interrupt_t TC_INTERRUPT =
{
0, // etrgs
0, // ldrbs
0, // ldras
1, // cpcs
0, // cpbs
0, // cpas
0, // lovrs
0 // covfs
};
// Register the RTC interrupt handler to the interrupt controller.
INTC_register_interrupt(&MS_Tick_Interrupt, AVR32_TC_IRQ0, INT0);
// Initialize the timer/counter.
tc_init_waveform(tcMsTickTimer, &WAVEFORM_OPT); // Initialize the timer/counter waveform.
// Set the compare triggers.
// Remember TC counter is 16-bits, so counting second is not possible.
// We configure it to count ms.
// We want: (1/(FPBA/4)) * RC = 1000 Hz => RC = (FPBA/4) / 1000 = 3000 to get an interrupt every 1ms
tc_write_rc(tcMsTickTimer, MSTICK_TIMERCHANNEL, (SLOW_PERIPHERAL_BUS/4)/1000); // Set RC value.
tc_configure_interrupts(tcMsTickTimer, MSTICK_TIMERCHANNEL, &TC_INTERRUPT);
|