Electronics Forums

Electronics Forums > Newsgroups > Electronics Newsgroups > 8bit Microcontrollers > Banking Pic 16F877

Reply
Thread Tools Display Modes

Banking Pic 16F877

 
 
NDS
Guest
Posts: n/a
 
      06-06-2007, 10:44 AM
Hi all. I'm having a strange problem here with some debugging. Got an ide
that the problem is perhaps relatet to some sort of bank-switching. My
qustion is :

I'm in program bank ?.
Make a call to a routine in bank1.
In here i recieve an INT whitch takes me to some code in programbank 0. In
the INT i save PCLATH, then make several call's. When done, i restore
PCLATH, then retfie.
Now i'm back with the routine in bank 1, but after return it seemes like
sometimes i'm not returning to the bank from where the original call was
made (this could be any one).

The datasheet states that you need to set PCLATH only on the way OUT - not
on return? Is that also true after servicing a INT in a nother bank,
containing call's of it's own ?
If not - is it "wrong" to have "common routines" like switch-reading which
need to be called from different banks - out of bank 0? Or is there some
other way round this?

If there's a "simple" problem here, i would really like to know - before
spending even more time debugging .

Thanks Niels


 
Reply With Quote
 
 
 
 
Tom
Guest
Posts: n/a
 
      06-08-2007, 11:58 PM
NDS wrote:
> Hi all. I'm having a strange problem here with some debugging. Got an ide
> that the problem is perhaps relatet to some sort of bank-switching. My
> qustion is :
>
> I'm in program bank ?.
> Make a call to a routine in bank1.
> In here i recieve an INT whitch takes me to some code in programbank 0. In
> the INT i save PCLATH, then make several call's. When done, i restore
> PCLATH, then retfie.
> Now i'm back with the routine in bank 1, but after return it seemes like
> sometimes i'm not returning to the bank from where the original call was
> made (this could be any one).
>
> The datasheet states that you need to set PCLATH only on the way OUT - not
> on return? Is that also true after servicing a INT in a nother bank,
> containing call's of it's own ?
> If not - is it "wrong" to have "common routines" like switch-reading which
> need to be called from different banks - out of bank 0? Or is there some
> other way round this?
>
> If there's a "simple" problem here, i would really like to know - before
> spending even more time debugging .
>
> Thanks Niels
>
>

How are you making the call to the routine in bank 1? The PIC midrange
reference manual has the following:

call k where k is between 0 and 2047

It doesn't appear that you can call a routine in another bank unless you
manually twiddle with the bank select bits and save pclath yourself.
 
Reply With Quote
 
 
 
 
Michael Lange
Guest
Posts: n/a
 
      06-09-2007, 03:25 PM
Hi Niels,

some common mistakes and errors are:

1. PCLATH != PCH
2. PCLATH will _only_ copyed to PCH on GOTO, CALL or a write operation
to PCL. So unnecessary writing to PCLATH can make confusion on other
3. Remember to the stack depth of the used PIC, i.e. nesting of your
code. Bear in mind that the interrupt also need 1 stack level.
4. Call statement to code that not ends with a return statement.
5. Jump to a subroutine.
6. Jump to an adress outside the current subroutine.


HTH
Michael
 
Reply With Quote
 
NDS
Guest
Posts: n/a
 
      06-10-2007, 10:12 PM

"Tom" wrote:
> It doesn't appear that you can call a routine in another bank unless you
> manually twiddle with the bank select bits and save pclath yourself.


Sorry, i explained myself too bad.
I shift the bank with a macro before call :

pbank1 macro
banksel PCLATH
bcf PCLATH, 4
bsf PCLATH, 3
endm

Like this:

pbank1
call routine
.......
.......
return
(set correct bank in STATUS right after the call is returned)

If no INT happens in the middle of routine ( i tried killing it) i return OK
no matter from where the call was made..
If INT, i _sometimes_ returns OK.
AND - it seemes like when it goes wrong it takes me someplace new every
time.

And - Michael - i'm not (as i see it) pushing the stack more than 8 adresses
even with INT.

Niels


 
Reply With Quote
 
NDS
Guest
Posts: n/a
 
      06-11-2007, 08:59 AM
Just found the bug. Just a few thousand lines above where i was looking for
it.

cblock 0x20
...
...
; cblock 0x70
status_temp
pclath_temp
w_temp
...

cblock 0xA0
...

Guess what line was accidently commented out.
This way, succesfull saving of PCLATH depended on the selected databank
before INT.

Niels


 
Reply With Quote
 
Tom
Guest
Posts: n/a
 
      06-11-2007, 05:11 PM
Glad to hear you figgered it out. The banking in PICs can be a real
P.I.T.A.



NDS wrote:
> Just found the bug. Just a few thousand lines above where i was looking for
> it.
>
> cblock 0x20
> ...
> ...
> ; cblock 0x70
> status_temp
> pclath_temp
> w_temp
> ...
>
> cblock 0xA0
> ...
>
> Guess what line was accidently commented out.
> This way, succesfull saving of PCLATH depended on the selected databank
> before INT.
>
> Niels
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Usury: A Short History of Banking vaughn Home Power and Microgeneration 0 10-05-2009 05:36 PM
Re: Usury: A Short History of Banking Steve Stone Home Power and Microgeneration 0 10-05-2009 01:16 PM
Banking Process surya.delhi@yahoo.com Electronic Basics 0 01-26-2008 07:10 PM
16F877 PIC problem Pubudu Electronic Design 8 06-27-2006 11:37 PM
code banking on 8051 spotato Hobby Electronics 1 07-14-2003 07:53 AM