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

Timer0 and Timer1 too slow on PIC18F46K22

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



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

Timer0 and Timer1 too slow on PIC18F46K22
PostPosted: Tue Nov 06, 2012 2:19 pm     Reply with quote

Hi, I'm using a PIC18F46K22 with compiler version 4.137

I'm having trouble with Timer0 and Timer1. They are way too slow. I've tested Timer2 and Timer4 and they are working perfectly. I've dumbed down my code to show the problem. I'm blinking an LED in this case, and as I have it written, I would expect it to strobe... but it's not, it's blinking on and off a couple times a second instead... Anyone know what the issue could be?

Code:


#include <18F46K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#device ADC=10
#device ICD=TRUE
#use delay(clock=16000000, int)


unsigned long int wait = 10;
short change = 0;
unsigned long int count = 0;


#INT_TIMER0
void TIMER0_isr()
{   
   set_timer0(10);
   count++;        
}               


void main ()
{
setup_timer_0(T0_DIV_1);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);

while(1)
{

   if(count >= wait)
   {

      if(change == 1)
      {
      output_high(PIN_B4);
      change = 0;
      }
      else if(change == 0)
      {
      output_low(PIN_B4);
      change = 1;
      }

   count = 0;
   }
   

}
}

Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 2:34 pm     Reply with quote

I've just checked the microchip data sheet.

Timers 1,3,5 are 16 bit timers/counters.

Timers 2,4,6 are 8 bit type modules.

Timer 0 can be either.

Does this help?

Mike
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 3:13 pm     Reply with quote

Yes, thanks!

I replaced the setup_timer_0 bit with this:

Code:


setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2|RTCC_8_BIT);



works great! thx!
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