PIC based DRO - Page 4

Page 4 of 10 FirstFirst 1234567 ... LastLast
Results 37 to 48 of 113

Thread: PIC based DRO

  1. #37
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    You know, I've been looking through your code and I've reached a bit of a dilema...

    You've really done a fantastic job and from what I can tell, if I were to do it on my own... I'd just be reinventing the wheel and in the end, come up with basically the same thing. (there's only so many ways to do it...)

    So, I think I am going to concentrate on part 2 of this which is the display/control end of things. The plan is to connect all of these to a single 16F883 which will manage the scales and display the info on a small LCD.

    The 16F883 has hardware USART so, that part's done for me

    Gonna do this in assembly so wish me luck. The LCD should prove interesting... It has a standard HD44780 controller.



  2. #38
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    The plan is to connect all of these to a single 16F883 which will manage the scales and display the info on a small LCD.
    I was thinking of doing the same in order to replace the PC. Care to share?

    The 16F883 has hardware USART so, that part's done for me
    The DRO displays need to be updated as fast as possible (to make it feel right on the lathe/mill). This means using the scale's fast 20mS mode. With three (or four) axes to display this gives you 5-6mS to collect, parse, convert and display the binary/bcd to inches and/or millimetres.

    Incidentally, I find the simultaneous display of Inch & mm very useful on the mill.

    Gonna do this in assembly so wish me luck.
    The binary/bcd inch/metric conversion maths may be easier in C.


    The LCD should prove interesting... It has a standard HD44780 controller.
    No that's easy (initialising the 44780 can be a pain). I have some four bit driver code if need it. However, I suggest you make your interface 8 bit, since it'll give you the option of using a VFD module (when you find the LCD unreadable )


    Attached is a zip with a compiled version of the PIC code and the VB5 DRO application installer.

    The app' has a sort of 'demo' mode, so you can look at it and play with out an interface. Either of my interfaces - single com-port powered or multi channel will work with it. One of these days, I'll finish of the MDI version.

    I'll try to put together a typical interface protocol conversation for you later.

    Attached Files Attached Files
    Bill


  3. #39
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default

    Awesome, thanks for the code. I'll have to play around with it when I get home this evening.

    I agree on possibly just writing the program in C. I already know C well and there are built in routines for handling the LCD in either 4 or 8 bit mode. Given the chip's built in usart, the only real code is going to be handling the commands to and from the scales and the conversion of incoming data.

    I suppose I can always practice my assembly on some future project Maybe I'll rewrite the software I used on my stepper driver boards using assembly... hmmm

    As for sharing, of course... I'll share everything I have once things are completed. MikroC spits out an asm file as well, so that might be worth looking at by someone that knows whats what... Could most definately be improved.

    I will keep you updated.



  4. #40
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    How's it going?

    Bill


  5. #41
    Registered
    Join Date
    Jul 2009
    Location
    US
    Posts
    20
    Downloads
    0
    Uploads
    0

    Default still working

    Sorry for not giving any updates or anything for so long. I'm still working on this little by little. It's been hard to find time lately as I just bought a house and am trying to finish getting settled in. Hasn't left much time for fun stuff.



  6. #42
    Registered
    Join Date
    Feb 2010
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default

    Hello Bill,

    What a great DRO project you have done.

    I think I want to give this a try. I found this thread after I have bought a 18F87J50 demo board, this PIC has USB capabilities. Boy does that add complexity!

    I only want a single DRO in my own VB program so I can just buy a $15 Serial to USB adapter and try your much simpler method.

    I just built a hex file from your code using MPLAB IDE v8.01 and I ended up with a byte for byte copy of your hex file, that was cool.

    I think I'll order some 12F675's tonight.

    Would you care to share some VB code that reads the serial port and puts the scales value in a text box?

    Thanks,
    Dale

    Last edited by KiloOne; 02-01-2010 at 11:04 PM.


  7. #43
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    Hi Dale,

    My program is a torturous mess of VB5 object code, so you probably wouldn't want to copy it

    The PIC code responds to 2 byte commands with a VB friendly string (I think it is all documented in the source listings). The receiving app' has to asynchronously workout what it has received then act appropriately (sound hard than it is) . I'll dig out some code for you later.

    Bill

    Bill


  8. #44
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    Dale,

    This is how it's done in my application ATM (I'll try to simplify it later)

    Data received by the Comm control is passed to a Scale Control object in the form of a string.
    Code:
    Private Sub MSComm_OnComm()
    Dim s As String
    'Dim T As Single
        Select Case MSComm.CommEvent
            Case comEvReceive
                s = MSComm.Input
                SC.DataInput s 'pass data to scale control object
            
            Case Is = comEvCTS
                'CTS line change
                If MSComm.CTSHolding Then
                    SendIdentify
                Else
                    SC.RemoveAll 'lead unplugged
                End If
            
        End Select
    End Sub

    The Scale Control object splits up the string, works out what to do with the parts and passes that data onto the appropriate handler.

    Code:
    '* < DataInput Sub Header >
    '* Author.......: {UserName}
    '* Date.........: 03-Aug-2007 12:32
    '* Purpose......: Data from verniers
    '* Assumptions..:
    '* Effects......:
    '* Inputs.......: sting data from scales
    '* Returns......:
    '* ------------------------------------------------------------------------
    Public Sub DataInput(vData As String)
    
        Dim strErrmsg  As String
    
    If Not IsInIDE() Then On Error GoTo DataInputError
    
    '------------------------------------------------------------------------ Main Code
    'update appropriate vernier class
    Dim VS As clsVernier 'Vernier scale object 
    Static RXS As String
    Dim SCid As String
    Dim sData As String
    Dim vMode As Integer
    Dim vType As String
    Dim vUnit As String
    
    
        RXS = RXS & vData
        Do While InStr(RXS, ":") 'Len(RXS) >= 9
            sData = Sfmt.SplitAtDelim(RXS, ":")
     
            Select Case Left(sData, 1)
                Case Is = "C"
                    'connect e.g CX
                    SCid = Mid(sData, 2, 1)
                    'AddScale ScID
                    RaiseEvent ScaleComms("I0")
                Case Is = "D"
                    'disconnected e.g DX
                    SCid = Mid(sData, 2, 1)
                    RemoveScale SCid
                Case Is = "I"
                    'info string  ID,Mode,Type,Unit e.g. IX,0,Decimal,Inch:
                    SCid = Mid(Sfmt.SplitAtDelim(sData, ","), 2, 1)
                    vMode = Sfmt.SplitAtDelim(sData, ",")
                    vType = Sfmt.SplitAtDelim(sData, ",")
                    vUnit = sData
                    If Not Scales.Exists(SCid) Then AddScale SCid
                    For Each VS In Scales ' find the correct Vernier Scale object
                        If VS.Key = SCid Then
                            VS.Mode = vMode
                            VS.ScaleType = vType
                            VS.Unit = vUnit
                        End If
                    Next
                Case Is = "R"
                    'scale has been zeRoed (can't use Z)
                    SCid = Mid(sData, 2, 1)
                     For Each VS In Scales
                        If VS.Key = SCid Then
                           VS.ResetAbsolute
                        End If
                    Next
                    
                Case Else
                    'data e.g. X+00.0000
                    SCid = Left(sData, 1) 'uses the the identifier e.g. W, X,Y or Z to choose the scale ID
                    If Scales.Exists(SCid) Then 'check if scale ID is in scales collection
                        Set VS = Scales.Item(SCid)  ' set current vernier scale object
                        VS.Setdata Right(sData, Len(sData) - 1) ' pass data
                    End If
            End Select
        Loop
    '------------------------------------------------------------------------ End of Main Code
    The Vernier Scale object has to work out the data type convert it and save it in a standard form (e.g. inches)

    The PIC can output three type depending the make of digital vernier used:

    1)A 6 digit Hex number where 20480(d) units = one inch
    2)A signed two significant digit + four decimal place string in Inches
    3) A signed three significant digit + two dp string in millimetres.


    Code:
    Public Sub Setdata(sData As String)
        'takes sData string e.g. H000000 (hex 1/20480"), +00.0000 (inches) or -000.00 (mm)
        'and converts it to ABS value
        Dim pos As Long
        Dim NV As Single
        Select Case True
            Case Mid(sData, 5, 1) = "."
                'decimal vernier in metric mode
                NV = Val(Right(sData, 7)) / 25.4
            Case Mid(sData, 4, 1) = "."
                'decimal vernier in inch mode
                NV = Val(Right(sData, 8))  ' convert decimal string
            Case Left$(sData, 1) = "H"
                ' convert hex string
                    pos = 1 - Val("&" & sData & "00") 'shift 24bit to 32bit and invert
                NV = pos / 5242880 '20480* 256
        End Select
    
      'add to glitch filter 
        If mRev Then
            AddToFilter NV * -1
        Else
            AddToFilter NV
        End If
        mController.Refresh Me  'update the controller
    End Sub
    In order to improve the display stability and remove jitter and glitches I added a simple filter to the output.

    Code:
    Private Sub AddToFilter(NV As Single)
        'filter new value add to abs value
        Static FI As Integer 'filter index
        Dim n As Integer
        Dim FT As Integer
        FT = UBound(Filter())
        Dim Tot As Single
        
        
        'glitch filter
           
        'average last few readings
        Filter(FI) = NV
        
        FI = FI + 1
        If FI >= FT Then FI = 0
    
        For n = 0 To FT - 1
            Tot = Tot + Filter(n)
        Next
        mvarAbsValueInch = Tot / FT
    End Sub
    The display routine reads the Scale object's AbsValueInch or AbsValueMM (the scale object does the conversion to a single precision variable).

    Bill


  9. #45
    Registered
    Join Date
    Feb 2010
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default

    Bill

    Thanks, thats great, I'm sure I can make use if this.

    I'm still considering using an 18F13K50 20 pin USB PIC but I did order the 12F675's.

    I'm wading thru the Microchip USB dll, mpusbapi.dll. It might be not too bad and I can still adapt your VB code somewhat to do it.

    I'm thinking of making a round PCB the size of a 2032 battery that is used in my calipers. One SOIP 18F13K50 and very few external components. It will have a vertical mini-USB connector that comes thru a hole in the battery lid. I can sneak the 2 signal wires inside the case to their pcb pads and solder them on thru the existing connector hole. Should be pretty neat, especially if I can use the USB PIC.

    24 inch calipers for $80 and DRO to a PC, very appealing.

    Dale



  10. #46
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    Be aware that the callipers have the battery +ve grounded (i.e. they sort of run a negative rail).

    I was considering making an opto-isolated version to avoid the problem in future.

    Bill


  11. #47
    Registered
    Join Date
    Feb 2010
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default

    I don't think mine has a +ve Gnd.

    When I check for continuity, with the battery out, between both battery contact points on the pcb and the metal of the caliper, they are both open.



  12. #48
    Registered
    Join Date
    Aug 2008
    Location
    UK
    Posts
    573
    Downloads
    0
    Uploads
    0

    Default

    That sounds like a very different (and better) type of calliper. The 2032 battery is a great improvement. What type of calliper is it? Are you sure that it outputs the same code as the cheaper Chinese ones?

    Last edited by BillTodd; 02-04-2010 at 06:35 AM.
    Bill


Page 4 of 10 FirstFirst 1234567 ... LastLast

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
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

PIC based DRO

PIC based DRO

PIC based DRO