|
|
View previous topic :: View next topic |
Author |
Message |
Markus
Joined: 30 Oct 2003 Posts: 13
|
16F877A, TMROIF |
Posted: Tue Aug 17, 2004 4:42 am |
|
|
Hi,
Does sb. know of a problem with the Timer0 Interrupt Flag (TMR0IF) when set up as RTCC?
I define TMR0 as a RTCC
Code: |
setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_1);
|
to count pulses within a given time (Timer1).
Whenever I start Timer0 and Timer1 to start counting the pulses, TMR0IF is already set. I tried to clear it "by hand" before starting Timer0, but it gets set again immediately.
Code: |
TMR0IF = 0; // useless???
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
|
My current workaround is to start Timer0, wait until my routine is finished and start it again. In this case it works... But that wastes valuable time. ;-)
I know it's a strange problem. I hope somebody of you can help me out.
Thank you in advance.
Markus |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 17, 2004 11:13 am |
|
|
Post a small but complete test program, which will demonstrate the problem. Also tell us what you are using for your external clock source
for Timer0. |
|
|
Markus
Joined: 30 Oct 2003 Posts: 13
|
|
Posted: Tue Aug 24, 2004 5:54 am |
|
|
Hi PCM_Programmer,
I don't know if this is complete enough (I can't locate the error myself, so I don't know which part to post).
Code: |
#int_timer0
void TMR0_isr() {
if (getting_master_speed) master_speed_temp += 255;
}
#int_timer1
void TMR1_isr() {
disable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER1);
master_speed = 0x3FF - (master_speed_temp + get_timer0());
getting_master_speed = false;
}
static void get_master_speed() {
disable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER1);
getting_master_speed = true;
TMR1Mode = getSpeed;
set_timer0(0);
master_speed_temp = 0;
// ~5.5ms (@12MHz)
set_timer1(49000);
// is 1 and will be 1 at first run
// cleared before second run
TMR0IF = 0;
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
}
|
PCM programmer wrote: |
Also tell us what you are using for your external clock source for Timer0.
|
I'm counting motor increments. The maximum is 300 rpm x 1024 (resolution) x 4 (multiplication) = 1228800 increments/min.
Markus |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 24, 2004 12:56 pm |
|
|
I wanted a full test program that I could drop into MPLAB and compile,
and program into my demo board. I wanted a program that would
test the TMR0IF bit at appropriate times, and say "Right here, at this
line of code, I can tell that the bit is at an incorrect value. Please help
me to discover why this is happening".
You just gave me code fragments.
I wanted to see your #bit declaration for the TMR0IF bit.
It might be incorrect.
Historically, there have been problems with using external clocks
with timer/counters in the 16-series PICs. You might be experiencing
one of the those problems, or it might be something else.
I don't have time to write a test program for you today.
And, I mean a full program, showing all #fuse , #use delay, #include
statements, etc., but also with only just enough code to demonstrate
the problem. You must write the test program. |
|
|
|
|
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
|