Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: AT91SAM7X multiple type GPIO interrupts - possible?
PostPosted: Mon Sep 21, 2009 10:54 am 
Offline

Joined: Wed Feb 07, 2007 12:38 pm
Posts: 3
Hi,

I need to measure pulse widths of multiple PWM channels with AT91SAM7X256. The PWM frequencies are around 50Hz and the pulse edges of different channels might not be aligned, so the start of the pulse must be measured separately for each channel.

I was planning on using PB0...PB3 for the PWM inputs.

Is it possible to trigger totally independent GPIO interrupts for the follwing different cases? Then I would have the following separate interrupt service routines:

1. PB0 negative edge interrupt service routine.
2. PB0 positive edge interrupt service routine.
3. PB1 negative edge interrupt service routine.
4. PB1 positive edge interrupt service routine.
5. PB2 negative edge interrupt service routine.
6. PB2 positive edge interrupt service routine.
7. PB3 negative edge interrupt service routine.
8. PB3 positive edge interrupt service routine.

The idea here is that I have the minimum amount of code in each service routine. The only method I now know is, that you have a single PIOB interrupt routine either for positive endge or negative edge. In the routine, you have a bunch of if() statements, with which you check which one was the GPIOB pin that generated the interrupt. However, this method spends quite a lot of time in the interrupt.

Thanks.


Top
 Profile  
 
 Post subject: Re: AT91SAM7X multiple type GPIO interrupts - possible?
PostPosted: Fri Sep 25, 2009 4:56 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

The SAM7X has independent interrupt for each port (A and B). Therefore you can improve efficiency by spreading your port edge interrupts over these two ports.

The following is the general handler from the uTasker project which allows each pin to dispatch its own interrupt handler sub-routine:

// Port A interrupt
//
static __interrupt void PortA_Interrupt(void)
{
unsigned long ulInputChanges = PIO_ISR_A;
unsigned long ulBit = 0x40000000;
int iInterrupt = 30;
ulInputChanges &= PIO_IMR_A; // only treat enabled inputs
while (ulInputChanges != 0) { // for each input change that has been detected
if (ulInputChanges & ulBit) { // an enabled input has changed
if ((gpio_config_a[iInterrupt] & 0x1) // any edge accepted
|| ((gpio_config_a[iInterrupt] & HIGH_LEVEL_SENSITIVE) && (PIO_PDSR_A & ulInputChanges)) // positive edge accepted
|| ((gpio_config_a[iInterrupt] == NEGATIVE_EDGE_TRIGGERED) && (~PIO_PDSR_A & ulInputChanges))) { // negative edge accepted
iInterruptLevel = 1;
(gpio_handlers_a[iInterrupt])(); // call the application handler
iInterruptLevel = 0;
}
ulInputChanges &= ~ulBit;
}
iInterrupt--;
ulBit >>= 1;
}
}

Of course there needs to be a loop or similar to check each individual interrupt pin source but this shows that the higher port interrupts are more efficient since they are handled first and the loop exits as soon as all waiting interrupts have been treated.
The bit checking order could also be changed from PA00..PA30 to give PA00 priority (and higher efficiency).

In your case, if you use both Ports A and B and position the interrupt at the same end (eg. PA00, PA01 or PA30, PA29) the worst case would be once around the loop and so still quite efficient.

Don't forget that the SAM7X has, in addition, interrupt inputs (IRQ0, IRQ1, FIG) which generate their own dedicated interrupt (edges and levels). By using these as well as dedicated interrupts from port A and port B you can again improve efficiency.

Note that the ATMEL AVR32 (which is very similar to the SAM7X in terms of peripherals) has one interrupt for each 8 bits of a port. Therefore Port A has an interrupt for each change in PA00..PA07, then one of PA08..PA15, etc. This allows more efficient dispatchers since the worst case is then 8 checks rather than up to 31 to handle PA00..P30.

Regards

Mark

http://www.uTasker.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: