Simple Timer Interrupt - changing TimerRegister RC has no impact!??

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

Need help from someone who was successful by encrypting the user manuals according to timer/counter and interrupt generation.

 

My setup:
 - AVR32 (AT32UC3L064 Xplained Board)
 - Using ASF library (in Atmel Studio 7)

 

Goal: Setting up blinking LED triggerd by timer interrupt.

 

Estimated complexity: very simple
Real complexity: feels like rocket science

 

Concidered example:
TC Example 3 - UC3-L0 Xplained

 

Getting inspired by different source code, example 3 for the UC3-L0 Xplained came closest to what worked. 

There are two things I do have a missunderstanding with:

  1. Configure Waveform clocksource .tcclks: using TC1 is completely dead (no 32 kHz), TC2 ... TC5 have all the same frequency and don't seem to devide the clock (TC2: PBC clock / 2, TC3: PBC clock / 8,...).
  2. Varying the RC value doesn't have any effect even so commenting out its configuration seems to having no impact at all (tc_write_rc(tc, LED_TIMER_CHANNEL, 20000);)

 

Below is my source code (reduced to the very necessary parts). Very much the same as in Example 3 but the used interrupt timer source is AVR32_TC0_IRQ0 instead of AVR32_TC1_IRQ0, because TC1 seemed to not do anything.

(with this source code the LED on the Xplained board blinks with a speed of abount 2 Hz. But the frequency is only controllable by the)

 


#define LED_TIMER_CHANNEL 0u

uint32_t counter = 0;


__attribute__((__interrupt__))
static void Isr_LED_timer(void)
{
	if (counter >= 50000) 
	{
		counter = 0;
		gpio_tgl_gpio_pin(LED_BLUE_GPIO);
	}
	else
	{
		counter++;
	}
}


int main(void)
{
	
	volatile avr32_tc_t *tc = &AVR32_TC0;
	
	tc_waveform_opt_t waveform_opt =
	{
		.channel  = LED_TIMER_CHANNEL,					// Channel selection.
				
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,		// Waveform selection: Up mode with automatic trigger on RC compare.

		.tcclks   = TC_CLOCK_SOURCE_TC3				// TC CLOCK 1: 32k oscillator
		// TC CLOCK 2: PBC clock / 2
		// TC CLOCK 3: PBC clock / 8
		// TC CLOCK 4: PBC clock / 32	(1.25 MHz @fPBC=40MHz)
		// TC CLOCK 5: PBC clock / 128	(312.5 kHz @fPBC=40MHz)
	};
			
	static const tc_interrupt_t TC_INTERRUPT =
	{
		.cpcs  = 1,
	};
	
		
	sysclk_init();
	sysclk_enable_peripheral_clock(LED_TIMER_CHANNEL);
	
	Disable_global_interrupt();
		

	/* Initialize interrupt vectors. */
	INTC_init_interrupts();

	INTC_register_interrupt(&Isr_LED_timer, AVR32_TC0_IRQ0, AVR32_INTC_INTLEVEL_INT0);
	
	Enable_global_interrupt();
	
	
	tc_init_waveform(tc, &waveform_opt);

	//tc_write_rc(tc, LED_TIMER_CHANNEL, 20000);
	
	tc_configure_interrupts(tc, LED_TIMER_CHANNEL, &TC_INTERRUPT);
	
	tc_start(tc, LED_TIMER_CHANNEL);
	


	board_init();
	
	gpio_set_group_low(LED_PORT_ID, LED_CHASER_PORT_MASK);

	while (1) 
	{
		// doing things
	}
}

So, can any one help? I now spend about 16h trying to set up a simple interrupt and searching through the entire internet (at least part of it ...)!

 

"You don't have to be afraid of interrupts they said" surprise

 

 

Cheers and thank you for any help!

 

 

 

This topic has a solution.
Last Edited: Thu. Jul 11, 2019 - 11:56 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To use the 32 kHz oscillator you will first need to configure and enable it.



As a general rule, in an interrupt handler you will need to read the SR of that module to reset that interrupt.
Try a tc_read_sr( &AVR32_TC0, LED_TIMER_CHANNEL ); at the start of Isr_LED_timer(void) and uncomment //tc_write_rc(tc, LED_TIMER_CHANNEL, 20000);

Last Edited: Thu. Jul 11, 2019 - 01:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

angry and this was even part of the example arrrrrgggg!!! 

=> http://gph.is/2c14JPK

 

 

Thank you very much!

 

... just an other day feeling stupied!crying

 

no time for stupidness, lets carry on cool