MachineKit Encoder
Motivation
w/ AS5304 / AS5306
Pins for Quadrature Input on ATSAMS70?
A key limitation in my previous work here was encoder positioning. I wanted to use a ring magnet and off-axis linear sensor to decode rotary position - the trouble was I could only find one supplier of ring magnets with the right pole spacing, and it was ~38mm ID. The whole gist of the mechanical design here is to bring the diameter way up, so this was not satisfactory, or, at least, it was a constraint.
Here I am going to try to use discrete magnets in an assembly of my own... I am basically just building a big ring magnet, and trying to read that.
Problems
I am using an AS5304 (4mm poles) or an AS5406 (2.4mm poles). Each has 160 positions per magnetic period. This translates to a resolution of 25um and 15um steps, respectively. If I wrap this around some diameter D I have that
angular resolution = 360 / (((PI x D)/pole_length) x 160)
Of course, I have to set the circumference equal to an integer value of magnets. I wrote a quick spreadsheet for this, and get that w/ a Diameter ~ 100mm (where the gearbox currently stands) I can get 0.017 deg/step with a 2.4mm pole pair, and ~ 0.03 deg/step with a 4mm pole spacing. Nice.
Now, this is not so straightforward. The important thing to remember is that Resolution != Accuracy - while I have ~ 0.03 deg / step, those steps are not exactly mapped perfectly in a circle. I will actually be referencing magnets that are glued in place - so my glueing and magnet placement would have to be perfect for Resolution to = Accuracy. In addition, not all magnetic fields will be identical, etc. Everything is crooked.
In addition to these mappings between poles, I will have some deviation, I'm sure, within the poles. As in, the magnets will likely have small gaps (finding a magnet which is perfectly 4mm across... not likely) and so I expect readings to kind of sine-wave around linear.
This can be overcome in implementation by mapping in memory a lookup table, with respect to some 'home' position, of how measured ticks of the encoder match up with reference positions. For example, I would rotate the encoder to known positions (with some other, higher precision system) and map readings -> known values.
This is not ideal! And it requires a deal of labor, some good routines and memory-storage games, and a reference point.
In this exercise (which I am trying to keep bounded)1 I will try only to measure this deviation-from-perfection. Or, at least, deviation from some other, better positioning system.
At best, I hope to cancel periodic deviation (i.e. map the sine-wave between individual poles into a more linear interpolation. my encoders have an Index pulse (on every top-of-pole) that I can use as a reference point for this.
Design
Without further ado, here's a sketch of how I plan to build the encoder:
And then, a system to put that encoder in set positions, while measuring...
- while pole pairs are 4.0mm apart, poles are 2mm long - magnets are 2mm across.
In some moment of foresight, I want to find an encoder with a bigger pole spacing - I think that 2mm is tooo small and seems likely to drive me to madness in assembly. Time to DigiKey it up! None are available, boo. The other option is to truly roll my own encoder, using Hall Effect Sensors with variable output, look at the sine waves, and do encoding from there. This is becoming a challenging project.
OK, nevermind. I'm going back to on-chip quadrature de-quadraturing (or, mag field -> quadrature).
I made a home for the board
And started laying out a schematic. Had to build the footprint in Eagle.
If you're wondering why I have SPI pins labelled, it's because I'm actually connecting this to a plug on my Networking Switch - these are the pinouts. Instead of SPI I will just configure those pins to do GPIO.
THIS is a big what-if for me. As in, what if I get my switch boards back from the fab and it turns out I can't get GPIO to work on these particular pins? I have trapped myself. !
I also have voltage dividers set up here - the AS5304 drives 5v, and I don't want to pump that into my puny 3v3 logic lines on the ATSAMS70.
I also have a jumper / pin header footprint setup on the Analog Out pin - this will let me read the strength of the magnetic fields, making sure I am aligned.
Ideally, I would tie these to an ADC on the ATSAM, but I haven't broken any of those out on the BLDC encoder board... this is a long chain of interconnects. I am rethinking my overall switch -> peripheral strategies now. A good learning / systems design moment. OR I could tie it to some kind of comparator, and have an LED turn on only when that voltage was in a particular range. shrugguy
OK, Routed
Exporting to mods from Eagle is a bit of a pain. In the fullness of time I would write a MOD to do GERBERS -> Milling, however.
Layers -> none Layers -> Top, Pads export image monochrome
Layers -> none Layers -> Bottom, pads export image monochrome
... ok
Back to my layout, and working back into my sheet, I'm going to add magnets here:
And then to test this against some reference, I'm going to use a stepper motor. With the current diameter I'll have 0.05 deg resolution (or, I would ideally) - this means I would need 1/32 microstepping to match up on a stepper motor - I want my reference to have a bit more resolution than what I'm measuring, so I'll try to find a stepper motor with 400 steps / rev, and do 1/32 microstepping on that. Then I have 0.028 deg / step. I'll also bring the diameter down on my encoder to 58 poles, so I'll have 0.077 deg / step there. This means I have about 3x the resolution on my reference than I do on my measured-thing, and intuitively that feels like a good spec. Thumbs up.
ALSO - I knew I should check this, and I'm glad I did - here's a #2 and a #0 screw - the #2 contacts the encoder ring. Noice.2
Final touches, I'm going to make a mount for a NEMA17 Motor on the back, and a little teeny desktop stand.
OK, check it oot
Fab: the board
So I milled this board on the Roland SRM-20. I'm plugging this into my other ongoing work... here's my brushless motor controller that rides below my even-more-unresolved networking chip. Those ports you see on the left of the bldc-driver are for other GPIO, including this encoder.
Ramble ramble, here it is:
And you can see the AS5304 here
Also, a moment of appreciation for the new Leica microscope that showed up at the CBA soldering station. Has variable zoom, and generally is very lovely.
Fab: the kit
I printed the hardware on the Eden. The Eden's washing-up station is currently broken, and I spent the better part of an afternoon trying to cobble together a fittings-and-adapters solution to unbreak it, to no avail. I await McMaster parts.
Programming
I'm using my ATSAMS70 Switch (link?) - I actually used this project as an excuse to bring the GPIO (in SAM-speak, this is just 'PIO' and stands for Parallel Input and Output). Looks like it's datasheet-o-clock again...
Measurements
I want to be like Sam. Sam measures everything and he does it really beautifully. This is some of the functionality I really want to be able to bring into mods - the ability to quickly pull test data out of systems, do computation with it, and learn.
With that motivation, I want to take this chance to run a test cast of that. The Goal here:
- Use one of the 'network switches' (or are they routers? vagueness rules in this project at the moment)3
- Gateway it to MODS
- Build a basic interface to do this test, where I spin the stepper around a few times and measure devation from 'linear' rotation between the stepper and the encoder.
- Pull this data out and chart it in mods, using javascript to do the maths.
- Have some conclusions, or solutions, to whatever I see in this data.
Footnotes
- But I am also planning on actually using this encoder in my implementation of an arm, and later in linear applications, so having an idea of how to really pull this off is - I am hoping - something that will come to me. But I make no plans as such. Seems hard.
- Ideally I would solder small threaded-things on to the back of the PCB, then I could mount it from the rear and really pinch the rest of it against the plate. Also this would allow me to adjust the encoder position with the ring already in place.
- In any case, they are modular hardware - ATSAMS70 chip w/ a 40 pin extension header that I plan to do 'stuff' with. I want a good backbone for motion control, a chip to get cozy with.