Magnetic Rotary Encoder v2.1

Overview

flickr:5360965359

The Magnetic Rotary Encoder v1.2 is a fantastic building block for positioning systems. The core of this board is the AS5040 chip. This type of chip is commonly called an encoder. It reports its location by measuring the changes in the magnetic field surrounding the chip. This chip measures rotational motion like that of a motor shaft. When properly assembled, this board will allow you to detect the the position and speed of a motor. You can combine this with a motor and a microcontroller to build a closed-loop positioning system whose speed and position can be precisely determined and controlled, even if something unexpected happens.

Specifications

flickr:5360965785
  • 10-bit resolution providing 1024 absolute positions per 360° (step size ~ 0.35°)
  • Simple, 4 pin, .100" pitch interface
  • Runs on 5V
  • 18" cable included
  • 6mm magnet included

Interface

flickr:5361596922
PIN NAME FUNCTION
1 VCC Supply +5V on this pin to power the board.
2 GND Connect to ground to power the board.
3 B This is the 'B' channel of the quadrature output.
4 A This is the 'A' channel of the quadrature output.

LEDs

flickr:5361597140
LED DESCRIPTION
A This is the Quadrature A LED. This will turn on and off in sync with the Quadrature A signal.
B This is the Quadratere B LED. This will turn on and off in sync with the Quadrature B signal.
+ This is the Magnetic Field + LED. This will turn on if the field is too strong or non-existant.
- This is the Magnetic Field - LED. This will turn on if the field is too weak or non-existant.

Magnetic Field Strength Indicators

The +/- leds are diagnostic LEDs to tell you if your magnet is positioned properly. If it is not present, all LEDs will light. If it is too close, the + LED will light. If it is too far, the - LED will light. If it is just right, they will both be off. Here is a handy table:

+ - MEANING
ON ON No magnetic field present.
ON OFF Magnet too strong or too close
OFF ON Magnet too weak or too far away
OFF OFF Magnet field strength just right. Device will function properly.

Usage

flickr:5361646078

Build your device such that the supplied magnet is about 1mm from the encoder's surface, centered on the AS5040 chip. You can place the magnet above or below the surface of the chip. There is even a hole in the bottom of the chip for your magnet to go if you want to position the magnet below the PCB.

Quadrature Encoding

flickr:5360678825

The board's output signal is quadrature encoding (also known as incremental encoding). This is a method for precisely measuring rotation using only 2 wires. An understanding of this technology is critical to using the magnetic encoder board. Read more about it on Wikipedia and at this excellent National Instruments tutorial.

Wire it Up, Arduino Stylie

flickr:5361531646
  • VCC goes to 5V
  • GND goes to GND
  • Channel A goes to D2
  • Channel B goes to D3

Example Code - Arduino

The below Arduino code assumes you have channel A connected to pin 2, and channel B connected to pin 3. Note: it is important that those pins are used, because they include special hardware functions that make it very easy to detect when the quadrature signals change.

Upload the below code to your Arduino. Open your Serial Monitor and set the speed to 19200. You should see the position printed to the serial terminal. Move the magnet over the device and you should see the position change. If you do, then everything is working!

#define ENCODER_A_PIN 2
#define ENCODER_B_PIN 3
 
long position;
 
void setup()
{
   Serial.begin(19200);
   Serial.println("Started");
 
   pinMode(ENCODER_A_PIN, INPUT);
   pinMode(ENCODER_B_PIN, INPUT);
 
   attachInterrupt(0, read_quadrature, CHANGE);
}
 
void loop()
{
   Serial.print("Position: ");
   Serial.println(position, DEC);
   delay(1000);
}
 
void read_quadrature()
{  
  // found a low-to-high on channel A
  if (digitalRead(ENCODER_A_PIN) == HIGH)
  {   
    // check channel B to see which way
    if (digitalRead(ENCODER_B_PIN) == LOW)
        position++;
    else
        position--;
  }
  // found a high-to-low on channel A
  else                                        
  {
    // check channel B to see which way
    if (digitalRead(ENCODER_B_PIN) == LOW)
        position--;
    else
        position++;
  }
}

Using it with the Extruder Controller v3.6

flickr:5361461798

Unfortunately the code to use this board with the Extruder Controller is not yet written. Be the first to write it, and we'll give you a free gift from the MakerBot store!

Using it with the DC Servo Driver v1.0

flickr:5360847899

With the power off, connect the encoder to the DC Servo Driver and follow the usage instructions for that board.

Schematic

flickr:5360985523

Partlist / BOM

Source

flickr:5361599836

The Magnetic Rotary Encoder v1.2 is Open Source Hardware and is licensed under the GNU GPLv3.

Download

History

The Magnetic Linear Encoder v2.1 is an original design by Zach Hoeken of MakerBot Industries.

Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.