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

Interrupt problem

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







Interrupt problem
PostPosted: Mon Aug 25, 2008 1:33 am     Reply with quote

Dear Sir/Madam

I use ccs c pic c compiler in my office. I have a problem with rs232
interrupt modules. I attached my code at the end of the mail. In my
code, in spite of disable the rs232 interrupts, interrupts are working.
I cannot solve this problem, would you help me ? It is important.
Code:

#int_rda
void isr(void)
{
         disable_interrupts(GLOBAL);
         disable_interrupts(int_rda);
         data = getc();
       if(data=='!'|| data=='u' )
       {


         output_toggle(PIN_A3);
         a=0;
              while(a<71)
            {
             while(goster<15)
            {
               output_d(a);
               output_b(0x05);
               Delay_us(1000);
               a=a+1;
               output_d(a);
               output_b(0x2A);
               Delay_us(1000);
               a=a+1;
               output_d(a);
               output_b(0x5C);
               Delay_us(1000);
               a=a+1;
               output_d(a);
               output_b(0x2A);
               Delay_us(1000);
               a=a+1;
               output_d(a);
               output_b(0x05);
               Delay_us(1000);

              a=a-4;

              goster=goster+1;
            }
            goster = 0;
            a=a+1;
         }

         a=0;

      }
      enable_interrupts(GLOBAL);
      enable_interrupts(int_rda);
     
}
Ttemah
Guest







PostPosted: Mon Aug 25, 2008 9:37 am     Reply with quote

First, _never_ enable the global interrupt inside an interrupt event. This is an absolute 'no no' on the PIC. The PIC has _hardware_that disables the global interrupt when interrupt events are called, and re-enables it, when they exit, _after the exit occurs_. If you re-enable interrupts _inside_ the handler, an interrupt can interrupt itself. Since the PIC does not support 're-entrancy' (where a routine calls itself), this potentially leads to disaster.
You can completely remove the code to enable/disable the interrupts.
Second, 'think again', about having such huge delays inside the interrupt handler. The PIC, has a grand total of just two characters of serial buffering (except for a few of the latter models with more). If your baud rate is (say) 9600bps, a character can arrive every 1.04mSec. With a delay of 1Sec inside the interrupt handler, you could potentially miss nearly 1000 characters.... Either set a flag, to say that you want the toggle and delay, and do this in the main code, or use a hardware timer, with it's own interrupt to handle this. A glance at the code, suggests the routine can actually take up to about a second to complete. Ouch. If you generate a hardware timer interrupt at 1mSec intervals, and have this walk through the five required output toggles, and the number of loops required, your hardware can carry on handling the RS232 when needed.
Third, make sure you have the keyword 'errors' in your RS232 definition. Without this, the serial hardware, will go into a 'hung' state, if even one character is not handled.

Best Wishes
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