The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 18, 2024, 04:28:11 04:28


Login with username, password and session length


Pages: [1]
Print
Author Topic: Assembler interrupts in Proton+  (Read 5092 times)
0 Members and 1 Guest are viewing this topic.
FranzW
Active Member
***
Offline Offline

Posts: 182

Thank You
-Given: 589
-Receive: 81



« on: January 31, 2012, 10:51:08 22:51 »

Hello,
I need to count fast incoming encoder pulses by means of interrupts on PORTB.7. Does somebody know what must I do in order to place my interrupt routine at ORG 4, the interrupt vector address? If I use ORG 04 in the program below, Proton issues the error message: “Overwriting previous address contents (0004)”
Part of the program can be seen below.

Device = 16F877A
Declare Xtal = 4
All_Digital = true
Dim Pulses As Word 'To store RB7 interrupts
TRISB = %11111001

' OTHER VARIABLES, TRIS, etc. WILL BE DECLARED HERE.

'Making place to save the required registers during the interrupt.
'Since I didn’t find anything about this in the Proton manual,
'I created room to save the registers, as stated in the PBP V 2.46 manual.
Asm
     W0 equ 0x0020 'bank 0 place For W
     S0 equ 0x0021 'bank 0 place for STATUS
     P0 equ 0x0022 'bank 0 place for PCLATH
     W1 equ 0x00A0 'bank 1 place for W
     W2 equ 0x0120 'bank 2 place For W
     W3 equ 0x01A0 'bank 3 place For W       
EndAsm   
         

GoTo Program 'Jump over the interrupt routine
'***********************************************
'*************Interrupt routine

Asm
   'Save registers
   Movwf W0
   Swapf STATUS, w
   Clrf STATUS
   Movwf S0
   Movf PCLATH, w
   Movwf P0
   
   'The interrupt code will be placed here.
   
   
   'Restore registers
   Movf P0, w
   Movwf PCLATH
   Swapf S0, w
   Movwf STATUS
   Swapf W0, f
   Swapf W0, w
   Retfie
EndAsm
'*****************************************
Program:
'Program code is placed here.

Logged
pickit2
Moderator
Hero Member
*****
Offline Offline

Posts: 4647

Thank You
-Given: 826
-Receive: 4207


There is no evidence that I muted SoNsIvRi


« Reply #1 on: January 31, 2012, 10:55:16 22:55 »

see if this helps you.  see post #14
http://www.protonbasic.co.uk/showthread.php/61133-TMR0-question/page2?highlight=interupts+16F877A
Logged

Note: I stoped Muteing bad members OK I now put thier account in sleep mode
FranzW
Active Member
***
Offline Offline

Posts: 182

Thank You
-Given: 589
-Receive: 81



« Reply #2 on: January 31, 2012, 11:37:27 23:37 »

Dear pickit2,

Thanks for your help.
On_Interrupt is used in post #14. The manual says that when On_interrupt is used, the incoming interruption just sets a flag, and the interruption routine will be executed after the current basic instruction has ended (and not immediately).
The PIC is also driving five multiplexed seven-segment displays. Each display is on for 3 ms, so if I used On_Interrupt, I would have to break the delayms 3 into hundreds of delayus in a for-next loop.
That is why I wanted to use an assembler interrupt routine. But there seems to be no way of telling Proton that the assembler routine should be placed at Org 4.
I will try using the for-next loop, and see what happens.

Regards,
FranzW
« Last Edit: February 01, 2012, 09:50:03 09:50 by FranzW » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #3 on: February 01, 2012, 09:54:53 09:54 »

Hi FranzW;

There is a method to what you want:
(the register's save-restore is also automatic, see the help file)

    Declare FSR_CONTEXT_SAVE = OFF ' If it is not used in the IT routine

    On_Hardware_Interrupt GoTo IT_Routine

    Goto Start

IT_Routine:
  .... may be also asm
    Context Restore ' restore regs and return from interrupt 

Start:
Logged
Parmin
Hero Member
*****
Offline Offline

Posts: 582

Thank You
-Given: 494
-Receive: 133


Very Wise (and grouchy) Old Man


« Reply #4 on: February 01, 2012, 09:56:26 21:56 »

I believe you do not have to tell Proton to place the interrupt handler on Org 4.
Simply point it to a label and Proton will sort the interrupt addressing out.
Logged

If I have said something that offends you, please let me know, so I can say it again later.
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC