View previous topic :: View next topic |
Author |
Message |
picj1984
Joined: 01 Mar 2010 Posts: 73
|
Timer0 and Timer1 too slow on PIC18F46K22 |
Posted: Tue Nov 06, 2012 2:19 pm |
|
|
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
|
|
Posted: Tue Nov 06, 2012 2:34 pm |
|
|
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
|
|
Posted: Tue Nov 06, 2012 3:13 pm |
|
|
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! |
|
|
|