instant interrupts with comparator


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    24

    Default instant interrupts with comparator

    I have been trying to get instant interrupts working, using the comparator interrupt with a 16f88. In the data sheet it says:
    "You may be getting stuck in an infinite loop with the comparator interrupt service routine if you
    did not follow the proper sequence to clear the CMIF flag bit. First you must read the CMCON
    register, and then you can clear the CMIF flag bit.

    I used the following code ( after alot of trial and error) and it seems to work
    Code:
        
    @__CONFIG    _CONFIG1, _INTRC_IO & _LVP_OFF & _BODEN_OFF
    DEFINE OSC 8
    LED1   VAR  PORTB.1
    VAR1   VAR  BYTE
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
             INT_Handler   CMP_INT,  _ToggleLED1,   PBP,  no    
    endm
       INT_CREATE               ; Creates the interrupt processor 
       INT_ENABLE  CMP_INT     ; enable Comparator interrupts   
    
    ENDASM
    
    OSCCON = %01111000
    ANSEL = %00000111
    CMCON = %00000010
    CVRCON = %11001000
    
    TRISA = %00000011
    TRISB = 0
    
    PORTA = 0
    PORTB = 0 
    Main:
      PAUSE 1
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
    VAR1 = CMCON
    PIR2.6 = 0
         TOGGLE LED1
    @ INT_RETURN
    It works if I put no in the ResetFlags column and in the interrupt handler read CMCON, then clear PIR2.6, which is the flag.

    I would like to know if this is the correct way to do this or if there is a better way.
    Thanks, Mike

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Sure, that will work.

    You could also set the ResetFlag to YES, and just read CMCON in the handler.

    Typically, the handler would read CMCON anyway by testing the state of either the C1OUT or C2OUT bits so it can respond to the current state of the comparators.

    Right now you're just toggling an LED, so you have to read CMCON separately to end the mismatch condition.

    Once you actually do something in the comparator handler, you probably won't need the VAR1 = CMCON statement anymore.
    <br>
    DT

  3. #3
    Join Date
    Jun 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply Darrel and thanks for giving us Instant Interrupt. It lets a hack like me get alot more out of a PIC than just blinking an led.

    I am using the comparator to read the output of a hall effect sensor on a flow sensor and it works a treat.

    Thanks,
    Mike

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Excellent, another happy customer ...
    Don't forget to tip the waitresses.

    If you can find one ... have you seen one lately?
    My beer's empty
    DT

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. 18F2420, instant interrupts, and TMR0
    By dhickman in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th March 2009, 18:33
  3. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  4. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  5. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48

Members who have read this thread : 1

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

Posting Permissions

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