Quick thoughts: DT Ints with encoders


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Hey Hendrik,

    I'll take a glance at the parts you mentioned. Kinda cool you mentioned the uarts. Maybe you can answer a lingering question for me... In the example of the six "slaves" reporting to the "master"... If I send HSEROUT from the slaves, what would be the protocol for receiving at the master? Would I use SERIN2? What mode? Etc, etc?

    That question has driven me nuts for some time!

    I'm thinking 20 Mhz on the slaves and 40 Mhz on the master.

    What are your thoughts?

    Thanks again,

    Chris

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default

    Hi Chris,
    There are varoius ways to do it. You could for example have two wires between each slave and the master PIC. The master signals one slave at a time to to send the current position, and receives it with SERIN or SERIN2. When all 6 slaves are polled it sends the data to the master. The USART sends the data "true" so the master would need to receive it "true".

    Another approach is to implement a RS485 network.

    /Henrik.

  3. #3
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    I'll work on a bit of code and we'll see where it takes us...

    I'll keep you posted.

    Thanks,

    Chris

  4. #4
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Here's what I've got so far... for the "slave" pics anyhow.

    Critiques are definitely welcome!

    16F688 w/20Mhz

    Code:
    INCLUDE "DT_INTS-14-MOD.bas"
    INCLUDE "ReEnterPBP.bas"
    
    'Clock setup
        Define OSC 20
    'Pin setups
        ANSEL = %00000000       'No analog input
        TRISA = %00000111       'PortA: TRISA = %00XXXXXX
        TRISC = %00000000       'PortC: TRISC = %00XXXXXX
    'Usart setups
        DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
        DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
        DEFINE HSER_SPBRG 86  ' 57600 Baud @ SPBRGH = 0
        BAUDCTL.3 = 1         ' Enable 16 bit baudrate generator
    '----------------------------------------------------------------------------
    
    MaxCount con 21600
    BtnZeroCount var PORTA.0
    APin var PORTA.1
    BPin var PORTA.2
    AOld var byte
    BOld var byte
    CurCount var word
    
    ASM
    INT_LIST  macro    ; IntSource,  Label,  Type, ResetFlag?
            INT_Handler   RAC_INT,  _ABInt,   PBP,  yes
        endm
        INT_CREATE           ; Creates the interrupt processor
    
        INT_ENABLE  RAC_INT  ; Enable RA change interrupt
    ENDASM
    
    curcount = 0
    
    Start:
    
    if btnzerocount = 0 then    'btnzerocount (A.0) has pullup res
        curcount = 0
    endif
    
    aold = apin
    bold = bpin
    
    hserout ["$", dec5 curcount]
    
    goto start
    
    ABInt:
    
    '\\\ A caused the interrupt ///
    IF apin != aold THEN                       'APin IS NOT equal to AOld
        IF apin != bpin THEN                   'If A and B are different,
            GOTO CW                                 'it was clockwise rotation
        ELSE                                   'Otherwise,
            GOTO CCW                                'it was counter-clockwise rotation
        ENDIF
    ENDIF
    
    '\\\ B caused the interrupt ///
    IF Bpin != Bold THEN                       'BPin IS NOT equal to BOld
        IF apin == bpin THEN                   'If A and B are the same,
            GOTO CW                                 'it was clockwise rotation
        ELSE                                   'Otherwise,
            GOTO CCW                                'it was counter-clockwise rotation
        ENDIF
    ENDIF
    
    CW:                 ' -1
    if curcount > 0 then
        curcount = curcount -1
    else
        curcount = MaxCount
    endif
    @ INT_RETURN
    
    CCW:                ' +1
    if curcount < maxcount then
        curcount = curcount +1
    else
        curcount = 0
    endif
    @ INT_RETURN
    Thanks again guys,
    Chris
    Last edited by kevlar129bp; - 6th January 2010 at 02:22. Reason: Added Pic part#, fixed TRIS reg's...Doh!

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I'd move the aold=apin, bold=bpin to the ISR. If kept in the main routine it's possible that a new interrupt occurs, for example, right between those two lines which will mess with your count - I think.

  6. #6
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Thanks Henrik,

    Thanks for the heads up. I see your point there. Otherwise, do you think I've got viable code?

    Thanks again,
    Chris

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Yes, it look OK to me, the quadrature decoding seems to be correct but I'm sure someone around here knows of a faster/slicker way of doing it. (I'm not saying your way is slow).

    Are you sending directly to a VB program for testing or are you sending to a terminal program or something like that? If a terminal program I'd put Pause 100 or whatever in the mainloop and add a CR to the end of the "message". If you're sending to a VB program, you could send the high and low byte of the counter and put them together in the PC.

    If the encoders have Index-channel you could use that to zero the counter, at startup you move each joint of the arm thru "center" and it automatically zeros.

    /Henrik.

Similar Threads

  1. DT Ints work around for IOCA Register?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th January 2010, 01:20
  2. Problem with Dt Ints Interrupts
    By Quin in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th July 2008, 19:21
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21

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