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 support@ccsinfo.com

would the #org compiler directive help?

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



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

would the #org compiler directive help?
PostPosted: Wed Jun 03, 2009 1:52 pm     Reply with quote

Code:

#include <16F886.h>

#include <math.h>

float a, b;

long round(float fl) {
   return ( (long)floor(fl + 0.5) );
}

#int_RB
void  RB_isr(void) {   
   a = 2.1;
   b = round(a);
}

void main() {
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   //Setup_Oscillator parameter not selected from Intr Oscillator Config tab
   
   // TODO: USER CODE!!
   while (true) {
      a = 1.1;
      //b = round(a);
   }
}


Could some one tell me why do I receive 2 Warning 216 messages if I uncomment the last line in my code and whether these warnings could prevent my code from running properly?

I made some testing with the #org compiler directive and I couldn't succeed making my code running without these warning messages.

Many thanks in advance
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 2:06 pm     Reply with quote

If you would read the Warning message
Quote:
>>> Warning 216 "round.c" Line 34(2,3): Interrupts disabled during call to prevent re-entrancy:

You would know, that compiler disabled interrupts during execution of this code, because it takes a longer time. So if you are not using some interrupt routines in your program you can ignore this message. Wink
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 2:37 pm     Reply with quote

More specifically, you are calling the round() function inside the ISR and also in main. Recursive code is not allowed on the PIC so, to keep from entering the round() function in the ISR while you are in using it in Main, interrupts are disabled while in round().
_________________
Google and Forum Search are some of your best tools!!!!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 3:03 pm     Reply with quote

If fast, low latency interrupt action is intended, float arithmetic should be avoided in the ISR.
Ttelmah
Guest







PostPosted: Fri Jun 05, 2009 4:21 am     Reply with quote

As to why the code would not run though, look at what int_RB _must_ do.
Some interrupts (RB, RDA etc.), signify _hardware_ events, that must be handled, or they will keep triggering for ever. The RB interrupt signals that the PortB pin levels have changed from the levels latched inside the chip. You _must_ reset the latch, or the interrupt will never exit. You need to read PortB in the handler.

Best Wishes
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

would the #org compiler directive help?
PostPosted: Sun Jun 07, 2009 1:58 pm     Reply with quote

Many thanks to all of you for the feedback. I'll try to do the best out of it.
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