View previous topic :: View next topic |
Author |
Message |
hoangtuanthien
Joined: 25 May 2013 Posts: 7
|
Problem with timer interrupts |
Posted: Fri Jun 21, 2013 10:28 am |
|
|
i'm using the PIC 18F4550.
- [i'm just configing interrupt timer0 but timer timer0 just counts about several seconds then it stops. i don't know why it can not operate. please help me debug, config interrupt for timer.] i solved
- i have new problem that i set timer0 be overflow 10us, but it seems incorrect, please help me check it.
code
Code: | #include <18F4550.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES VREGEN //USB voltage regulator enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES ICPRT //ICPRT enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(crystal=16000000, clock=16000000)
int16 dem;
#int_TIMER0
void TIMER0_isr(void)
{
if(interrupt_active(int_timer0))
{
set_timer0(236);
dem++;
if(dem==50000)
{
dem=0;
output_toggle(pin_c1);
}
}
}
void main()
{
set_timer0(236);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2|RTCC_8_bit); //128 us overflow
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
}
|
Last edited by hoangtuanthien on Sat Jun 22, 2013 5:25 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Jun 21, 2013 11:03 am |
|
|
Hi,
I didn't look over your entire code carefully, but I do see one glaring problem immediately. The CCS compiler inserts a hidden sleep instruction
at the end of your code by default. You must not allow your program to ever reach this sleep instruction if you want the code to continue running!
Look at the .lst file that is generated when you compile your code, and you'll see what I mean!
To avoid this issue, add the following code shown in bold in the place shown:
Quote: |
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(1);
}
|
John |
|
![](templates/subSilver/images/spacer.gif) |
hoangtuanthien
Joined: 25 May 2013 Posts: 7
|
|
Posted: Fri Jun 21, 2013 6:25 pm |
|
|
thanks, John. it operated |
|
![](templates/subSilver/images/spacer.gif) |
|