EMBEDDED FOR US
Would you like to react to this message? Create an account in a few clicks or log in to continue.

The AS5048A Magnetic Rotary Encoder reading data with Arduino.

Go down

 The AS5048A Magnetic Rotary Encoder reading data with Arduino. Empty The AS5048A Magnetic Rotary Encoder reading data with Arduino.

Post  Admin Tue May 21, 2013 2:25 am

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]

 The AS5048A Magnetic Rotary Encoder reading data with Arduino. 8rBKOTJ



 The AS5048A Magnetic Rotary Encoder reading data with Arduino. G1vtSrO



 The AS5048A Magnetic Rotary Encoder reading data with Arduino. 2UHe8JS
 The AS5048A Magnetic Rotary Encoder reading data with Arduino. ZxeegQY
 The AS5048A Magnetic Rotary Encoder reading data with Arduino. S5BOhcH
 The AS5048A Magnetic Rotary Encoder reading data with Arduino. 9A9QRop


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

Admin
Admin
Admin

Posts : 49
Join date : 2012-08-15
Location : Mumbai,INDIA

http://embeddedforus.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum