CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F25k42 Interrupts Not Working - At all
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asgudeman



Joined: 25 Apr 2018
Posts: 13
Location: Arizona

View user's profile Send private message

PIC18F25k42 Interrupts Not Working - At all
PostPosted: Wed Apr 25, 2018 6:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 25, 2018 8:49 pm     Reply with quote

And what is your CCS compiler version ? The K42 parts are new and
CCS is still making changes. List of versions:
http://www.ccsinfo.com/devices.php?page=versioninfo
asgudeman



Joined: 25 Apr 2018
Posts: 13
Location: Arizona

View user's profile Send private message

PostPosted: Thu Apr 26, 2018 9:23 am     Reply with quote

I am using 5.078 CCS compiler with MPLAB X v4.05
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Thu Apr 26, 2018 10:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 26, 2018 11:03 am     Reply with quote

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: 19504

View user's profile Send private message

PostPosted: Thu Apr 26, 2018 12:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 26, 2018 3:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 26, 2018 6:34 pm     Reply with quote

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: 19504

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 12:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 5:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 4:03 pm     Reply with quote

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: 19504

View user's profile Send private message

PostPosted: Fri Apr 27, 2018 11:02 pm     Reply with quote

Just the current version 4.15. 4.05 is quite old.
asgudeman



Joined: 25 Apr 2018
Posts: 13
Location: Arizona

View user's profile Send private message

PostPosted: Mon May 07, 2018 5:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 07, 2018 6:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 07, 2018 8:20 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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