Lathe DRO for use with TouchDRO


+ Reply to Thread
Results 1 to 5 of 5

Thread: Lathe DRO for use with TouchDRO813 days old

  1. #1
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    100
    Thumbs Up
    Received: 6
    Given: 11
    Total Downloaded
    2.72 GB

    2 Not allowed!

    Default Lathe DRO for use with TouchDRO

    Hi,
    Below is short and simple program that reads two rotary decoders and outputs the readings serially via Bluetooth to Android app named TouchDRO. The program runs on 18f25k22 and uses the Interrupt On Change to read the decoders. It should run on any 18f with four pins of IOC. The program is (I believe) well commented and should be easy to understand.

    Code:
    '    -------------------------------------------------------------'    Name    : Quadrature.BAS                                      
    '    Author  : Flosi Guğmundssn                                  
    '    Notice  : Copyright (c) 2017 Flosi Guğmundsson              
    '            : All Rights Reserved                               
    '    Date    : 2.4.2017                                          
    '    Version : 1.0                                               
    '    Notes   : Interrupt on Change is used to read two qaudrature                                                  *
    '            : encoders and increment counter. Mainloop sends 
    '            : result serially over Bluetooth to TouchDRO app.
    '    -------------------------------------------------------------
    
    
        
        Include "18f26k22intosc64.Inc"
        Declare Hserial_Baud = 9600
        Declare Reminders = Off
        Declare Optimiser_Level 3
        Declare All_Digital = True
        Declare Dead_Code_Remove = On
        
        On_Hardware_Interrupt Interrupt_handler
    
    
        TRISA = 000000                   
        TRISB = 110011                        ' Quadrature inputs, Int0, Int1
        TRISC = 000000                       ' 
        
        Symbol GIE = INTCON.7                    ' Global Interrupt Enable
        Symbol PEIE = INTCON.6                    ' Periferal Interrupt Enable
        Symbol IPEN = RCON.7                    ' Interrupt Priorty Enable
        
        Dim wFSR1 As FSR1L.Word                    ' Used for look up table    
    
    
    '    Setup for Interrupt On Change for PortB 6-7
    '    ----------------------------------------------------------------------------
        
        Symbol RBIF = INTCON.0
        Symbol RBIE = INTCON.3    
                                                            
    '    Setup for Int0
    '    ----------------------------------------------------------------------------
        
        Symbol INT0F = INTCON.1
        Symbol INT0IE = INTCON.4    
        Symbol INTEDG0 = INTCON2.6
        
    '    Setup for Int1
    '    ----------------------------------------------------------------------------
    
    
        Symbol INT1F = INTCON3.0  
        Symbol INT1IE = INTCON3.3 
        Symbol INTEDG1 = INTCON2.5 
        
    '    PortB pullups
    '    ----------------------------------------------------------------------------
        
        Symbol NOT_RBPU = INTCON2.7
        IOCB = 110011                         ' PortB 7-4,1,0 used
        NOT_RBPU = 0                          ' PortB pullups on
                                                    
    '    Enable interrupts
    '    ----------------------------------------------------------------------------
         
        IPEN = 0                            ' Interrupt priority OFF
        GIE = 1                                ' Global Interrupt enable
        PEIE = 1                            ' Enable peripheral enable
        INT0IE = 1                          ' Int0 Interrupt Enable
        INT1IE = 1                          ' Int1 Interrupt Enable
        RBIE = 1                              ' PortB Interrupt Enable
    
    
    '
    '    Look up table for incrementing or decrementing the counter    
    '    and pointer to look up table
    '    ----------------------------------------------------------------------------
    
    
        Dim tLookUp[16] As SByte = 0,-1,1,2,1,0,2,-1,-1,2,0,1,2,1,-1,0 
        wFSR1 = VarPtr tLookUp
        
        Dim bNewX As Byte
        Dim bNewZ As Byte
        Dim bOldX As Byte 
        Dim bOldZ As Byte 
        
        Dim swCntX As SWord                 ' values to increment/decrement 
        Dim swCntZ As SWord
        Dim sbInc As SByte                     ' value of increment,0,1,-1
    
    
        Dim bTmp As Byte
        Dim fCntReady As Bit
        
        swCntX = 0
        swCntZ = 0
        
        While 1 = 1
            While fCntReady = 0 : Wend
            fCntReady = 0
            HRSOut "x",SDec swCntX,";","Z",SDec swCntZ,";",10    
        Wend
            
    Interrupt_handler:
        Context Save
        Toggle PORTC.2
        If RBIF = 1 Then                    ' On RBIF interrupt 
            RBIF = 0
            Swapf PORTB,WREG
            bTmp =  WREG
            bNewX = WREG & 3                ' bNewX = PortB 4,5
            Ror bTmp
            Ror bTmp
            bNewZ = bTmp & 3                ' bNewZ = PortB 6,7
            
            If bNewX <> bOldX Then
                bOldX = bOldX * 4
                WREG = bOldX + bNewX        ' Index to table
                sbInc = PLUSW1                ' Get element
                bOldX = bNewX                 ' update old value
                swCntX = swCntX + sbInc        ' change count
                Set fCntReady
            EndIf
            If bNewZ <> bOldZ Then
                bOldZ = bOldZ * 4
                WREG = bOldZ + bNewZ        ' Index to table
                sbInc = PLUSW1                ' Get element
                bOldZ = bNewZ                 ' update old value
                swCntZ = swCntZ + sbInc        ' change count
                Set fCntReady
            EndIf
            RBIF=0
            Toggle PORTC.2                            
        EndIf
        If INT0F=1 Then                        ' Push button X to clear
            INT0F=0
            swCntX = 0
            Set fCntReady
        EndIf
            If INT1F=1 Then                    ' Push button Z to clear
            INT1F=0
            swCntZ = 0
            Set fCntReady
        EndIf
        Context Restore
    The output is sent serially via Bluetooth to Android app TouchDro. The Bluetooth units work pretty much like any other tranceiver and connects to the serialport of the PIC. I have tried two kinds BT04-A and HC-05 and don't see any difference. The encoders I use for testing are cheap mechanical ones and I have not tried this on a lathe. I have yet to find suitable encoders. I may have to make something up myself. I have a lathe and a mil. If anyone knows of some small encoders suitable for a Sherline lathe I would like to hear that.

    As % signs seem stripped from above code it is zipped below:
    Attached Files Attached Files
    Flosi Guğmundsson
    Reykjavík

Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,755
    Thumbs Up
    Received: 77
    Given: 33
    Total Downloaded
    4.30 GB

    0 Not allowed!

    Default Re: Lathe DRO for use with TouchDRO

    Greetings Flosi,,
    A useful project. After a while people won't spot it in the forum. How about writing a short article for the Wiki?
    It could perhaps go in Example Code/Encoders. Let me know if you do and I'll publish it for you.
    Best wishes
    John

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    100
    Thumbs Up
    Received: 6
    Given: 11
    Total Downloaded
    2.72 GB

    0 Not allowed!

    Default Re: Lathe DRO for use with TouchDRO

    Hi,

    I'm working on a four axis dro for 18f14k22 which has 10 inputs with IOC. I might write that aricle when I finish that.
    Flosi Guğmundsson
    Reykjavík

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,155
    Thumbs Up
    Received: 74
    Given: 173
    Total Downloaded
    4.98 GB

    0 Not allowed!

    Default Re: Lathe DRO for use with TouchDRO

    Flosi, thanks for sharing
    George.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,755
    Thumbs Up
    Received: 77
    Given: 33
    Total Downloaded
    4.30 GB

    0 Not allowed!

    Default Re: Lathe DRO for use with TouchDRO

    Thanks Flosi, that would be useful to others when you get the chance.
    John

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Help needed with lathe tool changer logic
      By chudson in forum Proton Plus Compiler v3
      Replies: 7
      Last Post: 15th November 2010, 18:06
    2. Lathe for sale
      By Lester in forum Wanted and For Sale
      Replies: 0
      Last Post: 12th September 2005, 16:58

    Members who have read this thread since 13th October 2019, 07:50 : 1

    Actions :  (Set Date)  (Clear Date)

    You do not have permission to view the list of names.

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts