Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Speed of execution

Speed of execution

2009-02-24 by David VanHorn

So I have this Mega32 running at 4 MHz (yes, 4 MHz, I checked the fuses)

I'm trying to measure two pulse widths, on INT0 and INT1 using T1 with
a divisor of 1.
The pulses have a minimum period of 5uS, nominal period of 14uS, and
max of 23uS.
I can't adjust those values.

I enable INT0 for a rising edge int.
When the int happens, I zero T1, and exit the ISR.
When the int happens again, I read T1 and store it.

Then I disable INT0, enable INT1, and do the same thing for the pulse
on that input.


My problem is that the system seems to be running much slower than I
would expect.
The interrupt latency is measuring out more than 5uS!

I don't have any other ints enabled, other than a very simple T0 ISR
(see previous post)

There's no point where I have ints disabled, at least not in the code
that I wrote.

Do I really have to run the machine faster than this?
I wouldn't expect to have to in Asm..




-- 

"The very powerful and the very stupid have one thing in common. Instead of
altering their views to fit the facts, they alter the facts to fit their
views... which can be very uncomfortable if you happen to be one of the
facts that needs altering." Doctor Who, Face of Evil

Re: [AVR-Chat] Speed of execution

2009-02-24 by wagnerj@proaxis.com

> So I have this Mega32 running at 4 MHz (yes, 4 MHz, I checked the fuses)
>
> I'm trying to measure two pulse widths, on INT0 and INT1 using T1 with
> a divisor of 1.
> The pulses have a minimum period of 5uS, nominal period of 14uS, and
> max of 23uS.
> I can't adjust those values.
>
> I enable INT0 for a rising edge int.
> When the int happens, I zero T1, and exit the ISR.
> When the int happens again, I read T1 and store it.
>
> Then I disable INT0, enable INT1, and do the same thing for the pulse
> on that input.
>
>
> My problem is that the system seems to be running much slower than I
> would expect.
> The interrupt latency is measuring out more than 5uS!
>
> I don't have any other ints enabled, other than a very simple T0 ISR
> (see previous post)
>
> There's no point where I have ints disabled, at least not in the code
> that I wrote.
>
> Do I really have to run the machine faster than this?
> I wouldn't expect to have to in Asm..
>
>
>
>
> --
>
> "The very powerful and the very stupid have one thing in common. Instead
> of
> altering their views to fit the facts, they alter the facts to fit their
> views... which can be very uncomfortable if you happen to be one of the
> facts that needs altering." Doctor Who, Face of Evil
>

Well, interrupts are disabled inside ISRs!

Jim Wagner

Re: [AVR-Chat] Speed of execution

2009-02-24 by David VanHorn

> Well, interrupts are disabled inside ISRs!

I'm well aware of that.

I'm trying to get the ISRs (especially the first one) to be as fast as possible.

This is clipped from the file, it worked in monospaced font.


/----------------------------------------------- Start aquiring A
                                                                |
       /--------------------------------- Stop aquiring A
				|             |        /------------------------ Start aquiring B
				|             |        |           /------------ Stop aquiring B
				|             |        |           |
				|             |        |           |      /----- Start aquiring A again
				|             |        |           |      |      and so on.
Channel A:000000111111110000001111111100000011111111000000111111110000001111111100000011111111
Channel B:000001111111000001111111000001111111000001111111000001111111000001111111000001111111

Channel A is on INT0
Channel B is on INT1

INT0 should fire on the first high edge of channel A, after it is enabled.

The only code that executes in that case is:
TCNT1H=0;				// Timer starts at 0
TCNT1L=0;
Raw_Edge_Flag = 0xFF;	// Next time is the end of a pulse

Then I exit the ISR.

On the next high edge of channel A,  the ISR fires again, and the
following executes:

// Store output into serial buffer
Raw_Data[0][*Raw_Data_In_Pointer] = TCNT1;
GICR  |= (0<<INT0)|(1<<INT1);	// Disable INT0, Enable INT1
Raw_Edge_Flag = 0; 	// Next time is the beginning of a pulse

Now if this second part is a little long, that does not matter.
I'm going to then be looking for input on the B channel, and doing the
same thing.
The idea is to capture the period of oscillation of the A channel and
the B channel, as close as possible to the same point in time.

Re: [AVR-Chat] Speed of execution

2009-02-24 by wagnerj@proaxis.com

>> So I have this Mega32 running at 4 MHz (yes, 4 MHz, I checked the fuses)
>>
>> I'm trying to measure two pulse widths, on INT0 and INT1 using T1 with
>> a divisor of 1.
>> The pulses have a minimum period of 5uS, nominal period of 14uS, and
>> max of 23uS.
>> I can't adjust those values.
>>
>> I enable INT0 for a rising edge int.
>> When the int happens, I zero T1, and exit the ISR.
>> When the int happens again, I read T1 and store it.
>>
>> Then I disable INT0, enable INT1, and do the same thing for the pulse
>> on that input.
>>
>>
>> My problem is that the system seems to be running much slower than I
>> would expect.
>> The interrupt latency is measuring out more than 5uS!
>>
>> I don't have any other ints enabled, other than a very simple T0 ISR
>> (see previous post)
>>
>> There's no point where I have ints disabled, at least not in the code
>> that I wrote.
>>
>> Do I really have to run the machine faster than this?
>> I wouldn't expect to have to in Asm..
>>
>>
>>
>>
>> --
>>
>> "The very powerful and the very stupid have one thing in common. Instead
>> of
>> altering their views to fit the facts, they alter the facts to fit their
>> views... which can be very uncomfortable if you happen to be one of the
>> facts that needs altering." Doctor Who, Face of Evil
>>
>
> Well, interrupts are disabled inside ISRs!
>
> Jim Wagner
>
>
>
>

There is a current thread on AVRFreaks that sounds VERY similar to your
problems: Interrupt problem (timer1 timing + 'interference')

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=75366

Jim

Re: [AVR-Chat] Speed of execution

2009-02-24 by wagnerj@proaxis.com

>> Well, interrupts are disabled inside ISRs!
>
> I'm well aware of that.
>
> I'm trying to get the ISRs (especially the first one) to be as fast as
> possible.
>
> This is clipped from the file, it worked in monospaced font.
>
>
> /----------------------------------------------- Start aquiring A
>                                                                 |
>        /--------------------------------- Stop aquiring A
> 				|             |        /------------------------ Start aquiring B
> 				|             |        |           /------------ Stop aquiring B
> 				|             |        |           |
> 				|             |        |           |      /----- Start aquiring A
> again
> 				|             |        |           |      |      and so on.
> Channel
> A:000000111111110000001111111100000011111111000000111111110000001111111100000011111111
> Channel
> B:000001111111000001111111000001111111000001111111000001111111000001111111000001111111
>
> Channel A is on INT0
> Channel B is on INT1
>
> INT0 should fire on the first high edge of channel A, after it is enabled.
>
> The only code that executes in that case is:
> TCNT1H=0;				// Timer starts at 0
> TCNT1L=0;
> Raw_Edge_Flag = 0xFF;	// Next time is the end of a pulse
>
> Then I exit the ISR.
>
> On the next high edge of channel A,  the ISR fires again, and the
> following executes:
>
> // Store output into serial buffer
> Raw_Data[0][*Raw_Data_In_Pointer] = TCNT1;
> GICR  |= (0<<INT0)|(1<<INT1);	// Disable INT0, Enable INT1
> Raw_Edge_Flag = 0; 	// Next time is the beginning of a pulse
>
> Now if this second part is a little long, that does not matter.
> I'm going to then be looking for input on the B channel, and doing the
> same thing.
> The idea is to capture the period of oscillation of the A channel and
> the B channel, as close as possible to the same point in time.
>

Check the NAKED attribute for the ISR. I think that it significantly
reduces or eliminates the pushes and pops at each end to save working
registers. But, then, you need to take care of just what you need your
self.

Jim

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.