• AVR Freaks

Helpful ReplyHot!Trouble with MOVFFL on PIC18F26K42

Author
jpn
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2018/08/16 16:24:43
  • Location: 0
  • Status: offline
2018/08/17 18:57:54 (permalink)
0

Trouble with MOVFFL on PIC18F26K42

Hello everyone, 
I'm hoping someone can point out what I am doing wrong here.
I have been trying to use the MOVFFL instruction to move from a variable to POSTINC0 but have had no luck.
Here is what I am doing.
#include p18f26k42.inc

; CONFIG1L
  CONFIG FEXTOSC = OFF ; External Oscillator Selection (Oscillator not enabled)
  CONFIG RSTOSC = HFINTOSC_64MHZ; Reset Oscillator Selection (HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1)

; CONFIG1H
  CONFIG CLKOUTEN = OFF ; Clock out Enable bit (CLKOUT function is disabled)
  CONFIG PR1WAY = OFF ; PRLOCKED One-Way Set Enable bit (PRLOCK bit can be set and cleared repeatedly)
  CONFIG CSWEN = ON ; Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
  CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)

; CONFIG2L
  CONFIG MCLRE = EXTMCLR ; MCLR Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR )
  CONFIG PWRTS = PWRT_64 ; Power-up timer selection bits (PWRT set at 64ms)
  CONFIG MVECEN = OFF ; Multi-vector enable bit (Interrupt contoller does not use vector table to prioritze interrupts)
  CONFIG IVT1WAY = OFF ; IVTLOCK bit One-way set enable bit (IVTLOCK bit can be cleared and set repeatedly)
  CONFIG LPBOREN = OFF ; Low Power BOR Enable bit (ULPBOR disabled)
  CONFIG BOREN = OFF ; Brown-out Reset Enable bits (Brown-out Reset disabled)

; CONFIG2H
  CONFIG BORV = VBOR_2P45 ; Brown-out Reset Voltage Selection bits (Brown-out Reset Voltage (VBOR) set to 2.45V)
  CONFIG ZCD = OFF ; ZCD Disable bit (ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
  CONFIG PPS1WAY = OFF ; PPSLOCK bit One-Way Set Enable bit (PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence))
  CONFIG STVREN = ON ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
  CONFIG DEBUG = OFF ; Debugger Enable bit (Background debugger disabled)
  CONFIG XINST = OFF ; Extended Instruction Set Enable bit (Extended Instruction Set and Indexed Addressing Mode disabled)

; CONFIG3L
  CONFIG WDTCPS = WDTCPS_31 ; WDT Period selection bits (Divider ratio 1:65536; software control of WDTPS)
  CONFIG WDTE = OFF ; WDT operating mode (WDT Disabled; SWDTEN is ignored)

; CONFIG3H
  CONFIG WDTCWS = WDTCWS_7 ; WDT Window Select bits (window always open (100%); software control; keyed access not required)
  CONFIG WDTCCS = SC ; WDT input clock selector (Software Control)

; CONFIG4L
  CONFIG BBSIZE = BBSIZE_512 ; Boot Block Size selection bits (Boot Block size is 512 words)
  CONFIG BBEN = OFF ; Boot Block enable bit (Boot block disabled)
  CONFIG SAFEN = OFF ; Storage Area Flash enable bit (SAF disabled)
  CONFIG WRTAPP = OFF ; Application Block write protection bit (Application Block not write protected)

; CONFIG4H
  CONFIG WRTB = OFF ; Configuration Register Write Protection bit (Configuration registers (300000-30000Bh) not write-protected)
  CONFIG WRTC = OFF ; Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
  CONFIG WRTD = OFF ; Data EEPROM Write Protection bit (Data EEPROM not write-protected)
  CONFIG WRTSAF = OFF ; SAF Write protection bit (SAF not Write Protected)
  CONFIG LVP = ON ; Low Voltage Programming Enable bit (Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored)

; CONFIG5L
  CONFIG CP = OFF ; PFM and Data EEPROM Code Protection bit (PFM and Data EEPROM code protection disabled)

; CONFIG5H

MY_VARS udata_acs
tester res 1
    
REST udata
buffer res h'80'
  
RES_VECT CODE 0x0000
    GOTO START


MAIN_PROG CODE

START
    movlw h'DE'
    movwf tester, A
    
    lfsr 0, buffer
    movffl 0, POSTINC0 ; WORKS
    movffl tester, POSTINC0 ; DOESNT WORK
    movffl STKPTR, POSTINC0
 
 
    GOTO $

    END

 
 
The attached image shows the program memory, which seems to show something going wrong with the instruction using the variable by name (tester). 
But it seems to work just using the location of the variable (0x00). 
If anyone could shed some light I would be very grateful. 
EDIT: I am using MPASMWIN v5.77, and the default linker. 
Thank you. 
post edited by jpn - 2018/08/17 18:59:41

Attached Image(s)

#1
1and0
Access is Denied
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2018/08/18 02:17:50 (permalink)
+1 (1)
It looks like you have found a bug with the MOVFFL instruction. I suggest you to open a support ticket with Microchip.
 
#2
RISC
Super Member
  • Total Posts : 5376
  • Reward points : 0
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2018/08/18 03:14:33 (permalink)
+1 (1)
Hi,
I reported the issue with MOVFFL on MPASMX v5.77 back on MPLAB X v4.15
You should update MPLAB X to v5.05 as it has the latest MPASM X version v5.81 and check if the issue has been resolved.
Regards
#3
1and0
Access is Denied
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2018/08/18 03:27:15 (permalink)
+1 (1)
From MPLABX v5.05 Release Note:
 
  • Problems resolved between v5.79 and v5.80
 
(MPASM-461/462)
For projects targeting PIC18 K42 devices that have multiple modules that are separately linked with MPLINK and make use of the MOVFFL and/or MOVSFL instructions with operands that reference non-absolute symbols, the instruction encoding may not have been emitted correctly.
#4
1and0
Access is Denied
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2018/08/18 03:41:47 (permalink)
+2 (2)
I just updated to MPLABX v5.05 using MPASM v5.81 and it fixes this bug. :)
 
#5
jpn
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2018/08/16 16:24:43
  • Location: 0
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2018/08/18 03:45:56 (permalink)
0
Thank you guys all very much for the help. 
#6
_pike
Senior Member
  • Total Posts : 131
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/21 15:24:35 (permalink)
0
Hello everyone !!!
Aafter a lot of searching and experimenting i ended up here but my problem might be irrelevant....
Do you see anything strange on that code?
 

 
ISRHV     CODE    0x0008
     GOTO    HIGH_ISR
ISRLV     CODE    0x0018
     GOTO    LOW_ISR

ISRH      CODE                     ; let linker place high ISR routine
HIGH_ISR
 
BANKSEL PIR3
BTFSS PIR3,U1RXIF ; IF SET UART1 Receive Interrupt has occurred
RETFIE FAST
    
BANKSEL U1RXB
MOVFFL U1RXB,POSTINC0
 
RETFIE FAST  ; RESTORE CONTENT FROM SHADOW REGISTERS
 
 

 
It stores each incoming character but it seems that it doesnt increase the FSR.... it overwrites it again and again
 
 
Thank you!
 
 
 
<edit> The FSR0 is set at the beginning with the SFR's initialazation which means that it is set once and i re-set it to the beginning (so to read it) when i press a button. <edit>
 
 
 
post edited by _pike - 2019/08/21 15:33:17
#7
ric
Super Member
  • Total Posts : 23581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/21 15:30:21 (permalink) ☄ Helpfulby _pike 2019/08/21 15:35:13
0
Interrupt  routines must NEVER leave registers in a different state.
You are assuming your ISR can change the FSR register.
[1] That is a very BAD idea
[2] It won't work anyway because you are exiting with "RETFIE FAST" which restores all the core registers to how they were on entry, including FSR.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#8
_pike
Senior Member
  • Total Posts : 131
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/21 15:37:00 (permalink)
0
ric
Interrupt  routines must NEVER leave registers in a different state.
You are assuming your ISR can change the FSR register.
[1] That is a very BAD idea
[2] It won't work anyway because you are exiting with "RETFIE FAST" which restores all the core registers to how they were on entry, including FSR.

Thats why i keep reading the last input.... 
OK lets say that you wait a pack of data on the uart how would you handle this ?
 
 
<edit>Without FAST works fine...<edit>
 
 
post edited by _pike - 2019/08/21 15:42:11
#9
ric
Super Member
  • Total Posts : 23581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/21 15:40:45 (permalink) ☄ Helpfulby _pike 2019/08/22 08:07:18
0
Save a pointer to where it should go in a RAM variable, don't just let it float in FSR.
 
i.e. load FSR from that variable on ISR entry, and save it back to the variable before you exit.
You should also be checking to make sure it hasn't incremented past the end of your buffer.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#10
1and0
Access is Denied
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/21 15:52:10 (permalink) ☄ Helpfulby _pike 2019/08/22 08:07:21
0
If FSR0 is _not_ used concurrently in the ISR and the main code, then another option is to update the FSR0x_SHAD registers before RETFIE.
 
<edit> Also, there is no need to BANKSEL when using MOVFFL.
post edited by 1and0 - 2019/08/21 15:53:58
#11
1and0
Access is Denied
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/21 16:23:00 (permalink)
0
Another option is to use an offset variable to load WREG and use PLUSW0 instead of POSTINC0.
#12
_pike
Senior Member
  • Total Posts : 131
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/22 08:08:11 (permalink)
0
1and0
Another option is to use an offset variable to load WREG and use PLUSW0 instead of POSTINC0.


 Can you give me an example ? Smile: Smile
 
<edit>I read in a different topic that WREG is addressable.. perhaps it has to do of what you say above?
Btwq i found also this... https://www.microchip.com/forums/m883382.aspx <edit>
post edited by _pike - 2019/08/22 10:14:15
#13
1and0
Access is Denied
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/22 12:33:57 (permalink) ☄ Helpfulby _pike 2019/08/22 12:49:35
0
_pike
1and0
Another option is to use an offset variable to load WREG and use PLUSW0 instead of POSTINC0.

Can you give me an example ?

Like this:

        lfsr    FSR0,buffer     ; not needed if main() does not affect FSR0
        banksel index           ; not needed if in access RAM
       
        movf    index,w         ; get index
        movffl  U1RXB,PLUSW0    ; store into buffer[index]
        incf    index           ; increment index

 
#14
Jerry Messina
Super Member
  • Total Posts : 417
  • Reward points : 0
  • Joined: 2003/11/07 12:35:12
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/23 03:26:56 (permalink)
0
I've used PLUSWx before... it can be a handy instruction.
 
Just keep in mind that it treats the W register as a signed value (range of -127 to 128)
#15
1and0
Access is Denied
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/23 06:13:38 (permalink)
0
Jerry Messina
Just keep in mind that it treats the W register as a signed value (range of -127 to 128)

Yes, offset the pointer FSRx and you get an array with negative subscript. ;)  That is, it can access an array/buffer up to 256 bytes.
 
<edit> A signed value has range of -128 to +127. I think the datasheet is wrong. ;)
 
post edited by 1and0 - 2019/08/23 06:23:44
#16
Jerry Messina
Super Member
  • Total Posts : 417
  • Reward points : 0
  • Joined: 2003/11/07 12:35:12
  • Status: offline
Re: Trouble with MOVFFL on PIC18F26K42 2019/08/23 11:38:00 (permalink)
0
-128 to +127
Well now, that makes quite a bit more sense, doesn't it! Lord knows why I referred to the datasheet...
#17
Jump to:
© 2019 APG vNext Commercial Version 4.5