Anyone worked with reading a sine/cosine encoder?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2007
    Posts
    78

    Default Anyone worked with reading a sine/cosine encoder?

    Hi All,
    I have a sine/cosine encoder designed for monitoring the rotation in degrees of a telescope.
    I've looked at the output with an o-scope and it produces 36 sinusoidal cycles per one full revolution.
    In order for me to read it with resolution down to a degree, I'll have to divide each full cycle into 10 phases.

    I understand there is a possibility I can simply read it with two A/D channels and use some kind of trig formula to derive movement and direction.

    Does anyone have experience with this - who could help with the math I would need?
    Or perhaps there is example code somewhere - someone could point me too?

    Sincere thanks in advance!!
    dw

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


    Did you find this post helpful? Yes | No

    Default Re: Anyone worked with reading a sine/cosine encoder?

    In your particular case with a low cycles-per-rev encoder and, I image, slow rotational speed (?) it might be possible to go for an all analog approach, otherwise you need to add some comparators to produce digital quadrature signals which you use to count steps and to know which quadrant you're in. Then you use the analog signals for interpolation between those "digital steps".

    If you have not already, take a look at Texas Instrument app.note TIDUA05A as it goes into quite some details on what's involved.

    Keep us posted! I've got a 2048 cpr encoder I've been meaning to play with - perhaps this is a sign to dig it out....

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Anyone worked with reading a sine/cosine encoder?

    I forgot... Ideally you want an ADC with dual S/H inputs (or even dual converters) because sampling the two inputs in sequence as the encoder is moving will introduce errors. The error might be acceptable, I don't know but keep it in mind.
    The 18F2431 family of PICs are the only PIC that I know of (does not mean it's the only one) that has dual S/H circuits. Unfortunately it's old and expensive but still a very cool device with peripherals specifically for motor control applications.

  4. #4
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Anyone worked with reading a sine/cosine encoder?

    Thank you very much Hendrick!
    I had thought about firstly amplifying the signal - which has an amplitude swing of about 1.5 volts and bottoms out somewhere a little above zero.
    And doing that - with an op amp to make it swing between 0-5 volts. And then perhaps follow that with an LM3915 which has 10 comparators with preset voltage increments. At least that would be fun to play with :-]

    I wasn't certain if the PICs A/D would have enough resolution to follow a 1.5 volt swing and get the resolution down to 1/10 of a wave.

    From what I've read - if I first try the A/D route - the formula I should be using is atan2(V2,V1)
    But I've also read that some prefer to make the signal range from +5 to -5.
    If that is case - I'm not familiar with a PIC having an A/D that can read a negative voltage.

    I'll look into the S/H inputs that you spoke of, and the 18F2431 device family.
    I'm not at all familiar with that - but I kind of think I can imagine why - in a sinusoidal signal - that might be applicable.

    Any other hints you feel like passing my way would be greatly appreciated.
    Thanks!

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


    Did you find this post helpful? Yes | No

    Default Re: Anyone worked with reading a sine/cosine encoder?

    With a 10bit ADC (like most PICs have) and a VRef of 5V you get a (theoretical) resolution of 4.88mV. Your typical sin/cos type encoder outputs 1Vpp which means that (again, in theory) you should be able to "divide" that signal into approximately 200 "steps".

    If yours is actually 1.5Vpp then that's obviously "better", you'd get 300 "steps".

    At this stage I would not bother trying to amplify and/or offset the signal(s). I'd concentrate on seeing if it's at all possible to begin with. Then, if it does work but needs more resolution I'd start looking into what can be done either with the signals themselves or with, for example, the reference voltages for the ADC.

    The thing is that even if the PIC has 10 analog channels there's only one ADC and (usually) one S/H circuit. This means that you have to sample and digitize your two signals in sequence which in turn means that cos will change while you're digitizing sin (if the encoder is rotating). With dual S/H circuits (like in the 18F2431) you'll be able to take a snapshot of both signals at the same time, then convert them in sequence because there's still only one ADC.

    Again, this MIGHT not make a difference in your case - or it will totaly ruin it - I don't know but you need to be aware of it.

  6. #6
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Anyone worked with reading a sine/cosine encoder?

    Thanks again!
    I'm looking into the 18F2431 as we speak!
    Greatly appreciate!! :-]

  7. #7
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Anyone worked with reading a sine/cosine encoder?

    I'm thinking there may be a way for me to get my head around the math that will be involved before I start hooking up the PIC to the encoder.

    I was thinking of plugging some numbers into an excel sheet.
    One set of numbers to represent one full sinusoidal wave.
    And another set of numbers with the same values 90 degrees out of phase.

    Then - if I understand the formula - I would acquire the arc-tangent of one and divide it over the arc-tangent of the other - at that same point.
    I was thinking this might help me to anticipate what types of values to expect to see - and how to derive direction and movement them.

    Does that sound like a valuable experiment to you?

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: Anyone worked with reading a sine/cosine encoder?

    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Reading incremental encoder interupt
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st March 2017, 13:50
  2. Reading incremental encoder
    By robbe55 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 4th May 2016, 15:49
  3. ARCOS (inverse cosine)
    By mjphillips1981 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th October 2009, 17:53
  4. Wrong values with COSINE!
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 8th May 2006, 17:59
  5. Working with Cosine
    By Ed Cannady in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th May 2005, 14:25

Members who have read this thread : 3

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