PMDC SERVO MOTOR WITH quadrature encoder DRIVE ?


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here are some threads talking about how to work with the encoder.
    http://www.picbasic.co.uk/forum/show...rotary+encoder
    http://www.picbasic.co.uk/forum/showthread.php?t=1552
    http://www.picbasic.co.uk/forum/showthread.php?t=9700

    As far as stopping goes...
    Does the motor have a built in brake for holding? It can be stopped by shorting the leads but how fast it stops that way depens on the speed it is running when the leads are shorted.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Unhappy

    I was probe to stop motor and all work good.
    But now I have another problem:
    All examples from forum for read quadrature encoder with A and B outputs
    at 5V are confused for my head, I was probe PBP examples but is to slow
    and I think that for read quadrature encoder is needed ASM or some INT rutine becouse when motor work on ~ 3000 rpm rutine must be ultra speed
    and background proces....
    My head is like baloon ...

  3. #3
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Default

    All other info about my probe is now in PicBasicPro FORUM in:
    Probe to read quadrature encoder with DT_INT need help
    After my success I will post all here on FORUM.
    If any help and good idea pls write.
    Many thanks to all good peoples here!
    Best regards Robert

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    I recommend you take a look at the 18F2431 series PIC. It has a motion feedback module built in that can be set up to keep track of an incremental encoder. It also has a lot of other goodies specifically targeted at motor control applications.

    /Henrik.

  5. #5
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    I recommend you take a look at the 18F2431 series PIC. It has a motion feedback module built in that can be set up to keep track of an incremental encoder. It also has a lot of other goodies specifically targeted at motor control applications.

    /Henrik.
    I was buy today 18F4431 and will move to it.
    At moment I looking for examples for it.
    Thanks and regards Robert

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    This is cut and pasted from a larger program I have and this digested version is not tested so take it for what it is please. It's written for the 18F2431 so double check the pin assignments for the QEI module.

    Code:
    DEFINE HSER_RCSTA 90h                       'USART receive status init.
    DEFINE HSER_TXSTA 24h                       'USART transmit status init.
    DEFINE HSER_BAUD 57600                      'Baudrate is 57600.
    
    ANSEL0 = 0                                  'All inputs as digital
    
    PortA = 0
    PortB = 0
    PortC = 0
    
    TRISA = %11000                           'QEI pins as inputs.
    TRISB = %00000000
    TRISC = %10000000                       'USART RX pin as input.
    
    QEICON = %00010100                      'Setup QEI, 4X mode, reset on index. 
    
    PosLow VAR BYTE                          'Storage for the low byte of encoder count
    PosHigh VAR BYTE                         'Storage for the high byte of encoder count
    PosTemp VAR BYTE                        'Temporary storage for low byte of encder count
    Position VAR WORD                        'Actual encoder position, 16bit word.
    
    CLEAR
    
    Main:
      Gosub GetPosition
      HSEROUT ["QEI Count: " , #Position, 10]
      Pause 100
    Goto Main
    
    GetPosition:
    'Since the position counter isn't double buffered we can get to situations
    'where the lowbyte overflows between readings of the high and the low byte. This
    'is prevented by reading the low byte two times and compare the two readings.
    'If they are the same then we're fine, if not re-read the registers.
      
        PosHigh = POSCNTH                       'Get high byte of counter
        PosLow = POSCNTL                        'Get low byte of counter
        PosTemp = POSCNTL                       'Get low byte again
        
        If PosLow - PosTemp = 0 then Goto Done      'Compare, if equal we're done.
        
        PosHigh = POSCNTH                           'If not, get values again.
        PosLow = POSCNTL
    
    Done:
        Position = POSHIGH * 256 + PosLow           'Put high and lowbyte together.
    RETURN
    END
    Again, no guarantees but I hope it serves as a starting point for you.

    /Henrik.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,

    I started playing with the 4431 DIP version and wonder if you have ran into this with the one you are using. Maybe it is a 4331 problem, maybe whole series.

    When using a 4Mhz resonator and have the config set for HSPLL and DEFINE OSC 16 all works well.

    If I replace the 4Mhz with a 10 Mhz and try DEFINE OSC 40 everything goes erratic.
    The PIC runs but even a simple "blinky" will blink randomly.

    Here is the very simple code and configs I was playing with to set the OSC.
    Code:
        @ __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
        @ __CONFIG    _CONFIG2H, _WDTEN_ON_2H & _WDPS_512_2H
        @ __CONFIG    _CONFIG2L, _BOREN_OFF_2L & _PWRTEN_ON_2L    
        @ __CONFIG    _CONFIG3H, _MCLRE_OFF_3H
        @ __CONFIG    _CONFIG4L, _LVP_OFF_4L  
        
         DEFINE OSC 16
         
        START:HIGH PORTD.1:PAUSE 500
        LOW PORTD.1:PAUSE 500:GOTO START
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    This is cut and pasted from a larger program I have and this digested version is not tested so take it for what it is please. It's written for the 18F2431 so double check the pin assignments for the QEI module.

    Code:
    DEFINE HSER_RCSTA 90h                       'USART receive status init.
    DEFINE HSER_TXSTA 24h                       'USART transmit status init.
    DEFINE HSER_BAUD 57600                      'Baudrate is 57600.
    
    ANSEL0 = 0                                  'All inputs as digital
    
    PortA = 0
    PortB = 0
    PortC = 0
    
    TRISA = %11000                           'QEI pins as inputs.
    TRISB = %00000000
    TRISC = %10000000                       'USART RX pin as input.
    
    QEICON = %00010100                      'Setup QEI, 4X mode, reset on index. 
    
    PosLow VAR BYTE                          'Storage for the low byte of encoder count
    PosHigh VAR BYTE                         'Storage for the high byte of encoder count
    PosTemp VAR BYTE                        'Temporary storage for low byte of encder count
    Position VAR WORD                        'Actual encoder position, 16bit word.
    
    CLEAR
    
    Main:
      Gosub GetPosition
      HSEROUT ["QEI Count: " , #Position, 10]
      Pause 100
    Goto Main
    
    GetPosition:
    'Since the position counter isn't double buffered we can get to situations
    'where the lowbyte overflows between readings of the high and the low byte. This
    'is prevented by reading the low byte two times and compare the two readings.
    'If they are the same then we're fine, if not re-read the registers.
      
        PosHigh = POSCNTH                       'Get high byte of counter
        PosLow = POSCNTL                        'Get low byte of counter
        PosTemp = POSCNTL                       'Get low byte again
        
        If PosLow - PosTemp = 0 then Goto Done      'Compare, if equal we're done.
        
        PosHigh = POSCNTH                           'If not, get values again.
        PosLow = POSCNTL
    
    Done:
        Position = POSHIGH * 256 + PosLow           'Put high and lowbyte together.
    RETURN
    END
    Again, no guarantees but I hope it serves as a starting point for you.

    /Henrik.
    What if my ENCODER have only A and B output's and dont have INDEX pin ?
    Can I use it ???

  9. #9
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Thumbs up hard way to finish of idea of own uhu wuth friends from these forum

    Here is success probe with count encoder from 0 to 2000 for one turn of shaft of motor.
    Code:
    ' Pic 18F4431 @ 20MHz true XTAL
        define osc 20
        DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
        DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
        DEFINE HSER_SPBRG 64  ' 19200 Baud @ 20MHz, 0.16%
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
        ADCON0=0 'Turn of ADC
        ANSEL0=0 'Make Port A inputs Digital
    
        PortA = 0
        PortB = 0
        PortC = 0
    
        TRISA = %011100                'QEI pins as inputs.
        TRISB = %00000000
        TRISC = %10000000              'USART RX pin as input.
    
        QEICON=%11001100
        DFLTCON = %00111000            ' enable error filter for all capture inputs
        MAXCNTL = %11001111           'lowbyte = 207
        MAXCNTH = %00000111           'highbyte = 7 but after math: highbyte * 256 = 1792 + 207 = 1999
    'QEICON = %00010100                   'Setup QEI, 4X mode, reset on index. 
        PosLow VAR BYTE                          'Storage for the low byte of encoder count
        PosHigh VAR BYTE                         'Storage for the high byte of encoder count
        PosTemp VAR BYTE                        'Temporary storage for low byte of encder count
        Position VAR WORD                      'Actual encoder position, 16bit word.
        POSCNTL = 0                            ' clear lowbyte of counter for start
        POSCNTH = 0                            ' clear highbyte of counter for start
    CLEAR
        
    Main:
        Gosub GetPosition
        HSEROUT [dec position]
        Pause 100
    Goto Main
    
    GetPosition:
    'Since the position counter isn't double buffered we can get to situations
    'where the lowbyte overflows between readings of the high and the low byte. This
    'is prevented by reading the low byte two times and compare the two readings.
    'If they are the same then we're fine, if not re-read the registers.
      
        PosHigh = POSCNTH                       'Get high byte of counter
        PosLow = POSCNTL                        'Get low byte of counter
        PosTemp = POSCNTL                       'Get low byte again
        
        If PosLow - PosTemp = 0 then Goto Done      'Compare, if equal we're done.
        
        PosHigh = POSCNTH                           'If not, get values again.
        PosLow = POSCNTL 
    
    Done:
        Position = POSHIGH * 256 + PosLow           'Put high and lowbyte together.
    RETURN
    END
    Will continue...
    Robert

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