Instant Int and encoder (Elect. Gearing)


Closed Thread
Results 1 to 14 of 14

Hybrid View

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

    Default Instant Int and encoder (Elect. Gearing)

    Hi all,

    I have been working on this for too long and I'm starting to chase my tail.

    I'm to the point that I can remember the post numbers, but I'm still overlooking something.

    The purpose is this:
    1) Read Encoder #1 to measure direction and distance of a linear movement.
    2) If travel is +, do nothing
    3) if travel is -, feed pulses to a servo driver to move a motor (feed material at same rate as linear retract).
    4) there a couple of lines I left in for adding manual over-ride.
    5) testing on a 877 with a X-1 board but the target can be anything.

    Thanks for taking a look.
    Bo

    ' 1)Quadrature encoder reading direction and speed of mechanical slide.
    ' 2) Motor (servo) driven in ONE direction of slide movement,
    ' not driven for other direction. Pulse & Direction drive.
    ' 3) Overide switches to drive servo either direction manually.
    '
    A_INPUT VAR PORTB.4 'encoder A input
    B_INPUT VAR PORTB.5 'encoder B input
    F_Sw var PORTB.6 'Foward switch input
    R_sw var PORTB.7 'Reverse Sw input
    P_out var PORTA.0 'Pulse out to motor
    D_out var PORTA.1 'level out for direction
    'only for manual Sw
    ' drive. Implement Ltr.
    LED1 var PORTA.5 'heartbeat for INT
    RdEnc1 VAR BIT
    RdEnc2 VAR BIT
    COUNTER VAR WORD

    TRISA = %00000000
    TRISB = %11111111
    TRISD = %00000000
    OPTION_REG.7 = 0 'enable POTRB pull-ups

    INCLUDE "DT_INTS-14.bas" 'Base Inturrupt program
    include "ReEnterPBP.pbp" 'allow PBP int

    ASM
    INT_LIST macro ;IntSource, Label, Type, ResetFlag?
    INT_Handler RBC_INT, _MotorDrive, PBP, yes
    INT_Handler INT_INT, _ToggleLED1, PBP, yes
    endm

    INT_ENABLE RBC_INT ;enable RB change int
    INT_ENABLE INT_INT ; enable external (INT) interrupts
    ENDASM

    Start
    RdEnc2 = A_INPUT & ~ RdEnc1 'EVERY POSITIVE GOWING EDGE OF A_INPUT
    RdEnc1 = A_INPUT 'GIVES A PULSE OF ONE PROGRAM CYCLE

    IF RdEnc2 = 1 AND B_INPUT = 1 Then 'Encoder TURNS CW: UP
    COUNTER = 1
    EndIF

    IF RdEnc2 = 1 AND B_INPUT = 0 Then 'Encoder TURNS CCW: DN
    COUNTER = 0
    EndIF

    counter = portb & %00000011 'for troubleshooting: strip i/p.
    PORTD = counter 'for troubleshooting: to see i/p.

    goto start

    '+++++++++++++++++
    'Motor Drive Pulse Out inturrupt handler
    '++++++++++++++++++
    MotorDrive:
    if counter = 1 then
    pulsout P_out,100
    endif
    @ INT_RETURN
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
    TOGGLE LED1
    @ INT_RETURN
    end

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by boroko View Post
    pulsout P_out,100
    pulsout is a 'blocking' statement, a 'synchronous' statement.
    In other words, if you're trying to do something at the same time as you're trying to 'pulsout', that something might not get done until the pulsout is done doing what it has to do.

  3. #3
    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

  4. #4
    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...

  5. #5
    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

  6. #6
    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

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