Skip to main content
Topic: Magnetic rotary encoder with AS5043 (Read 43154 times) previous topic - next topic

Magnetic rotary encoder with AS5043

Moin

For my current long term project, a high resolution 3D printer  I needed a high precise linear drive.
High resolution means using a UV curing resin and an old lcd projector.
More details will follow as soon as I can set up a proper project website for it.
My plan is to provide many parts of it as possible open source.

I could get my hands on cheap used motor with a attached gearbox and a trapezoidal-thread spindle.
On the down side, it's not stepper motor.
You need some kind of position feedback to drive it to a certain position.
Usually people use optical encoder disks and forked light barriers to measure the motor speed and calculate the position.
While being cheap and simple, this technique has two disadvantages :
  • Machines like cnc mills or 3D printers are usually operated in rather dusty workshop environments.
    As soon as your encoder disk gets dirty you might have wrong readings. So you have to keep it clean.
  • If mounted at the wrong position scattered light e.g. from your lamps can interfere with the measurements.
    So you need to be careful there.

So I've been wondering whether there is no more robust solution.
After doing some research I found of course special modules for big industrial machines.
Which were of course expensive and overkill for my application.

Then I came across with the magnetic rotary sensors by austria microsystems.
Especially the AS5043 looked promising.
The setup for this sensor is rather simple, you need a few external components  and a neodym magnet that is attached to your motors axis.
Then the sensor is placed below the magnet.
Like in this illustration found on the austria microsystems website :

Since it uses the magnetic field neither dirt nor light will be a problem.
The sensor will output the angle of the magnet relative to a programmable starting position via analogue output or via a SSI-Style interface. (See the datasheet for details.)
With 10bit resolution it should be theoretically possible to measure the current angle in 0.35° steps.

I went ahead and requested some free samples with my .edu email-address.
The guys at austria microsystems were kind enough to send me 3 AS5043 and 3 AS5030 (similar part 8bit resolution).
Big thanks to them.

So I made myself a simple breakout board and started testing :

Etched and SurTin applied:


Greencoat applied:


Parts soldered :

As you can see I ripped of a track while drilling. I need better machinery for drilling my pcbs and the next version is going to have bigger tracks.


I used a special ribbon cable connector with locks, because I had some here and they are cool.

The only thing missing for testing was the right magnet.
I found those on ebay : 5x5x5mm Cubes.

The datasheet suggests diametrical magnetized cylinders, but they are hard to get so I decided to try cubes first and they've been working fine so far.

Next I needed a way to mount the magnets a distance about 3-5mm above the chip.
The datasheet recommends other values here but I experimented until I got nice results for my magnets.

So I fired up my lathe for the mechanical parts.
A shaft made of aluminium with a magnet glued in :


Then I fitted the ball bearing into a piece of POM and mounted the PBC on it :





I have not yet tested the SSI output, but I could test the analogue output.
Using a good multimeter, I marked the positions with 2,00V  3,00V 4,00 and then turned until I had the same output again while checking the marks.
If there is an error, I need a better way to measure angels. You can't spot any misalignment with the naked eye.

Also I used my drilling machine to turn it really fast and monitored the analogue output with my oscilloscope.
The result was a nice regular sawtooth just as I expected.
I didn't get any good pictures of the waveform yet, since I only have analogue scope and taking photos of the tube can be a bit tricky.
I'll post them as soon as I can repeat the test.

A final note on aligning the axis, the magnet and the sensor:
The alignment seems to be less critical the stated in the datasheet.
A misplacement of 0.25mm seem to still work.

Next step : Testing SSI.

I'll release the kicad files for the pcb and cad files for the other parts, as soon as I have the time to clean them up.
A friend of mine, working with me on this project, knows how to do proper technical drawings, so I'll also ask him to look over the cad files.
I want them to be compliant to the standards, so if you can't fabricate the part yourself, you can give the drawings to professionals.

That's all so far I'll keep you updated.

Sebastian

/Edit : Updated the image urls for the new website and fixed 100 typos ....
DIY-electronics ... eating all my money and free time since 1998

Re: Magnetic rotary encoder with AS5043

Reply #1
Cool project.  I would certainly enjoy hearing about your progress.  I do wonder what you used for the 'green coat '?

Re: Magnetic rotary encoder with AS5043

Reply #2
Moin

I used green permanent markers for the green coating ... isn't that obvious ?
Just kidding ....
Actually Greencoat is product by the german company Bungard.
http://www.bungard.de/index.php?option= ... ng=english
I've never seen anyone else using it, maybe because its hard to obtain.
Watterott is one of the few shops who offers  it http://www.watterott.com/index.php?page ... t&info=253 .

You can solder through it easily in the first 2-4 day, after that period it is cured.
The cured coating  is harder to solder through, so it acts similar to a solder mask.
It can't replace a real solder mask though, since it doesn't prevent the tin from flowing freely while not cured.

Also I tried to pack up the kicad files.
I used the kicad button for it, so I hope it took care of all the custom libs as well.
Can anyone check the project ?
AS5043board.zip
It's all under CC-BY-SA ...

Greetings
Sebastian
DIY-electronics ... eating all my money and free time since 1998

Re: Magnetic rotary encoder with AS5043

Reply #3
Well that green coat looks like one slick finish.  The homebrew finishes I've seen use glass paint and toner method to protect areas that are to soldered.  But with green coat being solderable and containing flux embedded in it would make it a real time saver.

Re: Magnetic rotary encoder with AS5043

Reply #4
Hi! Please note you can't rely on multimeter when using as5043 as this is absolute angle position sensor and it heavily depends on linearity. So you have to use a scope to check if the output is linear.

I will have time to read through the article a bit later, I have some more comments about magnet positioning, but I'm not sure by now you haven't taken on that already :-)

Update: Oops, I see you used a scope - my fault, too fast to comment :-)

Re: Magnetic rotary encoder with AS5043

Reply #5
On SSI: I've seen quite a few technics on the net - the IC works well on serial frequencies up to 6MHz no problem. I've been also using SPI myself, but as soon as STM32 (which I used as a main board) has a buggy SPI implementation (CS is not working how it is supposed to) and thus cannot provide DMA for quering the IC, I came up with another technique.

Loosing 1 bit of resolution (512 instead of 1024 marks per revolution), I'm very well off with... USART :-) Set it up as 9 bits with hw flow support, use RTS bit (or is that CTS? don't remember really) and set up DMA should you use an MC offering this feature - and you're good to go.

Re: Magnetic rotary encoder with AS5043

Reply #6
Moin

Some thoughts about the multimeter measurements :
I used my Simens B1041, not just some cheap hand multimeter.
Even though it's calibration expired in 2005 it's still more accurate the most of the stuff used by people out there.
The purpose of this test was not finding non linearities, but checking whether it was possible to get back to position given by
the encoders output.
Testing for linearity was of course done with a scope.
By the way scopes calibration also expired in 2005.
Also note that  these were only rather simple tests, just to see whether the device is working at all.
I mean I don't have any real data, just some observations, nothing you can really analyse with mathematical means.
All I can say for sure atm. is that it looks good to me.

The real testing will be done as soon as SSI works.

About SSI and SPI:
I'm also going to (ab)use hardware SPI to read the AS5043.
My plan is to use a AT90USB162, so no DMA.
While comparing the signal diagrams for SPI in Atmels datasheet and for SSI in the AS5043, I noticed a smaller problem.
The AS5043 seems to need clock that is high in Idle stage and  the bits will be shifted out on the positive clock edge.
That sounds very much like the SPI mode 3 in Atmel-speech.
Clock high on idle, data will be read on every rising edge.
And here comes the problem : The Atmel hardware SPI can read the miso pin only at a clock edge.
As I mentioned before that would be the rising edge for mode 3. So shifting out and reading would be done almost synchronous.
We all know, due to signal rise and fall times this will fail 90% of the time.

Therefore things are going to get hacky ....
I'm going to use mode 2: clock high and bits are read at the falling edge.
This leaves me with a different problem : I will read the first bit before the encoder has shifted it out.
The AT90USB162 SPI lets you read 8bit at once and I want to read all 16 bits from the encoder.
So the first byte will look like :  1 bit garbage then D9 to D3.
Reading the next 8bit will work fine since the 8th bit was shifted out on the last rising edge after reading the first 7.
The next 8 bit will look like : D2 to D0, OCF, COF, LIN, MAG INC, MAG DEC.
Everything after the D0-bit is status information needed in order to decide whether the measurement was valid.
But hey wait .... there is one bit missing. The 16th bit contains parity information.
It's need in order to verify that there was no error during transmission and since I want to do stuff right, I'll be of course checking the parity.
Here comes the hacky part:
The last bit will be already shifted out when I read the second byte.
All I have to do is manually check the miso pin state once.
The rest is simply bit shifting.

Also I won't be using the SS pin provided by the SPI module.
It goes high after reading 8 bit ... which will trigger a new measurement
Instead I'll use a normal IO pin for CS.

At least that's my current plan.
I have not tested it yet, but I've seen other people doing similar things on the net, so I'm optimistic.

Greetings
Sebastian
DIY-electronics ... eating all my money and free time since 1998

Re: Magnetic rotary encoder with AS5043

Reply #7
Oh Sebastian, I believe you are so overcomplicating it. First of all, if you don't have DMA, just drag the MC pins - quicker and no haead ackes.... If you want to go for SPI - do the rising edge. You will not get corrupted data - verified. SPI works great (set it up for word transfer length, not byte). And then of course when you played enough with those useless last bytes, come to the dark side - USART :-)

Re: Magnetic rotary encoder with AS5043

Reply #8
Yes, have a better look at the datasheet:
- After a minimum time tCLK FE, data is latched into the output shift register with the first falling edge of CLK.
- Each subsequent rising CLK edge shifts out one bit of data.
This means that you can read data on the rising edge - it's long been latched there - since the falling one.

Re: Magnetic rotary encoder with AS5043

Reply #9
Did you try assisted positioning? It seems that your construction doesn't allow for fine tuning?

Re: Magnetic rotary encoder with AS5043

Reply #10
Quote
Yes, have a better look at the datasheet:
- After a minimum time tCLK FE, data is latched into the output shift register with the first falling edge of CLK.
- Each subsequent rising CLK edge shifts out one bit of data.
This means that you can read data on the rising edge - it's long been latched there - since the falling one.

Yes it is latched out at that time, but it won't be shifted out until the first rising edge at CLK.
See figure 5  on page 6 in the datasheet.
Also it takes some time, to be precise t_DO_valid = 413ns  until the data at DO can be considered valid.
So if you are doing a readout with 1MHz clock, that's about half of your clock period !

You suggested 6MHz ...
The datasheet clearly states under 19.6 Timing Characteristics on page 32 the the maximum read-out frequency is 1MHz.
Also 6Mhz * 4213ns = 2.487 means you have shifted out 2 and a half bit until the first one can be considered valid.

This might work due to the shift register being faster then expected by the manufacturer,
but I don't want to depend on that.

Just for reference : http://www.austriamicrosystems.com/cont ... 7/7220/495

Quote
Did you try assisted positioning? It seems that your construction doesn't allow for fine tuning?

I think you refer to the operating mode called Alignment Mode in the datasheet.
Since I don't have a proper SSI interface no, but my construction allows moving the pcb by about 0.5mm in every direction.
3mm screws in 4mm holes. Simple but effective.

Greetings
Sebastian
DIY-electronics ... eating all my money and free time since 1998

Re: Magnetic rotary encoder with AS5043

Reply #11
Moin

Just a short update.
Here's the new release including all the mechanical parts, used to build the encoder.
AS5043board.zip

While I didn't do much this time, Obi had a lot of omgwhythef*ckisthislinewrong-fun trying to get the cool SolidEdge drawing into something the rest of us can read.
So the credit for the cad stuff goes to him.
SolidEdge is the tool used at our university, so we decide to use the academic edition which is free for students.
While no time learning a new software was required, we had a lot of fun exporting the parts, to DXF and PDF.

Finally it seems to have worked, but I'm afraid we'll still need to tweak our CAD - workflow further.

Greetings
Sebastian
DIY-electronics ... eating all my money and free time since 1998

Re: Magnetic rotary encoder with AS5043

Reply #12
Hi!
Just wanted to show my take on the AS5043.
Double sided PCB by Seed, Voltage regulator onboard,
one LED for power on, the other for magnetic range output.

Nice chip indeed but I am strugling with the digital output. Someone posted code for the arduino and a similar Austria Microsystems chip but this will influence the analog output.

Regards,
Michael


[attachment=0]

Re: Magnetic rotary encoder with AS5043

Reply #13
more pics

Re: Magnetic rotary encoder with AS5043

Reply #14
Moin

Nice board.
The led at the magregn pin is a cool idea. I somehow forgot about it totally.

No mounting holes and round, are you going to put it inside a motor/servo ?

[quote author="Wildweasel"]
Nice chip indeed but I am strugling with the digital output. Someone posted code for the arduino and a similar Austria Microsystems chip but this will influence the analog output.
[/quote]

Influences it in what way ?
Does it write something to the chip that change the config of that output ?

You could try my code, but I used plain C on an atmega32.
Connect  CLK to SCK, MISO to DO, CS to SS.
Don't connect MOSI anywhere.
Code: [Select]
void AS5043_setup(void) {
// Set MOSI and SCK, SS/CS output, all others input
DDRB = (1<<PB5)|(1<<PB7) | (1<<PB4);
// Enable SPI, Master, set clock rate fck/16
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0) | (1<<CPOL);
// double spi speed for fck/8
SPSR |= (1 << SPI2X);

// Set SS/CS
PORTB |= (1 << PB4);
}

void AS5043_readout(void) {
uint16_t data;

//CS low
PORTB &= ~(1 << PB4);

// Write a dummy byte
SPDR = 0xFF;
while(!(SPSR & (1<<SPIF)));
// Read value
data = SPDR >> 1;

SPDR = 0xFF;
while(!(SPSR & (1<<SPIF)));
data = SPDR << 7;
// 15 bit read so far

// Get Parity info ... check not implemented yet
if(PINB & (1 << PB6)) {

}
else {

}

// CS high
PORTB |= (1 << PB4);

}
I hope this woks since I copied only the relevant parts from a bigger sourcecode.

For detailed description what this code does, see my postings about ssi with spi above.

Greetings
Sebastian
DIY-electronics ... eating all my money and free time since 1998