Hi, Matt
Without your "Faulty" code ... no luck to tell you something usable ...
could be as simple as an Interrupt flag you've forgotten to reset ...
COULD be ...
Alain
Hi, Matt
Without your "Faulty" code ... no luck to tell you something usable ...
could be as simple as an Interrupt flag you've forgotten to reset ...
COULD be ...
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Here is my code:
http://pastebin.com/f456e5db
Sorry it's a bit of a mess. If I comment the "IF" on Line 343, with the corresponding ENDIF, the code runs much more consistently. Also, "Encoder_Counting" at 395 disabled interrupts to do some processing, but only for a few lines while it copies a buffer. If I disable interrupts for the entire routine, one of my problems goes away. The problem was that "Current_Position" got changed randomly. I guessed that my interrupt was screwing with it, so I disabled interrupts for that entire routine. Theoretically, my interrupt shouldn't interfere with that at all. None of the variables there are used by the interrupt. When I copy from the variables which are used during the interrupt, I disable global interrupts. ::Confused::
About assembly interrupts, when I use them I only restore the W register. Do I need to do anything with wsave1, wsave2, or wsave3? I know I have to declare them, but I"m not sure where they get used.
Thanks,
MAtt
Try adding ...Originally Posted by dksoba
Code:DEFINE LOADER_USED 1 ' Bootloader Used
DT
It has nothing to do with the stack.
It just makes sure nothing is in the first 4 words.
Those locations are needed for the Bootloader.
And when you overflow the stack on 16F's ... Nothing happens.
It's when you return, that you may end up in the wrong place.
What else is in your Includes?
Can you post them too?
<br>
DT
My main code (updated):
http://pastebin.com/m7513a97d
Includes:
generic_include.inc:
http://pastebin.com/m1be5ca8f
LCD_Init_PortD.inc:
http://pastebin.com/m17a1888d
ADC10:
http://pastebin.com/m3b596568
In my updated code, something bizarre happens. My setup has an optical encoder w/channels A/B. When I start my program, it drops into "Main" after initializing variables and such. Main displays the current position of the encoder. As my code stands, it's fast and normal. The LCD updates w/the correct position at the speed it's supposed to. If I make ONE simple modification, if I comment out DEBUG_STACK declaration on line 30, all of a sudden for no apparent reason, the update rate of the LCD will be 0.5-1s. No idea what's going on. This isn't the only thing to trigger that. If I then comment out the PID_Loop routine, it'll be fast again... I'm so confused and frustrated and I'm not sure wtf is happening. Oh yea, Even if the LCD updates slowly, it still displays the correct position, which tells me that the interrupt service routine is working.
Thanks,
Matt
Ok, this is probably what's happening.
You've got just enough variables that 1 or 2 are getting pushed into BANK1.
In particular _portb_masked.
_portb_masked is used in the interrupt handler, but the Bank isn't being changed. So it ends up overwriting memory in BANK0.
Where it's located makes it overwrite PBP's system registers at R1.
If you comment out the DEBUG_STACK variable like you mentioned, the _portb_masked variable moves and then overwrites PBP's R0 system var.
As the placement of the variable moves, so does the apparent problem that it causes, which corresponds with your symptoms.
If you were to remove two more variables, _portb_masked would no longer be in BANK1, and it would probably run correctly.
Unless you are handling the Banking, any variables you use at the ASM level should be declared in BANK0.
HTH,Code:encoder_history VAR BYTE BANK0:encoder_history = 0 'Store the current and last state of channelA/B of the encoder portb_masked VAR BYTE BANK0:portb_masked = 0 'Masked port B to have only the encoder channels interrupt_debug VAR BYTE BANK0: interrupt_debug = 0
DT
Bookmarks