Magnetic Angle Sensors

Discussion in 'The Completed Projects Collection' started by jpanhalt, Mar 19, 2015.

  1. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,672
    899
    This is not a completed project from my perspective, but the project to date may be useful to others. I don't really have any questions at this time, so "Completed Projects" seemed like a good enough, albeit loose fit.

    As a septuagenarian, I don't get excited over anything much anymore, except maybe gadgets. Lately, I have been interested in angle sensors. I started with a simple accelerometer, which worked well for angles relative to Earth, but it is not so good for angles between parts of a moving object, like a robot. Then I looked at capacitative sensors. That is what is used for the DRO's on my machines, but they are expensive. Finally, I tried magnetic angle encoders. Long story short, I am surprised they work at all, but they seem to work well, are simple, and cheap.

    This report is about an exploratory project of the AMS5048A (PWM and SPI output) magnetic sensor. For a practical device, you will need to make refinements. For my giggles, I bought the development board (AS5048A-AB-1.0-ND), which came with the sensor installed and decoupling capacitors. In addition, I got a little dial with a magnet attached that snaps into the board and properly positions the magnet (RMH05-DK-XX-ND). You can buy the sensor alone, but if you do a cost analysis on materials alone and your labor $1.00/hour, you may decide to go the route I took. I have given the DigiKey part numbers. Mouser stocks the same items. I wrote a simple program to look at the PWM output (attached). It is a very crude first draft.

    AS5048A_Capture.PNG

    This photo is overexposed to show the LCD values. Top line is the counts for the high value (T2H in the program) and the lower value is the total period (T3H in the program). Both values are in Hex and are not corrected for the PWM signal overhead (about 7 to 10 counts, respectively), which is explained in the datasheet.

    Initial testing used a 12F683 at 8 MHz and a Parallax serial LCD. I just approximated the dial positions and got uncorrected values of for 1/4, 1/2, and 3/4 clockwise turns of the K'nob of : 295°, 201°, and 113°, respectively. There was roughly a (-20)° offset, and applying that, my corrected values would be: 275°, 181°, and 93°, respectively. That was just by eye. Of course, either the SPI or I2C interface will probably give better numbers. My next step is to change the MCU to a 12F1840 at either 18 MHz or 32 MHz. I do have a rotary index for cutting gears on my mill, but it is still packed for moving. So, I cannot easily give a more precise estimate of the device's accuracy.

    Nevertheless, I have attached the assembly program used. The schematic is also attached. Pin 7 (GPIO,0) is the output to the Parallax serial display, and Pin 5 (GPIO,2) is the PWM input from the sensor to the MCU.

    Regards, John

    Edit1: 03.20.15 Fixed a typo in the T1CON binary to make pre-scale 1:1 as intended
    I apologize for the lousy looking Assembly file. If you load it into MPLAB with the settings shown (Tabs=5, Gitter = 4 and Page =80), it will look better. I tried to export as a pdf, but couldn't.

    Edit2: 03.23.15 Added schematic.
     
    Last edited: Mar 23, 2015
  2. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    Being an idiot at this type of stuff, I would like to see a schematic, even if only to see how simple it is.
     
  3. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,672
    899
    Hi Bill,

    <snip> This was a very rare instance in which I did not draw a schematic. I will draw something up and post as an edit to the original.

    John
     
    Last edited by a moderator: Mar 23, 2015
  4. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,554
    2,506
    John. I'm glad you're enjoying yourself. Wish I had known earlier what you were up to. I've been using Austria Micro Systems sensors for years now. I have schematics and code for the AS5045. If you'd like to look at them, just ask.
     
  5. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,672
    899
    Thank you for the comments. I decided to post this very simple project, because I didn't recall anything similar being posted recently. Last Winter, I saw a YouTube that showed how one could be used to control a motor's rotation, but that had no code. That device was news to me, and I found the technology and precision claims absolutely intriguing.

    Right now, all I am doing is getting a feel for the devices. The general theme for these projects is simplification of some of the machines I use around my hobby farm and conversion of a Bridgeport mill to CNC. As for specific projects, my first one was a remote leveler for when I have pallet forks on the front loader of my tractor. I used an accelerometer for that, which was before discovering these little gadgets. The accelerometer has its place, but I think ultimately absolute or relative angle sensing will have more uses. For example, a mechanical solution to the pallet fork problem, which is incorporated in some John Deere models, is to effectively create a parallelogram with the linkage. It would seem quite obvious to use a pair of angle sensors in the same general way.

    Do you use the SPI, I2C or PWM interfaces? And yes, I am always interested in code. Unfortunately, I can only manage to read and write in Assembly. I do keep a little library of code snippets, like I put together here, and am definitely interested in sharing, since I have absolutely no commercial interest in them.

    Regards, John
     
  6. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,554
    2,506
    I've used SPI and I2C in the past for many chips, but for this one in particular I've used SSI. As for PWM, I don't have much use for it since it's normally used for direct control and I always use an MCU in practically all my projects. And yes, I too only program in Assembler, though only for the 8051 family of chips. I've developed both SPI and I2C interfaces through bit-banging, since most of my applications are time critical and I need to know exactly what the MCU is doing at all times.
     
  7. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,672
    899
    8051 Assembly is definitely different, but based on the few examples of code I have seen posted, I can understand it pretty well. Of course, being able to read it is not the same as writing it.

    Considering the environment these sensors will be in, I am anticipating using wireless to the master. PWM from the accelerometer was very easy to do that way, as I just transmitted the four key registers (two, high/low pairs, T3 is T1 for the next cycle) as values (i.e., I don't convert to ascii). That could be done without interrupting the timing, as it operated at only 100 Hz, so I captured every cycle. All of the remaining calculations were done in the master.

    In any case, I am going to be quite busy until late Summer doing outdoors work. I will definitely keep in touch with you on this subject.

    John
     
  8. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,554
    2,506
    Sure thing... I'll be here :)
     
Loading...