View previous topic :: View next topic |
Author |
Message |
asgudeman
Joined: 25 Apr 2018 Posts: 13 Location: Arizona
|
PIC18F25k42 Interrupts Not Working - At all |
Posted: Wed Apr 25, 2018 6:20 pm |
|
|
I am very new to CCS, but have been using XC8-32 for about 6-7 years.
I am just trying (at this point) to make a timer interrupt do just that, interrupt.
I have checked PIE registers, TIMxCON registers. All are where they are supposed to be.
Here is a sample of the code (the entire set is too big to copy)
Code: | #include <18F25K42.h>
#device PIC18F25K42
#device ICD=TRUE
#FUSES NOWDT //No Watch Dog Timer
#FUSES RSTOSC_HFINTRC_64MHZ
#FUSES NOCKS //Clock Switching Disabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(internal=64M)
void main(void)
{
enable_interrupts(GLOBAL);
// Use TIM2 as SysTick timer (1 ms)
// (1/64000000)*4*128*125 = 1000 us or 1.0 kHz
setup_timer_2(T2_DIV_BY_128, 125, 1);
enable_interrupts(INT_TIMER2);
}
#INT_TIMER2
void TIMER2_isr(void)
{
sys_time++;
} |
I tried this exact same code on an evaluation board (different processor of course), and we were firing interrupts left and right. However, I can't get any to work on this specific chip. Any leads or help would be GREATLY appreciated. THANK YOU. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
asgudeman
Joined: 25 Apr 2018 Posts: 13 Location: Arizona
|
|
Posted: Thu Apr 26, 2018 9:23 am |
|
|
I am using 5.078 CCS compiler with MPLAB X v4.05 |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Thu Apr 26, 2018 10:53 am |
|
|
shouldn't there be a clock source for the timer setup? maybe it's defaulting to an external input.
Try adding T2_CLK_INTERNAL to the setup. |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Thu Apr 26, 2018 11:03 am |
|
|
looking at the device.h file, it looks like it defaults to T2_CLK_T2IN which is an external input.
try
Code: |
setup_timer_2(T2_DIV_BY_128 | T2_CLK_INTERNAL, 125, 1); |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19485
|
|
Posted: Thu Apr 26, 2018 12:15 pm |
|
|
and the divider needs to be 124, not 125. The division is by PR2+1. So to divide by 125 you have to load 124. |
|
|
asgudeman
Joined: 25 Apr 2018 Posts: 13 Location: Arizona
|
|
Posted: Thu Apr 26, 2018 3:19 pm |
|
|
I have tried putting all [spam] sources just to force an interrupt - but to no avail. The divider value is just for show right now, just trying to get basic interrupt functionality. What is the likelihood that the .h file has the vectors mapped wrong? Low? |
|
|
asgudeman
Joined: 25 Apr 2018 Posts: 13 Location: Arizona
|
|
Posted: Thu Apr 26, 2018 6:34 pm |
|
|
Could this be a thing where the specific target isn't fully supported with debug by a Microchip ICD3 debugger? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19485
|
|
Posted: Fri Apr 27, 2018 12:25 am |
|
|
Don't get me wrong, but I compiled:
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES RSTOSC_HFINTRC_64MHZ
#FUSES NOCKS //Clock Switching Disabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(internal=64M)
int16 sys_time=0; //Omitted from posted code
void main(void)
{
enable_interrupts(GLOBAL);
// Use TIM2 as SysTick timer (1 ms)
// (1/64000000)*4*128*125 = 1000 us or 1.0 kHz
setup_timer_2(T2_DIV_BY_128 | T2_CLK_INTERNAL, 124, 1);
enable_interrupts(INT_TIMER2);
}
#INT_TIMER2
void TIMER2_isr(void)
{
sys_time++;
}
|
And running in the current MPLAB simulator, it merrily increments 'sys_time'.
I'd be looking at your debugging environment. |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Fri Apr 27, 2018 5:16 am |
|
|
You might want to try adding a line of code in the main loop that turns an LED or at least an unused PIC output pin on/off based on the value of sys_time.
Be careful, though. You have a 16-bit value you are changing in the interrupt and also reading in the main program. It's possible for the interrupt to occur while it's in the process of being evaluated in the main program. |
|
|
asgudeman
Joined: 25 Apr 2018 Posts: 13 Location: Arizona
|
|
Posted: Fri Apr 27, 2018 4:03 pm |
|
|
Ttelmah wrote: | And running in the current MPLAB simulator, it merrily increments 'sys_time'.
I'd be looking at your debugging environment. |
Are you using a later version of MPLAB X? I have 4.05 currently installed with all the plugins I could find |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19485
|
|
Posted: Fri Apr 27, 2018 11:02 pm |
|
|
Just the current version 4.15. 4.05 is quite old. |
|
|
asgudeman
Joined: 25 Apr 2018 Posts: 13 Location: Arizona
|
|
Posted: Mon May 07, 2018 5:31 pm |
|
|
All,
I went ahead and ordered the PIC U64 device so I could more fluidly develop in the CCS compiler. Still no interrupts firing. Heck, I am having difficulty getting this program to have step-through capability. Any other ideas? |
|
|
asgudeman
Joined: 25 Apr 2018 Posts: 13 Location: Arizona
|
|
Posted: Mon May 07, 2018 6:04 pm |
|
|
Checking interrupt vectors right now, but timers 0, 1, 3... dont work with interrupts while timers 2, 4, 6... do.
I havent checked the comparator yet |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 07, 2018 8:20 pm |
|
|
I can buy one and check the problem. The reason I didn't do it so far
is quite often, the person will come back and say, I'm sorry I left off the
bypass caps or the Mclr circuit and now it works OK.
If you can assure me that everything is correct circuit-wise, I'll order
that PIC and test it.
One question is, have you tested the interrupts without using the debugger ?
Just test it in a Release Mode program. Blink an LED to prove it's in
the interrupt routine or output a character with putc(). Something simple. |
|
|
|