[SOLVED !] How to read TTL input of a displacement transducer - Page 2


Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 36
  1. #16
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    74
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    223.72 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    It is called Quadrature encoding. 2 digital signals that are 90 degrees out of phase. One leading the other means forward and 1 trailing the other means reverse. A standard protocol used for displacement sensors and rotary encoders. Be aware that from what you mentioned earlier yours is RS422 level comparable.

  2. 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. #17
    Member
    Join Date
    Mar 2018
    Posts
    140
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    19.14 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Please guide me with a code.I tried many codes but only I can get forward ( increasing) readings.

  4. 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. #18
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    534
    Thumbs Up
    Received: 31
    Given: 7
    Total Downloaded
    3.87 GB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Quote Originally Posted by amod View Post
    My displacement sensor has 90° shift.
    How do you know that as it is not in the data specifications you provided?
    I could find no other specifications from a quick internet search and neither the data you provided or any I found actually indicate which signals are connected to which pins or that it actually outputs a direction rather then just a position relative to one end. Are you sure that you do not have to calculate distance and direction of travel by comparing the current and previous reading of that it the type of output you want?

    Regardless of that the specifications indicate the output is RS422, 11uA and 1V P-P, so...
    1. Being a serial ouput it would be logial to expect the data output (if signed) is either two or three Bytes ( sign byte & magnitude) or a signed Byte/Word value.
    2. Assuming all three specs relating to the RS244 output and not three different output formats I do not think you can read it directly and reliably with a TTL input as the voltage level is too low.

    Therefore, I think the reason you are having trouble reading it is that you are treating the output as a single ended signal when RS422 appears to be a differential signal (the differential Amplifier/TTL links at the bottom of the page may also be helpful).
    If that is the case then possible methods of converting to a TTL compatible signal are...
    1. Purchase a RS422 to RS232 converter chip, probably the best option if you can find one or
    2. Differential amplifer with a gain of 5 or

  6. 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.

  7. #19
    Member
    Join Date
    Mar 2018
    Posts
    140
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    19.14 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Stephen Moss,I confirmed with the seller from which I purchased encoder it has TTL output with 90°shift .The same output as rotory encoder has.I have written a code that works but it only increases reading.

  8. 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.

  9. #20
    Member
    Join Date
    Oct 2013
    Posts
    179
    Thumbs Up
    Received: 8
    Given: 13
    Total Downloaded
    3.14 GB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Hi Amod,

    Here is a link to a program that I posted that reads rotary encoder and sends the result serially. IOC interrupt is used to read the pins and most of the work is done in the interrupt handler:

    http://www.protonbasic.co.uk/showthr...566#post509566http://www.protonbasic.co.uk/showthread.php/77483-Lathe-DRO-for-use-with-TouchDRO?p=509566#post509566

    T
    o count up and down and below zero I use signed integers. Note also that it has X4 count, which means that it counts all changes of both channels.
    Flosi Guğmundsson
    Reykjavík

  10. 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.

  11. #21
    Member
    Join Date
    Mar 2018
    Posts
    140
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    19.14 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Thanks Flosigud.

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

  13. #22
    Member
    Join Date
    Mar 2018
    Posts
    140
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    19.14 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    I purchased a simple rotary encoder which have two outputs and a switch.Iam getting the increasing values but decreasing.pls help.
    Last edited by amod; 28th February 2020 at 19:03.

  14. 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.

  15. #23
    Member
    Join Date
    Oct 2013
    Posts
    179
    Thumbs Up
    Received: 8
    Given: 13
    Total Downloaded
    3.14 GB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    This is the same encoder that I used to test my code.
    Flosi Guğmundsson
    Reykjavík

  16. 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.

  17. #24
    Member
    Join Date
    Mar 2018
    Posts
    140
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    19.14 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Hello Flosigud,
    You used interrupt in your program.I don't know how to use interrupt s.Please tell me how to use them with a sample code.

  18. 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.

  19. #25
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,530
    Thumbs Up
    Received: 75
    Given: 33
    Total Downloaded
    6.56 GB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Well, I saw the YouTube you posted and there is a small code which you could have easily converted.

    I came up with this: -

    Code:
    Dim EncA_LastState  As Bit
    Dim EncA_State      As Bit
    Dim Count           As SWord = 0
    
    
    Symbol EncA = PORTB.0
    Symbol EncB = PORTB.1
    
    EncA_LastState = EncA
    
    '=================================================================
    Main: 
    
    Do
    
        EncA_State = EncA
        
        If EncA_State <> EncA_LastState Then
            If EncB <> EncA_State Then
                Inc Count
            Else
                Dec Count
            EndIf
        EndIf
        
        EncA_LastState = EncA_State
        
    Loop
    According to the video and studying a bit the code, it should work.
    Regards

    Joseph

  20. 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.

  21. #26
    Member
    Join Date
    Mar 2018
    Posts
    140
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    19.14 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Thanks Joseph,
    Your code is working on increasing side only.I tried my code also but result is same.Can you guide me how to use interrupt.I think interrupt should be used for such codes.

  22. 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.

  23. #27
    Member
    Join Date
    Mar 2018
    Posts
    140
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    19.14 MB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Do I have to add pull-up resistor to portb.0 and portb.1 for rotary encoder?

  24. 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.

  25. #28
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    534
    Thumbs Up
    Received: 31
    Given: 7
    Total Downloaded
    3.87 GB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Quote Originally Posted by amod View Post
    Thanks Joseph,
    Your code is working on increasing side only.I tried my code also but result is same.Can you guide me how to use interrupt.I think interrupt should be used for such codes.
    I think the problem lies with the use of the not equals comparison
    Code:
    If EncA_State <> EncA_LastState Then
    as by using the not equals comparison the state of A will be 1-1-0-0 as it rotates and so unless it is moving forward one, back one it will miss every other count as the comparison is only true on a 0 to 1 or 1 to 0 transition. The same applies to the second comparison.

    As I said in reply to your PM you need to compare the current state to the previous state to establish direction, something like this...
    Code:
    Dim Current_State as Byte
    Dim Previous State as Byte
    Dim Position_count as Word
    Dim Position as Word
    
    Update_Position:
    Current_State = PortB & $03   'Read PortB and mask off non sensor (B7:2) bits, inputs on B1 & B0
    
    If Current_State <> Previous_State then    'Only perform position comparisons when there is movement.
    Select Current_State    'Sensor output forward data order is 1-3-2-0-1-3-2-0 
    Case = 0
    If Previous_State = 2 then Inc Position_Count   'Forward
    else 
    Dec Position_Count  'Backward
    
    Case = 1
    If Previous_State = 0 then Inc Position_Count
    else 
    Dec Position_Count
    
    'Add remaining two cases (=2 & =3) here
    'Inc & Dec may need to be reversed depending on how you have wired the senor connections in relation to what you consider to be the direction of forward travel. 
    
    EndSelect
    EndIf
    Previous_State = Current_State  'Update Previous State ready for next comparison
    
    Update_Reading:
    Position = Position_Count * Conversion_Factor  'Convert count to a real distance in cm, mm or Inches as applicable
    Try that the the main loop of a separate program (add output display) to see if it produces the correct results, turning the sensor slowly so that you don't miss any counts. If it does then as I also indicated in reply to your PM using interrupt on change inputs would probably be the best solution for your actual project, placing the Update_Position code inside your interrupt handler as when executed in you main code you could potentially miss rotations.

    There is a whole section on interrupts in the Proton Manual starting at page 440 (Interrupt Directives), and you will need to consult the PIC datasheet for how to set up interrupt on change.
    I suggest reading the Interrupt section of the proton manual thoroughly and trying the examples in a separate program to get a feel for how interrupts work before adding interrupts to your main project program. I would recommend using the immediate On_Hardware_Interrupt over the when the code has time On Interrupt to run the Update_Position code as again with On Interrupt you could potentially miss counts but you should play with both types of interrupt in simple a separate program to get a feel for them.

  26. 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.

  27. #29
    Member
    Join Date
    Oct 2013
    Posts
    179
    Thumbs Up
    Received: 8
    Given: 13
    Total Downloaded
    3.14 GB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    Quote Originally Posted by amod View Post
    Do I have to add pull-up resistor to portb.0 and portb.1 for rotary encoder?
    The encoder you posted may have pull up resistors. Mine didn't so í added those.
    Flosi Guğmundsson
    Reykjavík

  28. 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.

  29. #30
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,530
    Thumbs Up
    Received: 75
    Given: 33
    Total Downloaded
    6.56 GB

    0 Not allowed!

    Default Re: How to read TTL input of a displacement transducer

    I ordered one of those encoders to make tests. It will take a while until it arrives.

    Amod, post your circuit diagram how everything is connected.
    Regards

    Joseph

  30. 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. PIC18F46K20 Can't read digital input on port D
    By normnet in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 20th May 2011, 20:20
  2. 18F26K22 Can't read Analog input on AN0
    By arifcan in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 14th May 2011, 13:45
  3. [SOLVED !] MultiTask? Read input while performing output
    By t0pP8uZz in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 2nd November 2009, 12:51
  4. Torque transducer
    By [email protected] in forum The Lounge
    Replies: 12
    Last Post: 28th September 2007, 21:06
  5. 2 TTL outputs to 1 PIC input?
    By ChrisB in forum Proton Plus Compiler v3
    Replies: 22
    Last Post: 5th January 2006, 06:37

Posting Permissions

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