Go Down

Topic: AS5020E ABSOLUTE ANGULAR POSITION ENCODER - Not Able To Read Stable Data (Read 965 times) previous topic - next topic

AmitParmar

Hi Friends,

I am using AS5020E 6-bit Absolute Angular Position Encoder in my project in order to track position of a stepper motor. Here is datasheet of the sensor:

https://www.e-lab.de/downloads/DOCs/AS5020.pdf

I carefully studied sensor datasheet and wrote following code to read data from sensor.  It seems to work fine but I am not getting stable values for each stepper motor position/angle. The values vary in between 3 digits. i.e, for each position, I get 1 1 1 2 2 2 1 1 3 3 something like that. I have attached screen shot of serial monitor as well.

Can somebody please help me resolving this issue? 

Thanks In Advance,
Amit

Code: [Select]
const int clockpin = 7;
const int datapin = 9;
const int cspin = 6;

void setup()
{
  Serial.begin(9600);
  pinMode(clockpin, OUTPUT);
  pinMode(cspin, OUTPUT);
  pinMode(datapin, INPUT);

  digitalWrite(cspin, HIGH);
  digitalWrite(clockpin, LOW);
}

void loop()
{
  digitalWrite(cspin, LOW);
 
  digitalWrite(clockpin, HIGH);
  delayMicroseconds(1);
  digitalWrite(clockpin, LOW);
  delayMicroseconds(1);

  byte data = shiftIn(datapin, clockpin, MSBFIRST);
 
  digitalWrite(cspin, HIGH);
  Serial.println(data/4); //Value devided by 4 inorder to remove last two bits cos its 6-bit encoder
  delay(1000);
}

Southpark

Could you please explain what you mean by 'it works fine except .....'

I just checked the data sheet. This device shifts a 6 bit representation of the angle via a serial transfer method. So while this device might be ok for certain applications.... it might not be great for your purpose. This device is based on magnets ... I think. It might not be a real absolute encoder.

To get things done nicely.... take a look at better devices.... optical absolute encoders.... 10  bit parallel or better. Eg .... 10 pins which can transfer all 10 bit angle position information to a micro-controller as fast as possible. Depends on how quickly you need the angle information.

This 6 bit one ... with 64 levels.... appears to be toylike.

AmitParmar

Thanks for your quick reply and Sorry for confusion.

As I mentioned in my post, The sensor gives me data for all 64 position when i move magnet which is connected to my stepper motor. However, the data does not remain stable. The data varies in 3 digit range. For example If I set magnet to Zero position, sensor would give me 0 0 0 1 1 2 2 something like that. It suppose to be 0 0 0 0 as long as magnet remain at zero position.

I have attached screen shot of the result.

I got this sensor from my client, so, I dont have choice to use different sensor. I will to talk with them and will see if they agree to use different sensor.

Thanks Again,
Amit

Paul_KD7HB

Your results tell me your magnet is either too close to the sensor or the magnet is too powerful, or both. Make some changes in distance and tell us what the results are.

Paul

Southpark

As I mentioned in my post, The sensor gives me data for all 64 position when i move magnet which is connected to my stepper motor.
Does this mean that ----- you are still getting these fluctuations in values even when the stepper motor is not attached/coupled to this encoder device?

If this device has 64 values spread around 360 degrees, then the value eg. 0 to 63 should only change for a 360/64 or 5.625 degree change in angle. And 5.625 degree is relatively sizeable change.

Also ---- for your stepper ----- what amount of angular change do you want to detect? Will changes of 5.625 degree be satisfactory for your application?

For your code .... instead of serial printing data/4 .....  also serial print 'data' itself. And show some results of the values of 'data' for various angular cases. Begin with the 'zero' angular position, and then move to the next higher position (ie. the '1' position), followed by the '2' position. And serial print 'data' only ..... not data/4.

Also ---- even if the delay(xxxx) function has nothing to do with the issue, you could begin to practise coding methods that allows for time-delays to occur without using 'blocking' (or time-blocking) functions like delay(xxxx). The delay(xxxx) function pretty much does a time-freeze on the rest of your computer program functions until the delay(xxxx) finishes doing its timing delay. Google details on 'arduino delay blocking'.

MorganS

The recommendations for the magnetic material of the magnet are important. By specifying a material and a size for the magnet, they have effectively specified the magnetic field strength.

Just any old bar magnet probably won't work.
"The problem is in the code you didn't post."

mikb55

As with anything involving sensing magnetic fields you need to ensure that external fields, such as those leaking from the stepper motor, don't influence the sensor readings. You need physical separation and a non-magnetic  coupling to the motor.

jremington

Quote
to track position of a stepper motor
With proper mechanical design and selection of motor and driver, the stepper won't skip steps.

So you know the "position".  Why the encoder?

AmitParmar

Hi Friends,

Thanks for quick reply. I got lots of awesome suggestions to resolve my issue. I appreciate all of you and will try to cover what suggestions i applied and what result i got in my post

Your results tell me your magnet is either too close to the sensor or the magnet is too powerful, or both. Make some changes in distance and tell us what the results are.
My client is using industry standard magnet and stepper motor. They use same magnet and sensor for their other product without any problem. so, I think the problem is not with magnet. I also tried to change the distance between magnet and sensor which increases the fluctuations.

Does this mean that -----
Yes, The values fluctuate a lot when magnet/stepper motor is not attached to sensor. Here is the result when magnet is not attached:

238   198   114   235   123   238   99   238

I want to read sensor data at every 15 degree of stepper motor which is 360/15 = 24 positions.

As per suggestions, I made following changes to my original code , capture 10-11 sensor reading for all 24 stepper motor position and attached the result to the post.

Code changes: Instead of delay function i used millis(), replace 'data/4' with 'data'.


The recommendations for the magnetic material of the magnet are important. By specifying a material and a size for the magnet, they have effectively specified the magnetic field strength.
Just any old bar magnet probably won't work.
As I mentioned, My client is using industry standard magnet and stepper motor. They have been using it for long time and for their other products so, I think magnet is not the issue.

As with anything involving sensing magnetic fields you need to ensure that external fields, such as those leaking from the stepper motor, don't influence the sensor readings. You need physical separation and a non-magnetic  coupling to the motor.
They are using very expensive industry standard stepper motor. The whole mechanism is well designed and physically separated. I wish i could posts the pictures of mechanism here but due to agreement, I cant post them. 

With proper mechanical design and selection of motor and driver, the stepper won't skip steps.
So you know the "position".  Why the encoder?
I am new to the project  and Their mechanism is way too complicated. As per my understanding, It may possible that the mechanism get heavy load and stepper motor skips some steps so they double check stepper motor position with sensor. Hope I got it right  :)

jremington

Quote
They are using very expensive industry standard stepper motor. The whole mechanism is well designed
If it skips steps, that is a design failure. But I suppose you would want to know about that.

But given that you are having problems reading the encoder, if the motor and encoder disagree, how will you know which has failed?

mikb55

The sensor was released in 2001 or thereabouts and cost less than $2 each. There are no obvious current suppliers. I don't see any references to drop in replacements. I can only assume the equipment is old. If you don't have any replacement chips on hand then it looks like you are going to have to pick a different sensor.

Does this equipment use an Arduino or does it pre-date the Arduino era?

Southpark

Armit .... the values themselves --- ie. the serial printed 'data' values look just fine, themselves - despite the fluctuation. The fluctuation is the issue obviously.

Do you get the same fluctuation for cases where the stepper is de-energised (unpowered)?

That is, do the data values become constant under the most basic condition --- ie. measuring an angle for various arbitrarily selected positions? Or do you still get those fluctuations for the most basic tests?

Go Up