View previous topic :: View next topic |
Author |
Message |
JerryR
Joined: 07 Feb 2008 Posts: 167
|
Can't get interrupts to fire on PIC16F1823 |
Posted: Tue Aug 30, 2016 12:45 pm |
|
|
New PIC for me, but i can't seem to get any timer interrupt to work! Wow, simple right?
PCWH 5.062
PIC16F1823 ON STABLE ELECTRICAL DESIGN (MULTIPLE BOARDS)
Simple code (right out of CCS Examples):
Code: |
#include <16F1823.h>
#use Delay(internal=8000000)
#define HIGH_START 114
byte seconds, high_count;
#INT_Timer0
clock_isr() {
if(--high_count==0) {
delay_us(1);
}
}
main() {
high_count=HIGH_START;
set_rtcc(0);
setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts(INT_Timer0);
enable_interrupts(GLOBAL);
while(TRUE);
}
|
Timer0 interrupt never fires. high_count stays at 114 after minutes. Have also written routines using other timers with same results-no interrupts. Am I losing my mind? Anyone see an issue? Have never had any problems with simple interrupts before.
Thanks! |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
Solved--but still puzzled |
Posted: Tue Aug 30, 2016 2:38 pm |
|
|
Well, kinda solved the issue. Consistently interrupts work using ICD3, but consistently does not work using a PICKit3 debugger. Still interested in knowing why.
Thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 30, 2016 4:52 pm |
|
|
Post your test procedure and environment. Are you running this test
in Debug or Release mode ? Are you using Debug Animate mode ?
What's your compiler version ? Are you using MPLAB 8.92 or MPLAB X
and what version ?
My guess is you are running in Debug mode, because I don't see any
code that toggles a pin so that you could put a scope on it. |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
|
Posted: Tue Aug 30, 2016 6:01 pm |
|
|
Hi PCM:
Compiler version 5.062, MPLab 8.92, used PicKit3 and ICD3 in Debug mode and set breakpoints at both points inside ISR. Also, variable high_count never changed values after minutes. Have never used animate.
Never entered ISR using PicKit3, ICD3 worked well and resumed code development with no issues. Three custom-designed targets all are stable and good hardware. Repeated results back and forth between PicKit3 and ICD3. I'll try using my RealICE tomorrow just for curiosity.
Thanks for your interest. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 02, 2016 6:16 am |
|
|
At first I tried it with your program and breakpoints in the isr didn't work.
Then...
I didn't like your program so I modified it to the way I would write a
program. Then it worked. Lol. I am loving this.
I set MPLAB v8.92 to compile in Debug mode, compiled the program,
and burned it into the 16F1823. Then I clicked to the left of the
output_toggle(PIN_C0) line in the source code to put a red breakpoint on
it. Then I clicked the "run" arrow in the MPLAB toolbar. It stops with the
cursor on the output_toggle(PIN_C0) line. I'm running this on the
Microchip Low Pin Count board, so it toggles the LED on Pin C0 each time
I click run. It's working great. This was tested with vs. 5.061.
Code: |
#include <16F1823.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=500KHZ)
#INT_TIMER0
void clock_isr()
{
output_toggle(PIN_C0); // Put a breakpoint on this line with Pickit 3
}
//======================
void main()
{
output_low(PIN_C0);
set_timer0(0);
setup_timer_0(T0_INTERNAL | T0_DIV_256); // Blink LED at ~ 1 Hz
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(TRUE);
}
|
Last edited by PCM programmer on Fri Sep 02, 2016 6:22 am; edited 1 time in total |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
|
Posted: Fri Sep 02, 2016 6:22 am |
|
|
Hi PCM:
Yes, interrupt working well now after burning code into target. Also worked while debugging with a ICD3 and RealICE emulators. Interrupt never fires while debugging with a PICKit3. Crazy! Anyway I moved ahead and finished the project.
As usual, thanks for your interest in the issue! All the best. |
|
|
|