• AVR Freaks

PIC18F458 debugging

Page: < 12 Showing page 2 of 2
Author
1and0
Access is Denied
  • Total Posts : 9978
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F458 debugging 2018/07/21 22:55:40 (permalink)
+2 (2)
verner
Thanks 1and0 for your sharp eyes, I have made the corrections you pointed out (except BRA, BNZ, which I will do later) but where else shall enable the GIEx bits? 

You must _not_ enable GIE bit inside the ISR. It is automatically enabled by the RETFIE instruction when exiting the ISR.
 

Where can I find how to use "CONFIG" i.s.o. "__CONFIG" respectively CBLOCK/ENDC as an asm-user?

In the MPASM User's Guide, and the config settings and values are listed in the device include .INC file.
 

And still the code just loops i.s.o. being interrupted.

You enable more (9) interrupts than you are handling (3) in your ISR; one such interrupt is Timer0.
    MOVLW b'11111000'
    MOVWF INTCON
    MOVLW b'10000000' ; PRIORITETER, FLANKER
    MOVWF INTCON2
    MOVLW b'00011000'
    MOVWF INTCON3 ;
    MOVLW b'00000011' ; INTERRUPT TILLÅTELSER
    MOVWF PIE1
    MOVLW b'00000000' ; INTERRUPT TILLÅTELSER
    MOVWF PIE2 
    MOVLW b'00000101' ; CAN BUS INTERRUPT TILLÅTELSER
    MOVWF PIE3

Also, enable global interrupt ONLY after EVERYTHING have been setup.
 
This does _not_ clear RBIF. Mismatch condition must be cleared _before_ RBIF can be cleared.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PANEL-INTERRUPT
PANELINT
    BTFSS INTCON,0 ; RBIF PANELSW 1
    GOTO PANELEND
    BCF INTCON,0
    BCF MAINT
    BTFSC HUVSW
    BSF MAINT
    BCF INTCON,0 ; RESET INTERRUPT FLAG
    MOVF PORTB ; DUMMY ATT TA BORT MISMATCH
PANELEND

 
#21
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 01:39:33 (permalink)
+1 (1)
verner
... but where else shall enable the GIEx bits?

Nowhere!
The RETFIE instruction does it for you. You WILL cause problems if you try to manually enable it before then.
 

  Where can I find how to use "CONFIG" i.s.o. "__CONFIG" respectively CBLOCK/ENDC as an asm-user?

C:\Program Files (x86)\Microchip\MPLABX\v4.10\mpasmx\docs\MPASM_MPLINK_User_Guide.pdf
 
Update the "v4.10" to match your MPLABX version.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#22
verner
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2017/12/12 15:09:59
  • Location: Sweden
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 03:17:24 (permalink)
+1 (1)
HEUREKA! Thanks for the reference docs for me to read more closely. I removed the no-no GIE, and made changes to the CONFIG:s and RB mismatch.
On my online computer, where I edit and debug files, I use MPLAB IDE 8.92 and there the interrupts is OK. When I tried to build my project with the "CONFIG" changes, the build was OK.
But my offline_machine where I burn my chip and measure etc, I use MPLAB IDE 7. When trying to build the code, I got errors in the CONFIG area and got suspicious. I installed the 8.92 on that machine and  the build is OK. 
AND the interrupts start working. As I assumed in my first post there is a simple solution but I could not see.
Thanks, you marvelous guys  who had lead me on the right track!!!!!
#23
dan1138
Super Member
  • Total Posts : 3284
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 12:51:01 (permalink)
+1 (1)
@verner,

There are bugs where your code returns from the Interrupt Service Routines.

It does not restore the correct value to the STATUS register.
And as qɥb has mentioned in post #22 you should not alter the state of the INTCON,GIE bit in an ISR.

This is the code you posted:
INTEND:
        MOVF    BSR_TEMP,W      ; Restore BSR
        MOVWF   BSR             ; Restore BSR
        MOVF    W_TEMP,W        ; Restore WREG
        MOVF    STATUS_TEMP,W   ; Restore STATUS
        MOVWF   BSR             ; Restore BSR
        MOVLW   b'11111000'     ;
        MOVWF   INTCON
        RETFIE


This is what I suggest would work better:
INTEND:
        MOVF    BSR_TEMP,W      ; Restore BSR
        MOVWF   BSR             ; Restore BSR
        MOVF    STATUS_TEMP,W   ; Restore STATUS
        MOVWF   STATUS          ; Restore STATUS
      SWAPF   W_TEMP,F        ; Restore WREG
      SWAPF   W_TEMP,W        ; Restore WREG
        RETFIE


You may want to read these documents for information on programming the PIC18 family of parts in assembly language:
PICmicro® 18C MCU Family Reference Manual
PICmicro® 18C MCU Family Reference Manual Errata Sheet
MPASM™ Assembler, MPLINK™ Object Linker, MPLIB™ Object Librarian User’s Guide

<EDIT> Oh crap, I trumped it and said should where I meant shouldn't ! :)

<EDIT2> Even dumber than a president! Thanks qɥb.
post edited by dan1138 - 2018/07/22 16:27:42
#24
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 13:16:16 (permalink)
+1 (1)
dan1138
...
And as qɥb has mentioned in post #22 you should alter the state of the INTCON,GIE bit in an ISR.
...

typo
"should" -> "should not" ! :)
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#25
verner
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2017/12/12 15:09:59
  • Location: Sweden
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 14:31:22 (permalink)
0
Thanks, some of these was pointed out earlier and is/will be corrected. Then there are logical fault to be corrected also but I got the interrupts working!!
#26
1and0
Access is Denied
  • Total Posts : 9978
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 16:11:57 (permalink)
+2 (2)
dan1138
There are bugs where your code returns from the Interrupt Service Routines.

It does not restore the correct value to the STATUS register.
And as qɥb has mentioned in post #22 you should not alter the state of the INTCON,GIE bit in an ISR.
...
This is what I suggest would work better:
INTEND:
        MOVF    BSR_TEMP,W      ; Restore BSR
        MOVWF   BSR             ; Restore BSR
        MOVF    W_TEMP,W        ; Restore WREG
        MOVF    STATUS_TEMP,W   ; Restore STATUS
        MOVWF   STATUS          ; Restore STATUS
;       MOVLW   b'11111000'     ;
;       MOVWF   INTCON
        RETFIE


I pointed these out in Post #18.  Your restore snippet still does _not_ restore WREG correctly.  Anyway, as I have also pointed out in Post #17 it's better to use the Fast Register Stack.
#27
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 16:17:25 (permalink)
0
Indeed, the comments in that block should be corrected to:
INTEND:
        MOVF    BSR_TEMP,W      ; Restore BSR
        MOVWF   BSR             ; Restore BSR
        MOVF    W_TEMP,W        ; Restore WREG
        MOVF    STATUS_TEMP,W   ; Restore STATUS, corrupt WREG
        MOVWF   STATUS          ; Restore STATUS
;       MOVLW   b'11111000'     ;
;       MOVWF   INTCON
        RETFIE

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#28
1and0
Access is Denied
  • Total Posts : 9978
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F458 debugging 2018/07/22 16:29:48 (permalink)
+2 (2)
If you insist on inefficient code, do this
        MOVWF   W_TEMP              ; Save WREG
        MOVFF   STATUS, STATUS_TEMP ; Save STATUS
        MOVFF   BSR, BSR_TEMP       ; Save BSR
 
        ; ISR code here
 
        MOVFF   BSR_TEMP, BSR       ; Restore BSR
        MOVF    W_TEMP, W           ; Restore WREG
        MOVFF   STATUS_TEMP, STATUS ; Restore STATUS
        RETFIE

but I would suggest this instead ;)
        retfie   FAST

#29
verner
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2017/12/12 15:09:59
  • Location: Sweden
  • Status: offline
Re: PIC18F458 debugging 2018/11/08 13:50:27 (permalink)
0
Thank you all for your tips. Since I don´t know where and how to start a new question, I do it here. Can I assume a 458, rather straight assembler code, to be working on a 4580 (without problems)?
#30
jack@kksound
code tags!
  • Total Posts : 3220
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: PIC18F458 debugging 2018/11/08 14:05:37 (permalink)
+2 (2)
You will likely need to change config settings and port settings when you change to the newer (relative) chip. There are also probably SFR changes, the 4580 likely has register and peripherals the 458 did not have. You will need to compare the datasheets to be sure. Basic instruction sets are the same.
#31
verner
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2017/12/12 15:09:59
  • Location: Sweden
  • Status: offline
Re: PIC18F458 debugging 2018/11/10 06:50:13 (permalink)
0
Thanks, I have made some changes to the configs and get it through the build OK.
But I can't get any response on PORTE<1.0> either as I/P nor O/P, not in real-life PC-board nor in MPLAB IDE 8.92. I tried with MCLRE as 0 and 1 with no change. My ADCON0 is 00h and ADCON1 is 07h. TRISE is set to 03h (which is desired). What do I miss?
Al other pin functions seems to work OK. I have not selected any instruction extension.
Simply I try to use the 4580 as a 458.
#32
qhb
Superb Member
  • Total Posts : 9999
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: PIC18F458 debugging 2018/11/10 16:17:12 (permalink)
0
What value have you written to PSPMODE?
That is TRISE.4
 

Nearly there...
#33
verner
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2017/12/12 15:09:59
  • Location: Sweden
  • Status: offline
Re: PIC18F458 debugging 2018/11/10 16:56:51 (permalink)
0
As mentioned, it is 03h. I appreciate your guys more experienced than I.
Quite outside the above, long time ago (late 60:s)I have written assembler in an General Precision GP4 computer for  Full Flight simulators. Fun!
#34
qhb
Superb Member
  • Total Posts : 9999
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: PIC18F458 debugging 2018/11/10 18:19:22 (permalink)
0
Can you show the actual code now?
I was looking back at post#12, where you wrote 0b11111011 to TRISE.
 

Nearly there...
#35
verner
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2017/12/12 15:09:59
  • Location: Sweden
  • Status: offline
Re: PIC18F458 debugging 2018/11/12 03:00:06 (permalink)
0
I found my mistake. It was ADCON1 that needed bit <3> set for 4580.
Thanks for your engagement.
#36
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5