Instant Int and encoder (Elect. Gearing)


Closed Thread
Results 1 to 14 of 14

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Pay no attention to the man behind the curtain. (or was that a mask)

    With DT_INTS, nothing is "blocking" except the interrupt handlers themselves.

    And if the conditions that generated the interrupt are not cleared, the handler will continue "blocking" everything.

    In your MotorDrive routine (RBC_INT handler), you MUST read PORTB to end the mismatch condition.

    Additionally, the statements to read the encoder should be in that handler too.

    Here's a snippet from SteveB for 2 rotary encoders, may give you some ideas.
    http://www.picbasic.co.uk/forum/showthread.php?p=25396

    hth,
    DT

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Pay no attention to the man behind the curtain. (or was that a mask)
    With DT_INTS, nothing is "blocking" except the interrupt handlers themselves.
    DOH!!! no kidding...

  3. #3
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Thanks for the replys Darrell and Skimask.
    I so hate asking for help for something thats likely to be an oversight on my part. I don't ever want to abuse the list's willingness to help.

    I'm going through your suggestions and the first thing that I don't understand in http://www.picbasic.co.uk/forum/showthread.php?p=25396 is this:
    ================
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler INT_INT, _Rot_Encoder, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    @ INT_ENABLE RBC_INT ;RB Port Change Interrupt
    ==============

    My understanding was that the INT_INT was for RB0 (external Int) only and that RBC_INT was for the "change on RB 4-7".
    I'm going to test and try to answer my own question, but I thought it should be answered in print. I know I have spun in small circles after looking for stuff like this.

    Bo

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


    Did you find this post helpful? Yes | No

    Default

    My understanding was that the INT_INT was for RB0 (external Int) only and that RBC_INT was for the "change on RB 4-7".
    Correct!

    Steve had found that bug later in the thread. I forgot to mention it.

    It should be RBC_INT.
    <br>
    DT

  5. #5
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Progress, but not right yet...

    Hi All,
    Been banging my head for a while now and I am getting closer. Thank you for the time you have taken to add life to this forum.

    The Travel encoder section works pretty well, but the Manual encoder is erratic and sometimes take over the travel section and not let it work. A bump on Manual, and the Travel works again.

    As a reminder. The Travel generates Pulse and Direction in one direction only. The Manual is for bi-directional fine adjustment after the Travel section's movement is complete (automatic). Target: 12F675 @ 4mHz INT_OSC

    Anybody see what I'm missing?
    Thanks
    Bo
    Code:
    A_trav  VAR GPIO.0          'Travel encoder A  input
    B_trav  VAR GPIO.1          'Travel encoder B  input
    A_man   var GPIO.2          'Manual Encoder A input
    B_man   var GPIO.3          'Manual Encoder B input
    P_out   var GPIO.4          'Pulse output to motor
    D_out   var GPIO.5          'level output for direction                               
    Dir         VAR bit            'Direction
    Scratch     var byte            'dummy byte
    Old_Bits    VAR BYTE
    New_Bits    VAR BYTE
    TravEncOld  var byte            'TRAVel Measurement ENCoder
    TravEncNew  Var byte            '
    ManEncOld   var byte            'MANual input ENCoder
    ManEncNew   var byte            '
                 
    P_out = 1                   'servo I/P = LO pulse, start HI 
     
    INTCON = %10001000          'GLOBAL ON, GPIO Int ON
    CMCON =  7                   'Comparator off, Digital I/O
    OPTION_REG = %00000000      'GPIO Pull-up Enabled
    TRISIO = %001111 
    WPU = %000111               'pull-ups 0-2 (3 added on board) 
    IOC = %001111               'Int On Change GPIO 1-3
    ANSEL = 0
    
    INCLUDE "DT_INTS-14-0.bas"     '..-14-0 = ALL Banks REM'd 
    
    ASM
    INT_LIST  macro    ; IntSource,    label,  Type, ResetFlag?
            INT_Handler    RBC_INT,  _EncChg,   ASM,  yes
        endm
        INT_CREATE                   ; Creates the interrupt processor
        INT_ENABLE   RBC_INT         ;RB Port Change Interrupt
    ENDASM                                           
    
    Old_Bits = GPIO & (%001111)                 'Get initial inputs
    
    Main:
             
    GOTO Main
    
    '---[RBC - interrupt handler]---------------------------------------------------
    EncChg:
        New_Bits = GPIO & (%001111)                'Get inputs
        TravEncNew = New_Bits & (%000011)          'strip New Travel encoder
        TravEncOld = Old_Bits & (%000011)          'Strip Old Travel Encoder
        if TravEncNew = TravEncOld then ManEnc   ' If no chg -> Manual Encoder
        Dir = TravEncNew.1 ^ TravEncOld.0            'Check direction
        D_out = Dir                                  'Direction LEVEL out
        if Dir = 1 then                              'Only travel 1 direction
        pulsout P_out,20                             'drive servo controller 
        Endif                                'Controller is STEP/DIRECTION I/P
        goto DoneRotEnc                      'skip Manual Encoder
             
    ManEnc:            
        ManEncNew = New_Bits & (%001100)           'strip Manual Encoder
        ManEncOld = Old_Bits & (%001100)
        Dir = ManEncNew.3 ^ ManEncOld.2           'Direction of Manual input
        D_out = Dir
        pulsout P_out,20                        'Pulse for either direction
    
    DoneRotEnc:
         Old_Bits = New_Bits                    'reset reference 
         Scratch = GPIO                         'read GPIO to clear mis-match
    @ INT_RETURN
    Last edited by boroko; - 21st March 2008 at 07:14. Reason: Add Processor Info

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


    Did you find this post helpful? Yes | No

    Default

    The interrupt type should be PBP.
    Code:
    ASM
    INT_LIST  macro    ; IntSource,    label,  Type, ResetFlag?
            INT_Handler    RBC_INT,  _EncChg,   PBP,  yes
        endm
    And you'll need to INCLUDE "ReEnterPBP.bas", for it to work.
    DT

  7. #7
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Thanks,
    I need to point out that this in on a 12F675.

    I commented out the bank lines in DT_INTS-14 (hence the "DT_INTS-14-0.bas" on the include)
    and removed ReEnterPBP

    I tried to use things in the way that was discussed in http://www.picbasic.co.uk/forum/show...9510#post49510

    Does that help this make sense a bit more?

    Thanks
    Bo

Similar Threads

  1. Using PICBASIC PRO in MPLAB IDE
    By jblackann in forum General
    Replies: 8
    Last Post: - 4th May 2008, 09:20

Members who have read this thread : 0

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