PMDC SERVO MOTOR WITH quadrature encoder DRIVE ?


Closed Thread
Results 1 to 38 of 38

Hybrid View

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

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

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

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

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

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


    Did you find this post helpful? Yes | No

    Talking

    My first step to make led blink and probe with these code:
    Code:
    define osc 20
    
        ADCON1 = 7
        led1 var porta.0
        led2 var porta.1
        high led1
        low led2
        pause 1000
        loop:
        toggle led1
        pause 500
        toggle led2
        pause 500
        goto loop
    And led wor blink...
    Now we will learn other fuses and options on 18F4431..
    But I still mean we must be WIZARD to get all we need..
    There is 400 pages of datasheet.
    All what I want to make is UHU type of PMDC control to interface it to MACH3 software for CNC.
    Idea come from original UHU controller from Uli Hubert from Germany.
    He use ATTINY2313 and make full stf WOW.
    Can you image these :
    He put in that little chip quadrature encoder full measure of his speed , direction and velocity reading ,
    capture coming pulse from PC wich is from 1-5 uS, PID control , RS232 terminal , 20KHz PWM , current measure , and motor control ...ETC.
    Then with 18F4431 must be much easy to do that.
    His UHU controller is maybe the best in world and I was test it like finished module on my friend CNC wich work 2 years without error 10h/day .

    Regards Robert
    Attached Images Attached Images
    Last edited by phoenix_1; - 31st August 2009 at 23:03.

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


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit and Henrik,
    My PIC is 18F4431
    I have success with 20MHz XTAL and define osc 20 , fuse HS.
    I found motor with encoder with INDEX pin and little modific Hanrik code.
    Result is 16 bit counter but I must find calculation becouse my encoder is 500 pulse per full rev of motor shaft.
    Henrik you was give me good way for start with 18F4431..thanks man again.
    Last edited by phoenix_1; - 1st September 2009 at 08:55.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by phoenix_1 View Post
    Hi mackrackit,
    My PIC is 18F4431
    I have success with 20MHz XTAL and define osc 20 , fuse HS.
    Mine works fine with 20Mhz HS also. It is when I try to run at 40Mhz HSPLL the problem starts. Maybe I have some bad 10s that are running a bit fast???
    I have some new 10Mhz on order, find out then.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    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
    Maybe you need to set manuel 4 nibbles of config manuel :

    Code:
    bit 7 IESO: Internal External Switchover bit
    1 = Internal External Switchover mode enabled
    0 = Internal External Switchover mode disabled
    bit 6 FCMEN: Fail-Safe Clock Monitor Enable bit
    1 = Fail-Safe Clock Monitor enabled
    0 = Fail-Safe Clock Monitor disabled
    bit 5-4 Unimplemented: Read as ‘0’
    bit 3-0 FOSC<3:0>: Oscillator Selection bits
    11xx = External RC oscillator, CLKO function on RA6
    1001 = Internal oscillator block, CLKO function on RA6 and port function on RA7
    1000 = Internal oscillator block, port function on RA6 and port function on RA7
    0111 = External RC oscillator, port function on RA6
    0110 = HS oscillator, PLL enabled (clock frequency = 4 x FOSC1)
    0101 = EC oscillator, port function on RA6
    0100 = EC oscillator, CLKO function on RA6
    0010 = HS oscillator
    0001 = XT oscillator
    0000 = LP oscillator
    and probe ?
    Last edited by phoenix_1; - 1st September 2009 at 20:34.

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


    Did you find this post helpful? Yes | No

    Default Duh!!!!

    Quote Originally Posted by mackrackit View Post
    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.
    In my haste I made the stupid mistake of NOT having capacitors near the PIC across VDD/VSS. A friend pointed this out.

    The PIC runs fine at 40Mhz.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by mackrackit View Post
    In my haste I made the stupid mistake of NOT having capacitors near the PIC across VDD/VSS. A friend pointed this out.

    The PIC runs fine at 40Mhz.
    You is the member of simple peoples TEAM... :-) like me.
    Regards Robert

  12. #12
    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 ???

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


    Did you find this post helpful? Yes | No

    Default

    Dave,
    I've never used the PLL on this series of PIC's I've run it on 4Mhz and 20Mhz "straight" though without problems, x-tals though, not resonators. Please keep as posted if/when you find the culprit.

    Robert,
    Yes the UHU-servo chip is impressive - I have a couple of them on 160V/25A drives (the HP-UHU) and they perform very well indeed. I've been meaning to play with replacing the UHU chip with a 18F2431 to gain some performance, mostly in the encoder count frequency. I've found the max encoder count frequency on the UHU-chip to be ~130kHz. Haven't got around to that yet though....

    You can use the encoder without index, the difference would be that the count doesn't automatically reset each each rev of the motor - something you probably don't want it to do anyway. Read up on the operation of the QEI module and QEICON register - you can set it up to operate in a few different ways.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,
    Yes I will measure a couple of encoder today to find if there INDEX pin.
    Maybe with some logic chip from CD40XX serie I can provide INDEX pulses if there isn't INDEX pin ?

    Regards and thanks for replay to all.
    Robert
    Last edited by phoenix_1; - 1st September 2009 at 07:41.

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