Actually, now that I look into this carefully, the same doc tells me that calls and retfie's will save/retrieve at least all 11 bits on a 2048-byte device, so for the 16F872, I won't actually need to save/restore PCLATH in the ISR. Yes, that was all one sentence. Cheers, -Neil. -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Pic Dude Sent: Wednesday, June 12, 2002 12:34 AM To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]: Odd problem... Bob, Bingo! Ran this thru the simulator and came up with this too -- the addwf PCL,F instruction kept jumping back to the Init section of my code (near the beginning). Page 6-2 in DS31006A (Mid-Range MCU Family doc) told me "..... 2K-word devices (or less) do not require paging". Liars! :-) Unless I'm interpreting that too generally. A little more delving found me figure 6-2 which showed that instructions modifying PCL are 8-bit and I need to set PCLATH etc. So since I did not want to have to be on the lookout for this as I continually grow the code, I thought I'd move the table read subroutine to a far off spot in upper mem. I tried this in the sim... org 0x0700 ; Start in really high memory ;----------------------------------------------------- ; Convert 4-digit data to 7-segment data ;----------------------------------------------------- Convert7Seg: movwf SAVE_ADDR ; Save offset movlw 0x07 movwf PCLATH movf SAVE_ADDR,W ; Retrieve offset addwf PCL,F ; Jump to appropriate offset retlw B'01111110' ; '0' retlw B'00110000' ; '1' . . . nop ; Error - '15' retlw B'00000001' ; Return dash It worked! BUT it didn't work on the actual chip. On the actual chip, I moved the subroutine to the beginning of code (before even the initialization stuff), and it works. That's still an unexplained mystery, but based on this 256-byte block issue, your #2 below makes sense now. I'll go add the PCLATH protection code in the ISR. Much thanks, -Neil. -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Bob Ammerman Sent: Tuesday, June 11, 2002 11:08 PM To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]: Odd problem... Ok, I am pretty sure I know what is going on here.... Until your latest addition, the routine below was probably in the first 256 instructions of memory (ie: the high byte of the PC is zero). You probably have zero in PCLATH.... Thus, your addwf PCL,F will take you to locations 0x009 thru 0x119 instead of where you want to go. To fix this: 1: make sure PCLATH contains the high bits of the address of the Convert7Seg routine before executing the addwf pcl.,f 2: make sure you properly save and restore PCLATH in the interrupt handler. Note: GOTOs and CALLs only care about 2048 instruction boundaries, but ADDWF PCL.,F cares about 256 instruction boundaries. Bob Ammerman RAm Systems before the call to Convert7Seg ----- Original Message ----- From: "Pic Dude" To: Sent: Tuesday, June 11, 2002 10:17 PM Subject: Re: [PIC]: Odd problem... > Y'know I did that, and there's only one 'table' that modifies > PCL. Here is that snippet from the .lst file... > > 00630 ;------------------------------------------- > 00631 ; Convert 4-dig data (in W) to 7-seg data > 00632 ;------------------------------------------- > 00633 > 0109 00634 Convert7Seg: > 0109 0782 00635 addwf PCL,F ; Jump to appr. offset > 010A 347E 00636 retlw B'01111110' ; '0' > 010B 3430 00637 retlw B'00110000' ; '1' > 010C 346D 00638 retlw B'01101101' ; '2' > 010D 3479 00639 retlw B'01111001' ; '3' > 010E 3433 00640 retlw B'00110011' ; '4' > 010F 345B 00641 retlw B'01011011' ; '5' > 0110 345F 00642 retlw B'01011111' ; '6' > 0111 3470 00643 retlw B'01110000' ; '7' > 0112 347F 00644 retlw B'01111111' ; '8' > 0113 3473 00645 retlw B'01110011' ; '9' > 0114 0000 00646 nop ; Error - '10' > 0115 0000 00647 nop ; Error - '11' > 0116 0000 00648 nop ; Error - '12' > 0117 0000 00649 nop ; Error - '13' > 0118 0000 00650 nop ; Error - '14' > 0119 0000 00651 nop ; Error - '15' > 011A 3401 00652 retlw B'00000001' ; Dash = error > 00653 > > Does not cross a 256-byte boundary. > > Also went looking for FSR/INDF, but can't seem understand > how that would cause a problem by being shifted in program > memory -- it still accesses low data memory. > > Thanks, > -Neil. > > > > > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Dwayne Reid > Sent: Tuesday, June 11, 2002 9:02 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Odd problem... > > > At 08:11 PM 6/11/02 -0500, Pic Dude wrote: > > >So I commented out the new code (subroutine) and it works again, BUT > >if I comment out the code that calls the new subroutine (but leave the > >subroutine in place), it still does NOT work. I've narrowed it down to the > >existence of the code that causes a problem. I've even changed the new > >subroutine to 26 nop's (instead of the 26 instructions that were there) > with > >absolutely no calls to it, and it still fails. > > I *really* would take a look at any and all jump tables. You have > described a classic page boundary problem (the nop's tell me that). Do a > search for PCL in your source and see if you have missed a computed goto or > jump somewhere. > > dwayne > > -- > Dwayne Reid > Trinity Electronics Systems Ltd Edmonton, AB, CANADA > (780) 489-3199 voice (780) 487-6397 fax > > Celebrating 18 years of Engineering Innovation (1984 - 2002) > .-. .-. .-. .-. .-. .-. .-. .-. .-. .- > `-' `-' `-' `-' `-' `-' `-' `-' `-' > Do NOT send unsolicited commercial email to this email address. > This message neither grants consent to receive unsolicited > commercial email nor is intended to solicit commercial email. > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics