Setting up interrupt for RC compare

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

Hello,

I am trying to set up an interrupt routine to execute every time an RC compare/trigger occurs on TC0. I've been able to set up the TC module to fire an interrupt when the compare occurs, but I'm struggling to understand how to properly setup the interrupt routine. What is the proper way to do this in C?

I've searched the forums in great length and was unable to find anything to help - any help here would be greatly appreciated. I'm using an STK600 dev board, if that is relevant.

Here is the interrupt-related code that I've worked out so far:

static void tc0_int_handler(void){
	
	//routine code here
	
}
Disable_global_interrupt();
	INTC_init_interrupts();
	INTC_register_interrupt(&tc0_int_handler, AVR32_TC_IRQ0, AVR32_INTC_INT2);
Enable_global_interrupt();
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Search the forums. This has been answered. Perhaps this is a starting point: https://www.avrfreaks.net/index.p...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the link - it was moderately helpful. I included the tc_read_sr function in the ISR so that the read will clear the status bit.

However, this hasn't solved the issue I'm experiencing. When I'm debugging, I find that whenever the interrupt state should be entered (e.g. an RC compare occurs), the debugger locks up, so to speak, and doesn't go anywhere.

Any help regarding this issue is very much appreciated!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, if include either of these in my code, check equals zero, even though I do believe I should get a true, or 1, result.

	Enable_global_interrupt();
	check= cpu_irq_is_enabled();

or

	cpu_irq_enable();
	check= cpu_irq_is_enabled();
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you enabling the clock for the timer module at all? I use the line of code in my main :

sysclk_enable_peripheral_clock(&AVR32_TC0);

Furthermore, I initialise the timer/counter module as:

void TC_init()
{
	volatile avr32_tc_t *tc = &AVR32_TC0;	//pointer to the channel 0 timer module within the Timer/Counter
	// Initialize interrupt vectors.
	INTC_init_interrupts();
	// Register the RTC interrupt handler to the interrupt controller.
	INTC_register_interrupt(&tc_irq, AVR32_TC0_IRQ0, AVR32_INTC_INT3);
	// Initialize the timer module
	tc_init(tc);
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I included the sysclk_enable_... line and my interrupts started working! First off, thank you so much!

Secondly, since my TC module's counter value was incrementing before I put that line in, I was under the impression that it was already being clocked. What exactly does that line of code do?

Again, thank you very much for the advice.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not a problem, that is what these forums are suppose to be here for ;D

Quote:
What exactly does that line of code do?

Have a look at: http://asf.atmel.com/docs/latest/common.services.basic.clock.example1.uc3_a3_xplained/html/group__sysclk__group.html
where it says:
Quote:
static void sysclk_enable_peripheral_clock (const volatile void *module)
Enable a peripheral's clock from its base address.

I use it (and others in the above url) instead of hassling with the conf_clock.h file to setup the various system clocks for the project and then calling sysclk_init(). I did try using the conf_clock.h file at first but I found that it was not flexible enough. So I did the following (below) instead and it worked as I needed (provided the Datasheet was close at hand - it is also your friend ;D) First I set the system clocks up using the Power Manager functions: http://asf.atmel.com/docs/3.9.1/uc3a3_a4/html/group__group__avr32__drivers__pm.html
and then I activate/enable the various peripheral clocks independently as needed.

It should be noted, I am by no means an "expert" when it comes to AVR32 and the silly/frustrating/bulky/sluggish ASF and AtmelStudio. I am merely playing around with it ( and the DSP library) for a final Electronics Degree project ;) My main experience (learning only this year) is with the AVR mega range and AVR Studio 4, bashing at the registers in assembler and then C.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I use it (and others in the above url) instead of hassling with the conf_clock.h file to setup the various system clocks for the project and then calling sysclk_init()

Ah, okay - that's making much more sense. I agree - I've been clinging to the datasheet for dear life. Best of luck to you for your electronics project!