View previous topic :: View next topic |
Author |
Message |
Momboz
Joined: 03 Jun 2009 Posts: 29
|
would the #org compiler directive help? |
Posted: Wed Jun 03, 2009 1:52 pm |
|
|
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
|
|
Posted: Wed Jun 03, 2009 2:06 pm |
|
|
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. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Wed Jun 03, 2009 2:37 pm |
|
|
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
|
|
Posted: Wed Jun 03, 2009 3:03 pm |
|
|
If fast, low latency interrupt action is intended, float arithmetic should be avoided in the ISR. |
|
|
Ttelmah Guest
|
|
Posted: Fri Jun 05, 2009 4:21 am |
|
|
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
|
would the #org compiler directive help? |
Posted: Sun Jun 07, 2009 1:58 pm |
|
|
Many thanks to all of you for the feedback. I'll try to do the best out of it. |
|
|
|