CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

What's a nifty way to jump to certain code after interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

What's a nifty way to jump to certain code after interrupt
PostPosted: Wed Feb 28, 2007 6:32 pm     Reply with quote

Over an RS-232, I'm sending commands to a 16F876A. I'm receiving the bytes using the INT_RDA interrupt.

When certain commands are sent, upon return to main, I'd like to immediately go into a subroutine. The problem with this is some of the operations happening within main when an interrupt is fired take some time to complete upon return from the interrupt. Hence, the commands received in the interrupt aren't very responsive.

Any ideas on how I could overcome this? I know the *wrong* way would be to have the desired subroutines called from within the interrupt - but I know that's incorrect.

Thanks!
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: What's a nifty way to jump to certain code after interru
PostPosted: Wed Feb 28, 2007 7:33 pm     Reply with quote

evsource wrote:
I know the *wrong* way would be to have the desired subroutines called from within the interrupt - but I know that's incorrect.


I would recommend a subroutine call from the interrupt. It's not always a wrong way. If the subroutine you want to call executes quickly with respect to the worst-case (shortest) delay between the interrupts, and if the timing is critical - you can call the subroutine from the ISR.

By the way, if you give us a little more context of your problem, you would get more useful responses. E.g. :
- What is the time-critical task?
- What are the timing requirements?
- What does the main() do on a background?
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

Re: What's a nifty way to jump to certain code after interru
PostPosted: Thu Mar 01, 2007 12:31 am     Reply with quote

kender wrote:

I would recommend a subroutine call from the interrupt. It's not always a wrong way. If the subroutine you want to call executes quickly with respect to the worst-case (shortest) delay between the interrupts, and if the timing is critical - you can call the subroutine from the ISR.


The subroutine could take a while to complete. The initial INT_RDA interrupt would get fired when a user (which could be someone typing and could be software handling it) sends a single byte hexadecimal command, e.g. setting a threshold. The next byte that the PIC program is expecting is the parameter, e.g. what the threshold is. In the case of software interaction with the PIC, the commands would come very quickly. But if the user is plunking out the commands, it could take on the order of seconds.

Explaining this is getting my mind churning with ideas. The initial command byte would be processed in a subroutine called from within the INT_RDA interrupt. All the subroutine would do is recognize that it was a command, and determine how many bytes should follow it as parameters. Subsequent bytes received would be recognized as the parameters. As soon as the number of required parameter bytes were received, the appropriate subroutine to process the command would be called, which would quickly execute since the parameters were already received.

kender wrote:

By the way, if you give us a little more context of your problem, you would get more useful responses. E.g. :
- What is the time-critical task?
- What are the timing requirements?
- What does the main() do on a background?


main() is communicating with several (up to 16) other PICs that are collecting data. Sometimes, those other PICs take awhile to respond since they are waiting on certain events. The entire process to collect from all PICs can take 1-2 seconds. So if a user enters a command, it can be very unresponsive if main() is just beginning a new batch of requests. I think the method I described above will satisfy my requirements - commands with their parameters will be received immediately, and the polling loop will continue on its merry with only very short interrupts from the ISR.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Thu Mar 01, 2007 1:30 am     Reply with quote

evsource wrote:
The subroutine could take a while to complete.

There’s no free lunch: if (on the long run) the cumulative processing time for the interrupt is longer then the average time between the interrupts, you will be loosing the interrupts. You just need to have the processing budget meet.

I think, what you want to accomplish can be called “serial communication protocol engine”. Here’s a standard way of doing this:
- ISR receives the bytes and stores them in a global array (buffer). When the ISR determines that it has a complete command, it will set a flag (global variable).
- main() checks the flag in a loop and processes the command. To speed up the response – check the flag every time after you poll a slave (16 times in a full cycle instead of 1).

evsource wrote:
…those other PICs take awhile to respond since they are waiting on certain events

IMHO, the fact that one of the slaves can cause the master to suspend for a long time is a design flaw. You need a way for a slave to tell a master that the slave is busy and the master would procede with its own duties and check the slave later.


Last edited by kender on Sat Mar 17, 2007 12:55 am; edited 1 time in total
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Sat Mar 03, 2007 8:25 am     Reply with quote

Hi,

You could set a variable flag in the isr and then poll this variable in the main function.

For example to process the INT_RDA interrupt you could use...

Code:

#iNT_RDA
usart_isr()
{
   bRcvFlg=TRUE;
   cRcvData=getc();

}


void main()
{


  do
  {

     if (bRcvFlg==TRUE)
     {
        bRcvFlg=FALSE;
        //<the>

     }

  }while(TRUE);

}




Hope this helps you ...

thanks
arunb
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group