PIC18F26K22 problem reading PCLATU register  - Page 1
Forum section: electronics / general

author: rollingstone
author_rank: Contributor
timestamp: July 16, 2016, 04:47:03 pm
content: Hi, My first post here. Because of this problem I tried several times (and several weeks) to register to Microchip forum but unsuccessfully so I'll try to ask here.I'm using PIC18F26K22 MCU and PICKIT3 debuger, coding in asembly. And trying to read program counter upper byte (PCLATU) register value. It works fine in simulator, but not with real hardware. I use instructions:MOVF PCLATU, 0 orMOVFF PCLATU, WREG orMOVFF PCLATU, FF (move value from PCLATU to any other file)And that does not work with real hardware (target registers are not updated with PCLATU value). I have no problem reading other PC registers (PCL, PCLATH). But with PCLATU I can only write the value to it. What I'm doing wrong? Datasheet does not say anything about not being able to read from it. Also I googled few days and looked many forums, butno luck.Thanx for any help.

author: JPortici
author_rank: Super Contributor
timestamp: July 16, 2016, 05:31:18 pm
content: AH! Registering on the microchip forum (and brosing it sometimes)Disable adblock/noscript and the such. the posting form didn't work with "https always" for exampleTry with different browsers (Internet explorer should work with no issues)Or register using your Google+ credentials (the only useful thing so far)what are you trying to accomplish exactly?

author: JTR
author_rank: Regular Contributor
timestamp: July 16, 2016, 05:48:21 pm
content: The PIC18F26K22 is a 64Kb device. It doesn't use PCLATU...

author: rollingstone
author_rank: Contributor
timestamp: July 16, 2016, 06:05:42 pm
content: With microchip forum i just don't receive registration confirmation, tried "resend activation confirmation" option dozen times, no luck. May be I should try new email and user address.With that MCU I'm trying to store messages in program memory using "DA" directive and then send them using table pointers to program memory (TBLPTL, TBPTRH, TBPTRU) to USART.So when my program runs to the point where i want to transmitt my message to USART,I do it by first assigning PC register values to table pointer values:MOVFF PCL, TBLPTRLMOVFF PCLATH, TBLPTRHMOVFF PCLATU, TBLPTRUAnd then after that i use DA directive to write my message to program flash memory (right where PC is pointing at):da "\x02\r\n" ; x02 symbol indicates start of messageda "Change device name error ocured!\r\n" ; actual messageda "And don't worry\r\n" ; actual messageda "And be happy\r\n" ; actual messageda "\x03" ; x03 symbol indicates end of messageAnd then i call subprogram to transmit message from that place (where PC was pointing at) from begining (002h symbol) to the end (003h symbol) of message:CALL USART_MSG_TXAnd everything works fine, except THAT problem. Instead of doing it normal way (MOVFF PCLATU, TBLPTRU) i can write to TBLPTRU register value manualy. But then I will have to worry because it's value will depend on where in the program memory space this subprogram sits.

author: rollingstone
author_rank: Contributor
timestamp: July 16, 2016, 06:13:38 pm
content: if The PIC18F26K22 is a 64Kb device and It doesn't use PCLATU…Then why PCLATU register is on datasheet and i can see it in register list when debuging and can write to it and it's value is updated?And of course i checked include file and it also has PCLATU register definition with address FFBh which is right according to datasheet.

author: picandmix
author_rank: Frequent Contributor
timestamp: July 16, 2016, 07:31:12 pm
content: Will have to look at the PCLATU in the datasheet, but in the meantime have you ? or why don't you run your program via the Pickit3 in Debugger mode and use breakpoints to just before those instructions , then single step through then while 'watching' those registers in Mplab .

author: picandmix
author_rank: Frequent Contributor
timestamp: July 16, 2016, 08:00:24 pm
content: A while since I played around with those registers but looking at some old working code I used the Table Pointers, section 6.2 of the datasheet with the DB directive,brief example below.Saves messing with the PC register which can be all to easy to screw up.Code:movlwhigh textl; load text1 H address to tbptrHmovwfTBLPTRHmovlwupper textl; load text1 U addressmovwfTBLPTRUmovlwlow textl; load text1 L address to tbptrLmovwfTBLPTRLtext1db"1234567890!£$%&*", 0

author: JTR
author_rank: Regular Contributor
timestamp: July 17, 2016, 04:20:04 am
content: Quote from: rollingstone on July 16, 2016, 06:13:38 pmBecause PCLATU is used on other family members with more memory. For any PIC18 with 64KB code space or less PCLATU is simply not required for user code. Even if it is there inside the silicon it will always be set to 0 on POR and every time the PCL SPR is read. Given a PIC18 with <=64KB The only time itmaybe used is with code that is located in a non user space like the debug executive. I cannot remember if the PIC18 uses a separate test area for the debug executive or not. The point is that for user code it is only used when you have > 64KB of code space.The PCLATU SPR is doecumented to exist in all PIC18 data sheets even when it has no functional role. It is there as a redundant "super set" feature and its usefulness is to be inferred by context.

author: rollingstone
author_rank: Contributor
timestamp: July 17, 2016, 02:38:00 pm
content: Thanx JPortici, JTR and picandmix for help, I just ignored PCLATU register and everything is working now. When debuging step by step it was very confusing to see a value 20h in this register, so I thought I have also to write that value to TBLPTRU register. It is strange that datasheet doesn't say anything about uselessness of this register. and I'm was not that genius to understand this "by default", so thank you for clearing this out. I Also used code provided by picandmix and it is much nicer way than moving values from PC register.

author: picandmix
author_rank: Frequent Contributor
timestamp: July 17, 2016, 07:28:52 pm
content: Quote from: rollingstone on July 16, 2016, 04:47:03 pmYou do not need to worry about not being able to get in to the Microchip forum as there are quiet a few folk from that forum here in EEvblog.I do not know all of them, but have spotted ian.m, who, if the same guy, is a very experienced and well thought after microchip forum member, who will surely be able to help out with assembly and more.

author: rollingstone
author_rank: Contributor
timestamp: July 18, 2016, 07:00:18 pm
content: Thanx picandmix, I really starting to like this placeNot that MICROCHIP rubish

author: picandmix
author_rank: Frequent Contributor
timestamp: July 19, 2016, 02:43:39 pm
content: A few beginner tips about the 18K series that you might find useful.The original 18F chips like the popular 4520/ 4550 contained all the systems registers in one fixed area of Ram bank 15 , known as the Access bank.This avoided the earlier 16F problems of frequently having to change banks for the system registers.However on the 18K series and newer chips with so many extra functions, they have had to extend that area for the system registers.Sadly, and for reasons I do not know, these extra register below 0xF60 have to be manually address by selecting bank 15.While most of these registers will only used during more advanced work, the Analogue Select registers are also in there so you will need to set them accordingly, as the Ports power on defaults are Analogue.Example -movlb 0xf ; set Bank Select Register to 15movlw 0x00 ; set Port to Digitalmovwf ANSELAmovwf ANSELBmovwf ANSELCmovwf ANSELDmovwf ANSELEmovlb 0x1 ; Set BSR to 1When looking at other code examples of 18F you will find its code is generally portable, but here are 2 examples of slight differences, to the 18K series;OSCON;movlw b'01010010' ; 45K22 CHANGED TO 0101 = 4MEG;movwf OSCCON ; set internal osc to 4 mhz; TIMER1 AS RTC; T1CON paramenter layout slightly different;movlw b'10001101' ; configure for ext clock and Turn ON Timer1;movwf T1CONFollowing on from your above point of addressing Program Memory; in Ram you can similarly address large areas by means of the File Select RegistersExample -ramclr movlb D'1' ; define bank1,clrf FSR1H ; FSR routine to clear ram banks 0 -4 onlyclrf FSR1Lclrram clrf POSTINC1 ; clear location and incmovlw 0x05 ; now in bank5subwf FSR1H,Wbnz clrram ; carry on clearing if not at bank5