The AS5048A Magnetic Rotary Encoder reading data with Arduino.
Page 1 of 1
The AS5048A Magnetic Rotary Encoder reading data with Arduino.
The AS5048A is an easy to use 360° angle position sensor (absolute encoder) with a 14-bit high resolution output and SPI interface. The maximum system accuracy is 0.05° assuming linearization and averaging is done by the external microcontroller.
Please use Diametrically Magnetized Magnets.
like
http://www.amazon.com/Neodymium-Magnets-Disc-Diametrically-Magnetized/dp/B0089FFO68/ref=sr_1_2?ie=UTF8&qid=1361910412&sr=8-2&keywords=Diametrically+magnet
or
[url= http://www.ams.com/eng/Products/Magnetic-Position-Sensors/Magnets3/AS5000-MD6H-3] http://www.ams.com/eng/Products/Magnetic-Position-Sensors/Magnets3/AS5000-MD6H-3[/url]
Tested code:
Serial output:
Please use Diametrically Magnetized Magnets.
like
http://www.amazon.com/Neodymium-Magnets-Disc-Diametrically-Magnetized/dp/B0089FFO68/ref=sr_1_2?ie=UTF8&qid=1361910412&sr=8-2&keywords=Diametrically+magnet
or
[url= http://www.ams.com/eng/Products/Magnetic-Position-Sensors/Magnets3/AS5000-MD6H-3] http://www.ams.com/eng/Products/Magnetic-Position-Sensors/Magnets3/AS5000-MD6H-3[/url]
Tested code:
- Code:
#include "SPI.h"
unsigned int result = 0;
unsigned int result1 = 0;
unsigned int result2 = 0;
void setup ()
{
Serial.begin(9600);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
}
void loop () {
digitalWrite(SS, LOW);
//Reading 8 bit frame (the first half of 16-bit SPI transfer)
result1 = SPI.transfer(0b00000000);
Serial.print("byte 1: ");
Serial.println(result1, BIN);
// removing (masking) first 2 bit
result1 &= 0b00111111;
Serial.print("byte 1 masked: ");
Serial.println(result1, BIN);
//shifting 8 bit to left. to create emty space for last 8 bit transfer
result1 = result1 << 8;
Serial.print("byte 1 shifted: ");
Serial.println(result, BIN);
// getting last 8 bits (the last half of 16-bit SPI transfer)
result2 = SPI.transfer(0b00000000);
Serial.print("byte 2: ");
Serial.println(result2, BIN);
// merging
result = result1 | result2;
Serial.print("Result: ");
Serial.print(result, BIN);
Serial.print(" = ");
Serial.println(result, DEC);
Serial.println();
digitalWrite(SS, HIGH);
delay(1000);
}
Serial output:
- Code:
byte 1: 10110110
byte 1 masking: 110110
byte 1 shifted: 11011000000000
byte 2: 111010
Result: 11011000111010 = 13882
Similar topics
» Proteus 8 Arduino blink LED
» Arduino Ethernet Shield
» Arduino blink led example: GETTING STARTED
» Proteus 8 Arduino library -- Arduinolibs.zip
» Arduino library proteus Arduinolibs.zip
» Arduino Ethernet Shield
» Arduino blink led example: GETTING STARTED
» Proteus 8 Arduino library -- Arduinolibs.zip
» Arduino library proteus Arduinolibs.zip
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum