+ Post New Thread
Results 1 to 20 of 23

17th November 2019, 09:04 #1
 Join Date
 Apr 2019
 Posts
 53
 Helped
 0 / 0
 Points
 359
 Level
 4
sine/cos encoder to digital
I have sine cos data from encoder and have to convert it to digital corresponding to angle and estimate the velocity as well. I need to do this using MCU. any proven methods?

17th November 2019, 09:55 #2
Awards:
 Join Date
 Jul 2009
 Location
 Aberdyfi, West Wales, UK
 Posts
 13,454
 Helped
 4488 / 4488
 Points
 82,033
 Level
 69
Re: sine/cos encoder to digital
What format is the encoder data at the moment? Presumably analog if it needs converting first.
Brian.PLEASE  no friends requests or private emails, I simply don't have time to reply to them all.
It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.

17th November 2019, 10:20 #3
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100
Re: sine/cos encoder to digital
You'll use atan2() function to convert sin/cos values to angle after digitizing it.

17th November 2019, 10:29 #4
Awards:
 Join Date
 Apr 2014
 Posts
 16,066
 Helped
 3637 / 3637
 Points
 79,154
 Level
 68
Re: sine/cos encoder to digital
Hi,
Sin/cos = tan
Thus divide your "sin" value by your "cos" value. Mint the undefined situations where cos value ( 90° and 270°)
Then from the tan value you may directly calculate the angle.Maybe use a lookup table and interpolation.
But you need to involve the signs of sin and cos value to determine the quadrants, because tan repeats every 180°.
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.

17th November 2019, 10:36 #5
 Join Date
 Apr 2019
 Posts
 53
 Helped
 0 / 0
 Points
 359
 Level
 4
Re: sine/cos encoder to digital
Hi KlausST
How do we deal with infinity (cos90 or cos270)? Secondly I have to also consider time resolution of the incoming data. Input shaft rotates art low rpm (060 rpm) for the highest rpm, time resolution 1/4095 or 244 us. Please guide me regarding the scan rate of this signal?

Advertisement

17th November 2019, 10:48 #6
Awards:
 Join Date
 Apr 2014
 Posts
 16,066
 Helped
 3637 / 3637
 Points
 79,154
 Level
 68
Re: sine/cos encoder to digital
Hi,
How do we deal with infinity (cos90 or cos270)?
If cos = 0, then there are just two possible solutions:
Phi = 90° when sin = positive
Phi = 270° when sin = negative.
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.

17th November 2019, 11:42 #7
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100
Re: sine/cos encoder to digital
atan2() function has no "undefined situations". It's defined over full four quadrants. Review literature before guessing…
Secondly I have to also consider time resolution of the incoming data. Input shaft rotates art low rpm (060 rpm) for the highest rpm, time resolution 1/4095 or 244 us.
Required time resolution is a different thing. It depends on the speed change rate (=bandwidth of the speed information). See similar thread https://www.edaboard.com/showthread....controlsystem
Of course there's no problem to increase the sample rate above the required minimum.

Advertisement

17th November 2019, 12:24 #8
 Join Date
 Apr 2019
 Posts
 53
 Helped
 0 / 0
 Points
 359
 Level
 4
Re: sine/cos encoder to digital
Hi FvM
Just tried atan including quadrant detection. I find the readings of angle non monotonic. excel file attachedLast edited by curious_mind; 17th November 2019 at 12:31.

17th November 2019, 14:06 #9
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100
Re: sine/cos encoder to digital
The angle values are monotonic, but not equidistant. Obviously the sin/cos readings are not corresponding to constant speed rotation, there seems to be a higher frequent ripple superimposed.

17th November 2019, 15:04 #10
 Join Date
 Apr 2019
 Posts
 53
 Helped
 0 / 0
 Points
 359
 Level
 4
Re: sine/cos encoder to digital
Hi FVM
Sampled the same signals at 10kHz. Please see the results(attached) . What should we conclude?

Advertisement

17th November 2019, 15:34 #11
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100
Re: sine/cos encoder to digital
What did you conclude?
The higher sampling rate doesn't change the picture, you have superimposed ripple during the first 45 degree. To me, it looks like a start transient. It shouldn't happen if you start the recording with settled motor speed.

17th November 2019, 16:54 #12
 Join Date
 Apr 2019
 Posts
 53
 Helped
 0 / 0
 Points
 359
 Level
 4
Re: sine/cos encoder to digital
Hi FvM
How did you conclude about the superimposed ripple and how do we remove it. I am unable to make it out. I tried FFT of the two waveforms and it did not show any other component except 1Hz

17th November 2019, 17:17 #13
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100

18th November 2019, 03:55 #14
 Join Date
 Apr 2019
 Posts
 53
 Helped
 0 / 0
 Points
 359
 Level
 4
Re: sine/cos encoder to digital
please suggest a workaround

18th November 2019, 11:00 #15
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100
Re: sine/cos encoder to digital
Workaround for what? We are apparently seeing a real start transient. Unfortunately you didn't mention the test conditions.

18th November 2019, 15:49 #16
 Join Date
 Apr 2019
 Posts
 53
 Helped
 0 / 0
 Points
 359
 Level
 4
Re: sine/cos encoder to digital
Hi FvM
The data was captured during running conditions, and I analyzed the data. The distortion of signal vanished, however the angle data points are not equidistant as previously posted. This poses difficulty in comparing with commercial converters, which provides both monotonic and equidistant angular points. So what should be the technique chosen to meet the requirement

18th November 2019, 15:56 #17
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100
Re: sine/cos encoder to digital
Can't comment unknown measurements.

27th November 2019, 12:16 #18
 Join Date
 Jun 2009
 Location
 Japan
 Posts
 1,068
 Helped
 282 / 282
 Points
 8,575
 Level
 22
Re: sine/cos encoder to digital
Hello!
There are a few things to take care about.
I didn't look at the data, but if you get a (sin, cos) pair of analog signals
from some kind of sensor, you have to first make sure that they are calibrated
(same amplitude) and that their phase is exactly π/2. If not, then you have to
start by a calibration and phase removal, which is not a big deal but must be
done.
Then, you have to be careful with the atan because it's undefined at π/2 and
π/2. Therefore you have to proceed with quarter of periods in the following intervals:
π/4 ~ 3π/4 > Calculate cos / sin (1 <=value <= 1)
3π/4 ~ 3π/4 > Calculate sin / cos
3π/4 ~ π/4 > Calculate cos / sin
π/4 ~ π/4 > Calculate sin / cos
If you don't take the sign into account, then you will get angles between π/4
and π/4. Then using the signs and the symmetries, you can calculate other
values.
NB: as all the tan value are between 1 and 1, it's easy to use a LUT and fixed point.
Anyway, even if you have some CPU power, atan will get you the angle on the
interval π/2 and π/2 only, there is not function that will get you the angle at
once.
Dora.

Advertisement

27th November 2019, 13:01 #19
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,790
 Helped
 13918 / 13918
 Points
 262,005
 Level
 100
Re: sine/cos encoder to digital
you have to be careful with the atan because it's undefined at π/2 and π/2.
The reported problem of superimposed ripple can be found in encoder x and y output signals (see post #10) and is not related to angle conversion.
Not sure how the latest measurements mentioned in post #16 look like. There may be a problem in angle conversion, but we should look at the x/y signals first.
The distortion of signal vanished, however the angle data points are not equidistant as previously posted.

27th November 2019, 15:44 #20
 Join Date
 Nov 2012
 Posts
 3,249
 Helped
 808 / 808
 Points
 17,798
 Level
 32
Re: sine/cos encoder to digital
The data was captured during running conditions,
Sometimes a plot says a lot. So I plotted the last column against column 1.
This is what I get:
The angle data points are not really equidistant.
You can also see a spike at 90 and 270 degree (0.25 and 0.75 time points).
There is a small ripple but that is not the culprit.
The difference is about 0.04 (degree; quite small in my opinion).
But why the difference?
It is not random (only +ve values are seen except the two points).
I suspect the error in the software.
By the way, what is the resolution of the ADC?
   Updated   
NB: as all the tan value are between 1 and 1, it's easy to use a LUT and fixed point.
Just see the plot of tan(x) vs x:
(we cannot plot ±∞ and the graph is cropped).
It is not easy to use a LUT for tan(x).
+ Post New Thread
Please login