PDA

View Full Version : Anyone worked with reading a sine/cosine encoder?



dw_picbasic
- 27th December 2020, 19:22
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

HenrikOlsson
- 27th December 2020, 23:04
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....

HenrikOlsson
- 27th December 2020, 23:18
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.

dw_picbasic
- 31st December 2020, 05:33
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!

HenrikOlsson
- 31st December 2020, 09:42
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.

dw_picbasic
- 31st December 2020, 21:36
Thanks again!
I'm looking into the 18F2431 as we speak!
Greatly appreciate!! :-]

dw_picbasic
- 31st December 2020, 22:09
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?

Acetronics2
- 6th January 2021, 10:59
Hi,

have a look here : http://www.robsonco.com/Dinsmore/Compass2-bas%20program.pdf

site to visit : http://www.robsonco.com/Dinsmore/Untitled_5.html

Alain