Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Ancaritha
PostPosted: Apr 08, 2008 - 07:59 PM
Rookie


Joined: May 22, 2006
Posts: 22


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);
 
 View user's profile Send private message  
Reply with quote Back to top
sma
PostPosted: Apr 08, 2008 - 09:00 PM
Posting Freak


Joined: Jan 14, 2007
Posts: 1836
Location: Nantes, France

Quote:

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?


This is simply done by the GPIO (it controls the mux).
Check the GPIO initialization and make sure to enable the pin you want to use.
TC config can remain unchanged.
-sma
 
 View user's profile Send private message  
Reply with quote Back to top
Ancaritha
PostPosted: Apr 08, 2008 - 09:26 PM
Rookie


Joined: May 22, 2006
Posts: 22


The example code did not set up an GPIO stuff for the TC, so I didn't either. I shall experiment with plugging in a GPIO set up for TC0 on one of the other pins.

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
Ancaritha
PostPosted: Apr 10, 2008 - 03:27 PM
Rookie


Joined: May 22, 2006
Posts: 22


I did the following code before initializing all of my Timer stuff:

Code:

// Timer/Counter Clck 0 options.
   static const gpio_map_t TC0_GPIO_MAP =
   {
      // So the ones on Peripheral B on Pin 44
      {AVR32_TC_CLK0_0_1_PIN, AVR32_TC_CLK0_0_1_FUNCTION}
   };

   // Assign GPIO pins to TC0
   gpio_enable_module(TC0_GPIO_MAP, sizeof(TC0_GPIO_MAP) / sizeof(TC0_GPIO_MAP[0]));


However, now my timer failed to run at all. If I commented this out, it worked. I then changed the pin configuration to:

Code:

{AVR32_TC_CLK0_0_0_PIN, AVR32_TC_CLK0_0_0_FUNCTION}


I believe this should have set it back to the default setting that it should have been using all along, but this failed to run as well.

Both of the above failed to print anything out on Usart1 (something is printed out at the start of time, and then once every second), so it suggests that the program was crashing, as I set up the TC first. I'm doing something wrong... I'm just not sure what exactly. Any thoughts?

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits