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


    Did you find this post helpful? Yes | No

    Default

    HI all,
    I moved this to a 16F627 and made the code as straight as I could.

    The problem is much like it has been for a while: The direction signal is erratic and can be tricked by interaction with the other encoder.

    Any thoughts would be appreciated.
    Code:
    '****************************************************************
    '*  Notes   :  16F627@20mhz, HS_OSC                             *
    '*          : PBP 2.50c, MPASM: 5.11,                           
    ' 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 LOW.
    ' 3) Manual Encoder to drive servo either direction manually.
    '                        16F627
    '          ----------------u-----------------
    '        -1|RA2/AN2/Vref            RA1/AN1 |18-   direction LEVEL output        
    '        -2|RA3/AN3/CMP1            RA0/AN0 |17-   Step PULSE o/p, Active LOW      
    '        -3|RA4/TOCKI/CMP2   RA7/OSC1/CLKIN |16-        
    '        -4|RA5/MCLR/vpp    RA6/OSC2/CLKOUT |15-              
    '        -5|-- VSS                    VDD++ |14-            
    '        -6|RB0/INT           RB7/T1OSI/PGD |13-   Manual Encoder B input       
    '        -7|RB1/RX/DT  RB6/T1OSCO/T1CKI/PGC |12-   Manual Encoder A input       
    '        -8|RB2/TX/CK                   RB5 |11-   Travel encoder B  input      
    '        -9|RB3/CCP1                RB4/PGM |10-   Travel encoder A  input        
    '          ----------------------------------       
    
    DEFINE OSC 20	
    INCLUDE "AllDigital.pbp"
    clear
    P_out   var PORTA.0          ' Step PULSE output to motor, Active LOW
    D_out   var PORTA.1          ' LEVEL output for direction  
    syncM   var PORTA.2          ' output for testing timing 
    syncI   var PORTA.3                            
    Dir         VAR byte         ' Direction
    EncOld      var byte
    EncNew      var byte 
    OPTION_REG = %00000000       ' Pull-up Enabled
    TRISA = %00000000 
    TRISB = %11110000
    TravEnc  con %00110000
    ManEnc   con %11000000 
    P_out = 1                    ' start out HI. Moves on LOW pulse 
    goto Main      
    '********** Subs *************************** 
    ManDrive:
           Dir = EncNew.7 ^ EncOld.6    ' XOR new L bit > Old Rt bit=Direction
           D_out = Dir                  ' set direction pin
           pauseus 2                    ' minimum 3.5uS for Gecko drive
           P_out = 0                    ' send drive pulse either dir
           pauseus 2
           P_out = 1                    ' reset drive pulse 
    return     
    TravDrive:
           D_out = 1                     ' set direction pin
           Dir = EncNew.5 ^ EncOld.4    ' XOR new L bit > Old Rt bit=Direction
           If DIR = 0 then                  ' end if travel DOWN
            P_out = 0                    ' send drive pulse retract only
            pauseus 2
            P_out = 1                    ' reset drive pulse
           endif  
    return 
    '******* MAIN *********************************************** 
    Main:
          'TOGGLE syncM                  ' pulse to time Main loop
        EncNew = PORTB           ' get the new state of both encoders 
        if (EncNew & ManEnc) != (EncOld & ManEnc) then ' man not same? Drive Man  
          gosub ManDrive
          endif
        if (EncNew & travEnc) != (EncOld & TravEnc) then ' Trav not same? Drive Trav 
         GOSUB TravDrive
         endif     
        EncOld = EncNew          ' save the previous state of both encoders 
    goto main        
    end
    Thanks
    Mark

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


    Did you find this post helpful? Yes | No

    Default Gotta learn the hard way....

    Well, this one has been quite a ride.... I've spent weeks trying to figure this out. I was in the middle of trying to craft a more detailed question that might generate some interest. One encoder was working wonderfully the way I expected, and the other, with almost the exact same code was causing all kinds of problems. I was in the process of using my Logic pod (which I love BTW: www.Saleae.com) to see if I could describe the problem better. I had a heartbeat pulse in the main and noticed that it would cut out for almost 3 mS when RB.4 changed. After looking at the datasheet for the ump-teenth time, I realized that I hadn't disabled the Low Voltage Programming option. That was it. Bet I won't take this long to look at that again!
    Thanks for all of you who looked at it, and especially those that took the time to give some feedback.
    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