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

Why Timer1 overflows don't count during delay_ms ?

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



Joined: 09 Jul 2012
Posts: 4

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 09, 2012 3:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 09, 2012 9:25 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 09, 2012 9:39 am     Reply with quote

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 Crying or Very sad
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Jul 09, 2012 9:43 am     Reply with quote

In other words, the problem is related to the LCD code not shown in your post.
dnacid



Joined: 09 Jul 2012
Posts: 4

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 09, 2012 10:30 am     Reply with quote

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 Question
dnacid



Joined: 09 Jul 2012
Posts: 4

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 09, 2012 10:59 am     Reply with quote

Embarassed 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

View user's profile Send private message

PostPosted: Mon Jul 09, 2012 12:14 pm     Reply with quote

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.
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