Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Hi. I am trying to make this Rotary Encoder work with DT-INTS on a 16F1827 device.

    It gets once in the interrupt routine and never seem to exit.

    Here is the code so far driving me crazy.

    Code:
    ASM
      __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_ON & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
      __config _CONFIG2, _WRT_OFF & _PLLEN_ON & _LVP_OFF & _STVREN_OFF & _BORV_25
    ENDASM
    
    DEFINE OSC 32
    
    OSCCON= %11110000   'PLL enabled, Internal RC-8MHz
     
    ' Set LCD Data port
    DEFINE LCD_DREG PORTA
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 0
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTA
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 4
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTB
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 3
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 1500
    ' Set data delay time in us
    DEFINE LCD_DATAUS 44
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    'Initializing Registers
      PORTB = 0:PORTA = 0
      TRISB = $33
      TRISA = 0
      
      ADCON0 = 0
      ADCON1 = 0
      ANSELA = 0
      ANSELB = 0
    
      INTCON = $88 ' Binary 10001000
      
      IOCBP=$30
      IOCBN=$30
      
      OPTION_REG = 0
      
      WPUB=$33
      
    eeprom 0,[2,0,3,1,1,3,0,2]
    led       var portb.4   
    Flag      var bit
    wsave     VAR BYTE    $70     SYSTEM  ' alternate save location for W 
    Q_New     var Byte
    Q_Old     var byte
    M_Count   var byte [4]
    P_Count   var byte [4]
    Q_Count   var word
    temp      var byte
    
    clear
         
    For Q_Old = 0 to 3
    Read Q_Old,M_Count[Q_Old]
    Read Q_Old + 4,P_Count[Q_Old]
    Next Q_Old
         
      Q_Count = 0   
        Q_New = 0
        Q_Old = 0
         Flag = 0  
          
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type,  Resetflag?                
            INT_Handler    IOC_INT,      _Encoder,  pbp,     yes       
        endm
        INT_CREATE                   ; Creates the interrupt processor
    ENDASM
    @ INT_ENABLE IOC_INT            ; enable external (INT) interrupts
    
    '---------------------------- Initialize LCD ----------------------------
    
    Lcdout $fe, 1                               ' Clear LCD screen
    Lcdout "System Ready"                       ' Display message
    Pause 500                                   ' Wait .5 second
    Q_Count=50
    
    Goto Main_Loop
    
    Encoder:                                    ' ISR 
        Q_New = PortB.5 + PortB.5 + PortB.4         ' get port status 
        
        If M_Count[Q_Old] = Q_New then              ' if M_Count code satisfied then minus
                  temp=temp+1
                  if temp=4 then
                    temp=0
                    Q_Count = Q_Count - 1
                    Flag = 1                       ' set flag to true to update display
                  endif
        goto Q_Skip
        endif
        
        If P_Count[Q_Old] = Q_New then              ' if M_Count code satisfied then plus
                  temp=temp+1
                  if temp=4 then
                    temp=0
                    Q_Count = Q_Count + 1
                    Flag = 1
                  endif                       ' set flag to true to update display
        endif
        
    Q_Skip:
        Q_Old = Q_New
        toggle portb.6                               ' update Q_Old Byte
    @ INT_RETURN
    
    
    Main_Loop:   
    if Flag = 1 then
        Lcdout $fe, 1                              ' Clear LCD screen
        Lcdout dec Q_Count                         ' Display encoder position (counts)
        Flag = 0                                   ' reset flag to false, display updated
    endif
    
    pause 100
    
    goto Main_Loop
    
    
    Thanks,
    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Ioannis,

    On those chips, the IOCIF bit is read-only and only gets cleared when ALL of the IOCBF flags are clear.
    So you can set the INT_Handler's ResetFlag option to NO.

    Then be sure the IOCBF flags are cleared before exiting the ISR.
    Also, take a look at section 13.4 in the datasheet regarding clearing the flags.
    DT

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Excellent! Works terrific now.

    These chips are a little pain in setting them.

    Thanks Darrel.

    Ioannis

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Use the code in post#27, (new approch to rotary encoder) is more efficient and you can achieve even higher frequency.

    Cheers

    Al.
    Last edited by aratti; - 14th January 2012 at 16:45.
    All progress began with an idea

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Hi Al. I am using the #27 ISR.

    The thing that I added was the check for the 4 counts before Q_Count variable is incremented or decremented.

    Thats because the encoder I use produces 4 pulses on every step I turn the knob. Thanks Henrik for noting this.

    Ioannis

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    The code was written to read quadrature count. Any rotary encoder with two channels will generate quadrature count.

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Yes that is correct. So the Q_count variable is incrementing by 4.

    Ioannis

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 : 5

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