Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Is that possible to use the Instant Interrupts to create/read, let´s say, 4 different buttons on PORTC ?
    Yes, that's possible. But it would be a lot easier if you used RBC_INT "Port B change interrupts". It uses PORTB.4 thru PORTB.7

    But if those pins aren't available, you could do something like this, which uses only 1 interrupt (INT_INT on Falling Edge), then the interrupt handler can read PORTC to figure out which one was pressed.


    <br>
    DT

  2. #2
    Join Date
    Nov 2003
    Location
    Sao Paulo - Brazil
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel

    Thank you very Much !

    I think this could help me a Lot !

    I´m already using some portb pins and this solution will help a lot !

    Thank you again !

    Sérgio

  3. #3
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default Instant Interrupts and Internal Comparators

    Hi Darrel,

    I have been using your wonderful instant interrupts routine, i have experienced a hiccup and cannot work out what I am doing wrong.

    I wonder anybody may be able to help direct me to a solution.

    I am using a 18F4520 with 2.5 and masm401. I have checked that I have your latest version which I beleive to be 3.2 (dated 28/8/07).

    when I compile the following code:

    define OSC 16
    INCLUDE "DT_INTS-18.bas"
    INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler CMP1_INT, _HopOut, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    TRISA = %00111111'
    TRISD = %00000000
    Z var bit
    x var byte
    CMCON = %00000010
    @ INT_ENABLE CMP1_INT
    Start:
    PORTD.4 = 0
    z = 0
    Waiting:
    if z = 0 then waiting

    for x = 1 to 20
    pause 50
    toggle PORTD.4
    next x
    goto start

    HopOut:
    z = 1
    @ INT_RETURN

    end


    I recieve the following complie errors



    Error[128]........: Missing argument(s)
    Error[113]........: Symbol not previously defined(IntFlagReg)
    Error[113]........: Symbol not previously defined(IntFlagBit)
    Error[113]........: Symbol not previously defined(IntFlagReg)
    Error[113]........: Symbol not previously defined(IntFlagBit)
    Error[101]........: ERRORInterrupt Source(IntFlagReg,IntFlagBit)not found)
    Error[128]........: Missing argument(s)
    Error[101]........: ERRORINT_ENABLE -Interupt Source not Found!)


    If I change the CMP1 to CMP2 I receive errors

    If I change the CMP1 to CMP then it compiles okay.

    Any thoughts... should I be looking to set the registers manually maybe? I was planning to use both comparators independantly.

    Thanks

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post

    Hi,

    No surprise if you read the interrupt sources list

    #define INT_INT INTCON,INT0IF ;-- INT External Interrupt, 16F compatible
    #define INT0_INT INTCON,INT0IF ;-- INT0 External Interrupt
    #define INT1_INT INTCON3,INT1IF ;-- INT1 External Interrupt
    #define INT2_INT INTCON3,INT2IF ;-- INT2 External Interrupt
    #define INT3_INT INTCON3,INT3IF ;-- INT3 External Interrupt
    #define RBC_INT INTCON,RBIF ;-- RB Port Change Interrupt
    #define TMR0_INT INTCON,TMR0IF ;-- TMR0 Overflow Interrupt 18F
    #define TMR1_INT PIR1,TMR1IF ;-- TMR1 Overflow Interrupt
    #define TMR2_INT PIR1,TMR2IF ;-- TMR2 to PR2 Match Interrupt
    #define TMR3_INT PIR2,TMR3IF ;-- TMR3 Overflow Interrupt
    #define TMR4_INT PIR3,TMR4IF ;-- TMR4 Overflow Interrupt
    #define TX_INT PIR1,TXIF ;-- USART Transmit Interrupt
    #define TX1_INT PIR1,TX1IF ;-- USART1 Transmit Interrupt
    #define TX2_INT PIR3,TX2IF ;-- USART2 Transmit Interrupt
    #define RX_INT PIR1,RCIF ;-- USART Receive Interrupt
    #define RX1_INT PIR1,RC1IF ;-- USART1 Receive Interrupt
    #define RX2_INT PIR3,RC2IF ;-- USART2 Receive Interrupt
    #define CMP_INT PIR2,CMIF ;-- Comparator Interrupt
    #define EE_INT PIR2,EEIF ;-- EEPROM/FLASH Write Operation Interrupt
    #define BUS_INT PIR2,BCLIF ;-- Bus Collision Interrupt
    #define LVD_INT PIR2,LVDIF ;-- Low Voltage Detect Interrupt
    #define HLVD_INT PIR2,HLVDIF ;-- High/Low Voltage Detect Interrupt
    #define PSP_INT PIR1, PSPIF ;-- Parallel Slave Port Read/Write Interrupt
    #define AD_INT PIR1, ADIF ;-- A/D Converter Interrupt
    #define SSP_INT PIR1, SSPIF ;-- Master Synchronous Serial Port Interrupt
    #define CCP1_INT PIR1, CCP1IF ;-- CCP1 Interrupt
    #define CCP2_INT PIR2, CCP2IF ;-- CCP2 Interrupt
    #define CCP3_INT PIR3, CCP3IF ;-- CCP3 Interrupt
    #define CCP4_INT PIR3, CCP4IF ;-- CCP4 Interrupt
    #define CCP5_INT PIR3, CCP5IF ;-- CCP5 Interrupt
    #define USB_INT PIR2, USBIF ;-- USB Interrupt
    #define OSC_INT PIR2, OSCFIF ;-- Oscillator Fail Interrupt



    ... only this :

    #define CMP_INT PIR2,CMIF ;-- Comparator Interrupt

    I think you have Yourself to look from which comparator the interrupt comes ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi Alain

    Thankyou Alain for taking the trouble to read my post and make a suggestion, may I draw your attention to the defines further down Darrel's wonderful coding.

    ;_____ Comparators __________________________________________________ ________
    #define CMP0_INT PIR1, CMP0IF ;-- Comparator 0 - 1230/1330 only

    CMPIFREG = PIR2 ;-- Comparator 1
    CMPIEREG = PIE2
    CMPIPREG = IPR2
    ifdef C1IF ; 18F24K20 18F25K20 18F26K20
    CM1IFBIT = C1IF ; 18F44K20 18F45K20 18F46K20
    endif
    ifdef CM1IF
    CM1IFBIT = CM1IF ; several J PICs
    endif
    ifdef CMP1IF
    CMPIFREG = PIR1 ; 1230/1330 only
    CM1IFBIT = CMP1IF
    CMPIEREG = PIE1
    CMPIPREG = IPR1
    endif

    ifdef CM1IFBIT
    #define CMP1_INT CMPIFREG, CM1IFBIT
    endif

    ifdef C2IF ;-- Comparator 2
    CM2IFBIT = C2IF ; 18F24K20 18F25K20 18F26K20
    endif ; 18F44K20 18F45K20 18F46K20
    ifdef CM2IF
    CM2IFBIT = CM2IF ; several J PICs
    endif
    ifdef CMP2IF
    CM2IFBIT = CMP2IF ; 1230/1330 only
    endif

    ifdef CM2IFBIT
    #define CMP2_INT CMPIFREG, CM2IFBIT
    endif
    '-----------------------------------------------------------------------------

    I think we are all waiting for the "K" series, perhaps this will compile to the K. I shall try it.

    I did wonder wether I should set the ADCON for this device particularily the LATA register. But I am also aware that <6> of the PIR2 PIE2 and IPR2 only refers to one CMI, I presume I shall have to be careful to make sure that any interrupt on either comparator does not interfere with the other. ie if one comparator is set then the other is disabled.

    Thanks again for your help.

    Duncan

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


    Did you find this post helpful? Yes | No

    Default

    The difference is that on the 4520, there is only 1 interrupt source for the Comparator module. A change in either comparator will cause an interrupt to the same handler.

    There are other chips that have individual interrupt flags for each comparator, but not the 4520.

    So you need to use the CMP_INT, on that chip.
    <br>
    DT

  7. #7
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Thanks for reply, I had slowly worked my way towrds that.

    for th 18F45K20 Migration
    The comparator is no longer controlled by the
    CMCON register and each comparator now has it’s
    own control register, CM1CON and CM2CON. The
    functionality of the bits has also changed.

    there is a section that confirms the observations made about the registers, so it really does always boil down to RTFD, but reading is sometimes not enough if you suffer from word blindness, anyway it gave me the opportunity to say thankyou for your routines which I intend to use.

    Duncan.

    Furthermore if everybody read and fully "understood" the datasheets this forum would die.

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 22:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 21:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 21:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 07:32
  5. Replies: 1
    Last Post: - 1st November 2006, 04:11

Members who have read this thread : 4

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