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

BUG with delay_ms() in PCH 3.249
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PostPosted: Mon Apr 23, 2007 3:53 am     Reply with quote

You are running into the Warning 216 problem, please run the following demo program. both main() and isr used the same delay_us(), then, the compiler will disable ISR before the delay_us() in main(). i.e. whenever the main() level and ISR using any identical function, this will happen, and you are asking for truoble !

Code:

#include <18F452>

#define  CLOCK_PERIOD      4        // in unit of 100 usec

#use delay(clock= 40000000)
#use rs232(baud = 115200, xmit=PIN_C6, rcv=PIN_C7)
#use fast_io(B)

int16 ccp1_compare_period, i, k;

void my_delay_us ( int16 n )        // delay n+2 usec
{
   while(n--);
}

#INT_CCP1
void rt_daq_ctrl()
{
   CCP_1 += ccp1_compare_period;    k++;

   output_high( PIN_B7 );      // take a scope and watch it carefully

      delay_us ( 300 );             // this will cause big trouble
// my_delay_us ( 300 );       // this is the safe solution

   output_low ( PIN_B7 );
}

void main()
{
   set_tris_B ( 0b00000000 );

   setup_ccp1 ( CCP_COMPARE_INT );
   setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );

   ccp1_compare_period = CLOCK_PERIOD * 125;

   enable_interrupts ( INT_CCP1 );
   enable_interrupts (  GLOBAL  );

   while(1)
   {
      for (i=0; i<500; i++)
      {
         output_high( PIN_B0 );     // look at scope
         delay_us ( 800 );

         output_low ( PIN_B0 );
      }
      printf( "\r\n k= %lu", k );   k= 0;
   }
}
 


Have fun !

Best wishes

C-H Wu
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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