PDA

View Full Version : PIC16F887 erratic behavior with DT interrupts



GordonCook
- 23rd October 2012, 04:46
I've been working on a program that uses Darrel's interrupts (thank you!) that has worked fine until I added more code. It uses portB interrupt on change.
I am using PBP3 and Microcode Studio plus and the latest MPLAB assembler.
It appears that a subroutine which works fine on the first call then behaves erratically when called a second time from another place, basically returning to an entirely different place in the program and gets stuck in a loop consisting of a few lines of code.
The behavior is different if I move the interrupt handlers around in the program. Still gets stuck, just in different places.
I get 3 'crossing page boundary' warnings.
Thank you in advance for your thoughts?

Demon
- 23rd October 2012, 05:20
Have you tried moving the interrupt handlers to the top of your program?

It would be easier for members to help you if you posted your code.

Suggestion: make a backup, trim your code down and test for changes (remove 1 logic at a time, it's easier to track down weird stuff).

In-circuit debugging is awesome if your PIC is supported.

I send messages to Microcode Studio Serial Communicator on the PC via RS232 to help debug.

Robert

GordonCook
- 23rd October 2012, 20:36
Hi Robert,
Thanks for your reply. The interrupt handlers are near the beginning of the program,after the main loop, but before all the subs. I moved them to the very beginning with the similar results, although it does seem to make a difference in exactly where the program goes.
Tonight I'll take up your suggestion to reduce the code and see I can get more insight that way. I had the ICD working at one point, but have not had much luck with that recently, but I may spend some time trying to fix that. I'll also see if I can get the serial communicator working, but the program functions are time sensitive and the ICD and serial activity slows things down too much.
I've been monitoring the I2C bus and also added a debug LED to see where the code is going, which is how I know it's going places that it shouldn't.
Gordon

GordonCook
- 24th October 2012, 13:42
I can post the program, but it's pretty convoluted and may be hard to follow as it has 'grown' as I've added functionality. It interacts with a rotary encoder, a couple of switches, a DSP, a AM/FM tuner IC, and a stepper motor. I'm a hardware guy, who knows enough to comment and use sub's, but am not a software person by nature or training. So the structure may be sub optimal, at the least.
I guess the question I have is..Is it possible that the compiler is creating this problem, or is it something about the interrupt assembly code, or should I continue to look for an error in my code?
Anyway, if someone wants to look at it I'll post it here.

mackrackit
- 26th October 2012, 02:58
Is it possible that the compiler is creating this problem, or is it something about the interrupt assembly code, or should I continue to look for an error in my code?
I will bet on the last option ;)

Post your code and let someone offer some help.