PMDC SERVO MOTOR WITH quadrature encoder DRIVE ?


Results 1 to 38 of 38

Threaded View

  1. #18
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Unhappy

    OK now next step are steped.
    I write calculation to increment in CW my variable defined as LONG to be incremented from position buffer
    which go from 0-12500 and again and again..
    Code:
    ' Pic 18F4431 @ 20MHz true XTAL
        define osc 20
        DEFINE HSER_RCSTA 90h            
        DEFINE HSER_TXSTA 24h            
        DEFINE HSER_SPBRG 64              
        DEFINE HSER_CLROERR 1             
        ADCON0=0                          
        ANSEL0=0                          
    
        PortA = 0
        PortB = 0
        PortC = 0
    
        TRISA = %011100                 
        TRISB = %00000000
        TRISC = %10000000                 
    
        QEICON=%10011000
        DFLTCON = %00111000              
        MAXCNTL = %11010100             
        MAXCNTH = %00110000                
        PosLow VAR BYTE                    
        PosHigh VAR BYTE                   
        PosTemp VAR BYTE                   
        Position VAR WORD                     
        y var LONG
        x var BYTE
        x = 0 
        y = 0
        POSCNTL = 0                     
        POSCNTH = 0                       
        PIR3.2 = 0  
        CLEAR
            
        Start:
        Gosub GetPosition
        y =  (x * 12500) + position 
        HSEROUT [dec y]
        Pause 10                      
        Goto Start                       
    
    
    GetPosition:
        PosHigh = POSCNTH                     
        PosLow = POSCNTL                       
        PosTemp = POSCNTL                         
        If PosLow - PosTemp = 0 then Goto Done  
        PosHigh = POSCNTH                     
        PosLow = POSCNTL  
    Done: 
        Position = POSHIGH * 256 + PosLow    
        if PIR3.2 = 1 then x = x+ 1
        PIR3.2 = 0
        RETURN 
        END
    Now I can count a long trip of mechanic of machine which is present in LONG variable in CW direction.
    But I have new problem in my head all these days and it is next.
    I have BIT which indicate direction of motor and it is in QEICON.5.
    If QEICON.5 is 0 then we go CCW and if it is 1 then we go CW direction.
    Now if we go CW and stop motor it wil be 1 all the time to next move
    and if we go CCW it will be 0 and after we stop from CCW it will be 0 all time to next move..
    Confuse how to make matematic to implement new formula for decrement LONG variable in CCW :
    y = y - (12500-position) or similar becous in CCW position go from 12500-0 and again 12500-0....
    If any idea or someone want to help THANKS.
    Regards Robert
    Last edited by phoenix_1; - 10th September 2009 at 20:21.

Similar Threads

  1. Quadrature encoder and ASM Interrupts. questions..
    By godfodder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th March 2013, 14:45
  2. Best quadrature encoder for buck?
    By jrprogrammer in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd June 2009, 13:58
  3. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 08:40
  4. saving RCREG to word
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2008, 13:51
  5. encoder wowes
    By wallaby in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 6th December 2005, 21:56

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