interrupt delay

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

interrupt delay

Postby bear » Sun Jan 09, 2011 10:14 pm

how to interrupt during delay??
bear
Apprentice
 
Posts: 46
Joined: Tue Oct 05, 2010 2:11 am

Re: interrupt delay

Postby aurora » Sun Jan 09, 2011 11:49 pm

Which interrupt?

If you have enable interrupt(s), your program(in main) will automatically enter interrupt mode when it detect change(s). After complete the interrupt routine, it will return to where it left.
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: interrupt delay

Postby bear » Mon Jan 10, 2011 12:27 am

i want to interupt the programe during its doing delay(delay function)..
bear
Apprentice
 
Posts: 46
Joined: Tue Oct 05, 2010 2:11 am

Re: interrupt delay

Postby yonghui » Mon Jan 10, 2011 9:32 am

hi,

the interrupt wont be blocked by any routine in the main program. it will just jump out of it by pushing any necessary data to the stack and go into interrupt vector then execute the interrupt routine and jump back and pop off the stack the data and continue the routine in main program.

delay wont block the interrupt from happening
thanks&regards,
yh
yonghui
Professional
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: interrupt delay

Postby ABSF » Mon Jan 10, 2011 9:57 am

That means C doesnt use any of the timers to do its delay function?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: interrupt delay

Postby zhenning » Mon Jan 10, 2011 10:26 am

Allen, you can use timer to do the delay. I think, bear is afraid that the interrupt wont work during delay. Actually interrupt can work anytime it needs to as long as it is triggered
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: interrupt delay

Postby ABSF » Mon Jan 10, 2011 11:40 am

What I meant is C doesn't implement delay functions using timer interrupt?

There must be a clock tick of 1mS or 10mS somewhere in C so the delay function would be accurate. In other words, how does the delay function in C works?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: interrupt delay

Postby ABSF » Mon Jan 10, 2011 12:20 pm

I just found out that the delay functions in HiTech C works by wasting time in delay loops. So interrupt shouldn't have any conflict with it.

Thanks.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: interrupt delay

Postby shahrul » Mon Jan 10, 2011 2:38 pm

Sometimes I prefer timer interrupt to do delay, manual looping delay wasting program processing.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: interrupt delay

Postby aurora » Mon Jan 10, 2011 9:03 pm

Delay functions by counting the clock cycle to meet the duration specified. For example, calling delay of 1ms on a 10Mhz circuit, the compiler will calculate the number of clock cycle that it need to track. (In this case, 2500 clock cycle = 1ms).

You won't see this, but when it compile, it will write something like

CODE: SELECT_ALL_CODE
while(counter <= 2500)
{ do nothing
}

before jumping to the line.

So when you have an interrupt:
1. uC will stop the delay function (hence stop the counter)
2. Begin interrupt routine
3. Finish interrupt routine
4. Resume delay function (resume counter)

The problem with the above, the delay function ignore all the clock cycle which happen during interrupt. If your interrupt take 200uS, the delay function actually prolong to 1.2ms (instead of 1ms).

To overcome this, some people prefer to use timer interrupt. Because timer interrupt function exactly like above, but better as it also continue to count the counter.

Or, write your own delay function:
CODE: SELECT_ALL_CODE
while(counter <= 2500)
{ do something here
}

Well, people don't usually do this, unless there is something more important, like another even higher priority interrupt.
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 4 guests

cron