Assembly Interrupts for PIC 18F27K42


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2020
    Posts
    9

    Default Assembly Interrupts for PIC 18F27K42

    The attached file demonstrates implementing non-vectored interrupts in assembly for a PIC 18F27K42. For this exercise, Timer1 and Timer3 are configured to run concurrently and each generates an interrupt on rollover. The interrupt service routine (ISR) demonstrates how to: disable additional interrupts during processing the current interrupt; determine which timer generated the interrupt; increment a rollover counter; reset the interrupt flag; re-enable interrupts; and return to the main program. All Timer and interrupt configuration is handled in the main code. The Main code includes a forever loop that toggles indicator LEDs when each timer counter equals a predefined trigger value. I do not code in Assembler, so there are likely better ways to do this. It works for my application, which is measuring time values for a tach measuring RPM from <100 to >11K. References for my approach include Section 6.3 of the PBP3 compiler reference manual; Section 41 Instruction Set Summary of the PIC18F27K42 datasheet; and various internet sources, including discussions on this forum.
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: Assembly Interrupts for PIC 18F27K42

    disable additional interrupts during processing the current interrupt
    You should never manipulate the GIE bit inside the ISR. That is handled automatically when you get the intr, and then RETFIE restores it on exit.
    Remove those two instructions.

  3. #3
    Join Date
    Mar 2020
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Assembly Interrupts for PIC 18F27K42

    Thanks for the comment, it should assist others in learning how to implement an ISR in Assembly. Consistent with that objective, I was able to find a Microchip reference (Section 8.1 of Microchip's PICmicro MID-RANGE MCU FAMILY) that states that the “return from interrupt” instruction, RETFIE, exits the interrupt routine as well as sets the GIEbit, which allows any pending interrupt to execute. The same document goes on to state, "When an interrupt is responded to, the GIE bit is cleared to disable any further interrupt, the return address is pushed into the stack and the PC is loaded with 0004h." While it is not explicitly stated, it seems reasonable to assume that this is being done in hardware. The demo code was edited as suggested.
    Attached Files Attached Files
    Last edited by dtbarber; - 19th May 2020 at 18:58. Reason: Added edited code

  4. #4
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    127


    Did you find this post helpful? Yes | No

    Default Re: Assembly Interrupts for PIC 18F27K42

    Thanks for this. I'm trying to implement a completely different interrupt on an 18F26K83 and this is the closest thing I've seen so far as a starting point.

    Troy

Similar Threads

  1. Replies: 2
    Last Post: - 8th February 2009, 06:10
  2. assembly in Pic
    By lerameur in forum Off Topic
    Replies: 11
    Last Post: - 1st May 2008, 21:06
  3. decoding PIC assembly -- need help
    By uchiprox in forum General
    Replies: 1
    Last Post: - 12th February 2007, 05:19
  4. Simultaneous equation using PIC assembly
    By mankan in forum General
    Replies: 2
    Last Post: - 11th September 2006, 20:16
  5. PIC to PIC communication and interrupts
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 22nd June 2004, 06:59

Members who have read this thread : 2

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts