View previous topic :: View next topic |
Author |
Message |
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
interrupt with PIC18F6722 |
Posted: Wed Aug 29, 2007 10:01 am |
|
|
Hello,
I'm actualy using a software with a PIC18F4520, and i want to use this code on a PIC18F6722.
I've got a problem to configure my interrupt (RTCC), the code on the interruption is not launched,
On my configuration i put the following code :
// Hardware SPI :
// - Master mode
// - Data valid when clock goes High to Low
// - SPI clock divide by 64 (115.2 kHz)
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_64);
setup_spi2(FALSE);
// Timer 0 (RTCC) :
// - Resolution 138 µs
// - Overflow 35.7 ms
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
// Timer 1 :
// - Resolution 4.3 µs
// - Overflow 284 ms
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
If somebody can help
Thank you
Bruno |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 29, 2007 11:27 am |
|
|
You need to enable interrupts for Timer0 (the RTCC). Currently, you
only have interrupts enabled for Timer1. |
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
|
Posted: Thu Aug 30, 2007 1:57 am |
|
|
Hello, thanks for the answerd,
I enable the timer 0 on the main. But when the code is executing :
enable_interrupts(INT_RTCC);
the PIC stop.
i check the code launched by the interrupt and everything is good.
Bruno |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 30, 2007 2:40 am |
|
|
Quote: | I enable the timer 0 on the main. But when the code is executing :
enable_interrupts(INT_RTCC);
the PIC stop. | This is completely different from what you told us in your original post. This behaviour suggests the interrupt is being called but never finishes. This can be caused by:
1) A missing interrupt handling function, than the interrupt flag is never cleared.
or
2) An interrupt function taking too long to finish so the timer generates a new interrupt before handling the current one is finished. Common mistakes are a delay_ms() or printf() call from the interrupt handler.
Another problem is in your calculations for the different clock speed configurations. The SPI-bus clock is derived from Fosc but the timers use Fosc/4. This means that the xxx_DIV_BY_xxx for SPI and timers are not giving the same timing as you now assume. You didn't mention your clock speed so I can't tell which textual comments are wrong now. |
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
|
Posted: Thu Aug 30, 2007 2:56 am |
|
|
Hello, ckielstra thanks for your answered,
My external clock is an 7.37Mhz, the configuration of the interrupt shorter, the code launch by the interrupt is too long for the cycle of the interrupt, case 2 in you explication.
Know i modified my code and the interrupt is working, thanks for your help
Bruno |
|
|
|