View previous topic :: View next topic |
Author |
Message |
dnacid
Joined: 09 Jul 2012 Posts: 4
|
|
Posted: Mon Jul 09, 2012 3:17 am |
|
|
I use Timer1 and count the overflows. All works, but when I use delay_ms in my main loop, then it will stop to count the timer overflows until delay finished.
I use:
PIC 18F45k22
20MHz Crystal
CCS 4.130
Why the overflows don't count at the delay time???
Here my code:
Code: |
int16 _counter = 0;
#INT_TIMER1
void Timer1_Overflow() {
_counter++;
}
void main() {
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(TRUE) {
lcd_putc(_counter + 48); // +48 to see the ASCII number 0-9
delay_ms(500); // no overflows for 500ms, but why???
}
}
|
|
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Jul 09, 2012 9:25 am |
|
|
According to the compiler manual (well, the version I have anyway), under delay_ms(), it says "the delay time may be longer than requested if an interrupt is serviced during the delay. The time spent in the ISR does not count toward the delay time"
I was not exactly sure what you were asking in your question, does this answer it for you ?
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
dnacid
Joined: 09 Jul 2012 Posts: 4
|
|
Posted: Mon Jul 09, 2012 9:39 am |
|
|
I tested now my code without LCD code. I used RS232 and i got correct counts when i use any timer irq. Only when i try to output the counts to lcd display, i got wrong counts.
My Testszenario looks like this:
i do some config for Timer to get every 10ms an overflow.
with RS232: i send a start signal from my pc and the board send after x ms the countet overflows. All works 100% fine.
with LCD: every 100ms counts are outputed to LCD. This means counts will change to count+10; but its only count + 4 overflows and not count + 10.
So i am missing 6 overflows, but why?
I tried this with every Timer from the PIC, always the same |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jul 09, 2012 9:43 am |
|
|
In other words, the problem is related to the LCD code not shown in your post. |
|
|
dnacid
Joined: 09 Jul 2012 Posts: 4
|
|
Posted: Mon Jul 09, 2012 10:30 am |
|
|
FvM wrote: | In other words, the problem is related to the LCD code not shown in your post. |
i use only LCD.h and because RS is on GND i ve no Read methods in LCD File. So there is no need to post the standard LCD File.
I started a new Project and write the code again and now it works. its very strange. hmmmm |
|
|
dnacid
Joined: 09 Jul 2012 Posts: 4
|
|
Posted: Mon Jul 09, 2012 10:59 am |
|
|
I'am sorry. it was my mistake.
there was this in my code:
Code: |
#INT_RB
void show_something(){
if (kbhit(CCT1)) {
lcd_putc(fgetc(CCT1)); // <- this line was only for a test
}
}
|
but i don't enabled the RB IRQ anywhere. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jul 09, 2012 12:14 pm |
|
|
Quote: | but i don't enabled the RB IRQ anywhere |
Doesn't matter. By calling a LCD routine in the interrupt, which in return uses the delay intrenally, you cause interrupt disable during delay_ms(), which is reported in the compiler messages.
Thus the described behaviour is pretty understandable. |
|
|
|