|
|
View previous topic :: View next topic |
Author |
Message |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
Some unexpected action with timer |
Posted: Thu May 13, 2010 2:09 am |
|
|
Hi all ,
I am in a great confusion.
Can anybody help me??
In my project I am using timer 0.
So I wrote a sample program for checking the timer 0 interrupt.
But my timer isr executing continuously even after the completion of my main routine. I am not using any infinite loop in my program. Here I am giving my code. I am using pic16f877a and CCS3.43.
Code: |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#int_TIMER0
TIMER0_isr()
{
printf("Timer Isr\n");
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1( T1_INTERNAL | T1_DIV_BY_4);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
set_timer0(251);
printf("Main Ends\n");
}
|
It prints "Main Ends" in the hyper terminal, but after that also it continuously printing "Timer Isr" in the hyper terminal.What may be the reason???
According to my knowledge my program should stop after the completion of main. But here it is not happening. It continues to execute the Isr even after the completion of main.
Where i went wrong???Can anybody help me??
Thanks in advance. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu May 13, 2010 2:20 am |
|
|
There are several modes of sleep, consult the datasheet for your pic.
The state of sleep it enters after the end of program execution by executing the sleep() instruction can stop interrupts and turn off IO lines or keep interrupts running and/or keep IO lines in their current state.
Your options are to make sure that sleep disables interrupts (if possible) or disable them yourself before the end of the program. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Thu May 13, 2010 4:24 am |
|
|
You don't show your fuses.
One possibility, would be that the watchdog is enabled. In which case, the chip will wake up from sleep when this times out, and execute the interrupt.
Normally timer0, will stop when the sleep executes, but it may already have triggered before the sleep is called, in which case, the sleep will not execute, and the timer ISR will.
Problem here is the sheer duration of the timer ISR. Probably over 10mSec for the printout. The timer is counting all the time, so will have triggered. Then the interrupt will be cleared when the ISR is left, but will trigger again, between 0, and 255 instructions latter. There are typically 30 instructions involved in exiting the ISR, so depending on just where it has got in the count, there is a high probability that the interrupt will re-trigger before the routine exits. If an enabled interrupt flag is active in the first clock cycle of the sleep instruction, then the sleep won't execute, and the ISR will be called.
Best Wishes |
|
|
|
|
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
|