PIC18F46K42 ASSEMBLER INTERRUPTS ARRANGEMENT
PIC18F46K42 ASSEMBLER INTERRUPTS ARRANGEMENT
I am actually setting up an application on MPASMX v5.83 based on the PIC18F46K42 microcontroller.
I will be using a large number of routines I programmed years ago on assembler. That way I am initially programming on MPASMXv.5.85 to check a concept.
Application use 2 push button switches and, Rotary encoder with push button and 2 sine wave input signals to be ZCD for a Phase Detector. . Action on those elements should start IRS.
Although I believe I am following the PIC18F46K42 Vectored Interrupts data sheet requirements, I have not been able to run properly even a simple IOC routine.
The INTERRUPTS .ARRANGEMENT.ASM source file is actually testing simple Vectored Interrupts IOC (RD4 & RD5),INT0(RB0),INT1(RA4)&INT2(RA5).CONFIG MVECEN = ON is setup (CONFIG2L) so the Vector table is used to determine the interrupt priorities.
That way:
; INT0,RB0,p8 for Rotary Encoder Push Button(RE)
; INT1,RA4,p23. & INT2,RA5,p24 for Push Button Switches
; IOCC6: RC6, RE.B,p44 & IOCC7: RC7, RE.A,p1
; NOTES:
; 1) PERIPHERAL PIN SELECT (PPS) MODULE was contemplated for INT0, INT1 & INT2 setting
; 2) CMP1 & CMP2 interrupts are not properly set up at this moment.
; They will be used after analyzing Vectored Interrupt behavior for simple IOC and INT0, INT1 analysis.
The INT0, INT1 & INT2 based on Interrupt on falling edge of PPS selected pins for INTi reinitialize the code when applied.
Changing status on pins targeting IOCC6 & IOCC7 did nothing. It clearly loos like that I am not handling and setting up properly the INTERRUPT VECTOR TABLE (IVT).
I set up the IVTBASE registers default to 00 0008h, with the high priority interrupt vector address on 00 0008h and the low priority interrupt vector address will be 00 0018h.
----------------;-----------------------------------------------------------------------------
; INTERRUPTS: 00 0008h location is used as the reset default for the IVTBASE
; register, the vector table can be relocated in thememory by programming the IVTBASE register.
;The IVTBASE register is user programmable and is
; used to determine the start address of the Interrupt
; Vector Table and the IVTLOCK register is used to prevent any unintended writes to the IVTBASE register.
;;******************************************************************************
;-----------------------------------------------------------------------------
; (IVTBASE = 0X08)
;Interrupt Vector Address ; Vector Number, Interrupt Source
ORG 0x0008; 0 - Software Interrupt
ORG 0x000A; 1 - HLVD
ORG 0x000C; 2 - OSF
ORG 0x000E; 3 - CSW
ORG 0x0010; 4 - NVM
ORG 0x0012; 5 - SCAN
ORG 0x0014; 6 - CRC
CODE 0x0016; 7 - IOC
BRA ISR_IOC ; RE PINS A OR B PRESSED
ORG 0x0018; 8 - INT0
BRA ISR_INT0 ; PROCESS ISR INT0,ROTARY ENCODER PB, RB0
ORG 0x001A; 9 - ZCD 51
ORG 0x001C; 10 - AD
ORG 0x001E; 11 ADT
ORG 0x0020; 12 - C1
bra ISR_CMP1 ; VF ZCD
ORG 0x0022; 13 - SMT1
ORG 0x0024; 14 - SMT1PRA
ORG 0x0026; 15 - SMT1PWA
ORG 0x0028; 16 - DMA1SCNT
ORG 0x002A; 17 - DMA1DCNT
ORG 0x002C; 18 - DMA1OR
ORG 0x002E; 19 - DMA1A
ORG 0x0030; 20 - SPI1RX
ORG 0x0032; 21 - SPI1TX
ORG 0x0034; 22 - SPI1 64
ORG 0x0036; 23 - I2C1RX
ORG 0x0038; 24 - I2C1TX
ORG 0x003A; 25 - I2C1
ORG 0x003C; 26 - I2C1E
ORG 0x003E; 27 - U1RX
ORG 0x0040; 28 - U1TX
ORG 0x0042; 29 - U1E
ORG 0x0044; 30 - U1
ORG 0x0046; 31 - TMR0
ORG 0x0048; 32 - TMR1
ORG 0x004A; 33 - TMR1G
ORG 0x004C; 34 - TMR2
ORG 0x004E; 35 - CCP1
ORG 0x0050; 36 - ?
ORG 0x0052; 37 NCO
ORG 0x0054; 38 CWG1
ORG 0x0056; 39 CLC1
ORG 0x0058; 40 INT1
BRA ISR_INT1 ; PROCESS ISR INT2, PUSH BUTTON SWITCH SW.PB1
ORG 0x005A; 41 C2
BRA ISR_CMP2 ; Vz ZCD
ORG 0x005C; 42 DMA2SCNT
ORG 0x005E; 43 DMA2DCNT
ORG 0x0060; 44 DMA2OR
ORG 0x0062; 45 DMA2A
......................................
;-------------------------------------------------------------
Any hint?
Following NorthGuy considering Predetermined addresses evenly divisible by 4 and DS40001919E-page 133 , EXAMPLE 9-3: SETTING UP VECTORED INTERRUPTS USING MPASM, IVT worked as expected:
i.e
;-----------------------------------------------------------------------------
; (IVTBASE = 0X08)
;Interrupt Vector Address ; Vector Number, Interrupt Source
ORG 0x0008; 0 - Software Interrupt
ORG 0x000A; 1 - HLVD
ORG 0x000C; 2 - OSF
ORG 0x000E; 3 - CSW
ORG 0x0010; 4 - NVM
ORG 0x0012; 5 - SCAN
ORG 0x0014; 6 - CRC
ORG 0x0016; 7 - IOC
DW ISR_IOC>>2 ; RE PINS A OR B PRESSED
ORG 0x0018; 8 - INT0
DW ISR_INT0>>2 ; PROCESS ISR INT0, ROTARY ENCODER PB, RC7
ORG 0x001A; 9 - ZCD 51
ORG 0x001C; 10 - AD
ORG 0x001E; 11 ADT
ORG 0x0020; 12 - C1
DW ISR_CMP1>>2 ; VF ZCD
ORG 0x0022; 13 - SMT1
post edited by Joaquinete33 - 2019/07/30 19:03:32