Magnetic Encoder AS5145 pins

Custom built or hacked Electronic boards and sensors
6 postsPage 1 of 1
6 postsPage 1 of 1

Magnetic Encoder AS5145 pins

Post by MOHIT JINDAL » Tue Aug 28, 2012 2:59 am

Post by MOHIT JINDAL
Tue Aug 28, 2012 2:59 am

Hi; I want to connect magnetic encoder AS5145 to Arduino Uno 3. Can anyone here tell me which pins of encoder go where in Uno 3 ? I want to get the position/angle of the DC motor from AS5145. I attached the datasheet in My Files section. Please read. :? File name is AS5145 HSSU.pdf
Hi; I want to connect magnetic encoder AS5145 to Arduino Uno 3. Can anyone here tell me which pins of encoder go where in Uno 3 ? I want to get the position/angle of the DC motor from AS5145. I attached the datasheet in My Files section. Please read. :? File name is AS5145 HSSU.pdf
MOHIT JINDAL offline
Savvy Roboteer
Savvy Roboteer
Posts: 178
Joined: Wed Nov 10, 2010 7:43 am

Post by mog123 » Thu Aug 30, 2012 9:23 pm

Post by mog123
Thu Aug 30, 2012 9:23 pm

If you are talking about incremental mode, then you should connect Dtest1_A and Dtest1_B to IO2 and IO3 which correspond with the atmega328p external interrupts. Then you will to learn how the incremental mode works and implement an external interrupt oriented code. Other modes will need more fiddling, because of the reprogramming of the AS5145 chip which is quite a hard task when tackling these chips for the first time. Good luck!
If you are talking about incremental mode, then you should connect Dtest1_A and Dtest1_B to IO2 and IO3 which correspond with the atmega328p external interrupts. Then you will to learn how the incremental mode works and implement an external interrupt oriented code. Other modes will need more fiddling, because of the reprogramming of the AS5145 chip which is quite a hard task when tackling these chips for the first time. Good luck!
mog123 offline
Savvy Roboteer
Savvy Roboteer
Posts: 50
Joined: Sat Jan 30, 2010 2:19 pm

Post by MOHIT JINDAL » Fri Aug 31, 2012 2:39 am

Post by MOHIT JINDAL
Fri Aug 31, 2012 2:39 am

Thanks. Can you give me your code which you wrote ? :roll:
Thanks. Can you give me your code which you wrote ? :roll:
MOHIT JINDAL offline
Savvy Roboteer
Savvy Roboteer
Posts: 178
Joined: Wed Nov 10, 2010 7:43 am

Post by mog123 » Fri Aug 31, 2012 8:42 am

Post by mog123
Fri Aug 31, 2012 8:42 am

I didn't write any. Besides, You need to learn how to research these things for yourself
I didn't write any. Besides, You need to learn how to research these things for yourself
mog123 offline
Savvy Roboteer
Savvy Roboteer
Posts: 50
Joined: Sat Jan 30, 2010 2:19 pm

Post by MOHIT JINDAL » Fri Aug 31, 2012 9:16 am

Post by MOHIT JINDAL
Fri Aug 31, 2012 9:16 am

Yes i already posted on arduino forums and 2 other forums. No help with the code. Trossen blocked my account saying i am a spammer. :lol: maybe one day we will get all sensors plug n play. After 2020. 8)
Yes i already posted on arduino forums and 2 other forums. No help with the code. Trossen blocked my account saying i am a spammer. :lol: maybe one day we will get all sensors plug n play. After 2020. 8)
MOHIT JINDAL offline
Savvy Roboteer
Savvy Roboteer
Posts: 178
Joined: Wed Nov 10, 2010 7:43 am

Post by MOHIT JINDAL » Mon Sep 03, 2012 8:05 am

Post by MOHIT JINDAL
Mon Sep 03, 2012 8:05 am

I have found one code,but I don't think its for getting angle\position of DC motor.
Code: Select all
const int ledPin = 13; // LED connected to digital pin 13, used as a heartbeat
const int clockPin = 7; // output to clock
const int CSnPin = 6; // output to chip select
const int inputPin = 2; // read AS5045

int inputstream = 0; // one bit read from pin
long packeddata = 0; // two bytes concatenated from inputstream
long angle = 0; // holds processed angle value
long anglemask = 262080; // 0x111111111111000000: mask to obtain first 12 digits with position info
long statusmask = 63; // 0x000000000000111111; mask to obtain last 6 digits containing status info
long statusbits; // holds status/error information
int DECn; // bit holding decreasing magnet field error data
int INCn; // bit holding increasing magnet field error data
int OCF; // bit holding startup-valid bit
int COF; // bit holding cordic DSP processing error data
int LIN; // bit holding magnet field displacement error data
int debug = 1; // SET THIS TO 0 TO DISABLE PRINTING OF ERROR CODES

void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // visual signal of I/O to chip: heartbeat
pinMode(clockPin, OUTPUT); // SCK
pinMode(CSnPin, OUTPUT); // CSn -- has to toggle high and low to signal chip to start data transfer
pinMode(inputPin, INPUT); // SDA
}

void loop()
{
// CSn needs to cycle from high to low to initiate transfer. Then clock cycles. As it goes high
// again, data will appear on sda
digitalWrite(CSnPin, HIGH); // CSn high
digitalWrite(clockPin, HIGH); // CLK high
delay(1000); // wait for 1 second for no particular reason
digitalWrite(ledPin, HIGH); // signal start of transfer with LED
digitalWrite(CSnPin, LOW); // CSn low: start of transfer
delay(100); // delay for chip -- 1000x as long as it needs to be
digitalWrite(clockPin, LOW); // CLK goes low: start clocking
delay(10); // hold low for 10 ms
for (int x=0; x < 18; x++) // clock signal, 18 transitions, output to clock pin
{
digitalWrite(clockPin, HIGH); // clock goes high
delay(10); // wait 10ms
inputstream = digitalRead(inputPin); // read one bit of data from pin
//Serial.print(inputstream, DEC); // useful if you want to see the actual bits
packeddata = ((packeddata <<1>> 6); // shift 18-digit angle right 6 digits to form 12-digit value
//Serial.print("angleshft:");
//Serial.println(angle, BIN);
//Serial.print("angledec: ");
//Serial.println(angle, DEC);
angle = angle * 0.08789; // angle * (360/4096) == actual degrees
Serial.print("angle: "); // and, finally, print it.
Serial.println(angle, DEC);
//Serial.println("--------------------");
//Serial.print("raw: "); // this was the prefix for the bit-by-bit diag output inside the loop.
if (debug)
{
statusbits = packeddata & statusmask;
DECn = statusbits & 2; // goes high if magnet moved away from IC
INCn = statusbits & 4; // goes high if magnet moved towards IC
LIN = statusbits & 8; // goes high for linearity alarm
COF = statusbits & 16; // goes high for cordic overflow: data invalid
OCF = statusbits & 32; // this is 1 when the chip startup is finished.
if (DECn && INCn) { Serial.println("magnet moved out of range"); }
else
{
if (DECn) { Serial.println("magnet moved away from chip"); }
if (INCn) { Serial.println("magnet moved towards chip"); }
}
if (LIN) { Serial.println("linearity alarm: magnet misaligned? Data questionable."); }
if (COF) { Serial.println("cordic overflow: magnet misaligned? Data invalid."); }
}

packeddata = 0; // reset both variables to zero so they don't just accumulate
angle = 0;
}
I have found one code,but I don't think its for getting angle\position of DC motor.
Code: Select all
const int ledPin = 13; // LED connected to digital pin 13, used as a heartbeat
const int clockPin = 7; // output to clock
const int CSnPin = 6; // output to chip select
const int inputPin = 2; // read AS5045

int inputstream = 0; // one bit read from pin
long packeddata = 0; // two bytes concatenated from inputstream
long angle = 0; // holds processed angle value
long anglemask = 262080; // 0x111111111111000000: mask to obtain first 12 digits with position info
long statusmask = 63; // 0x000000000000111111; mask to obtain last 6 digits containing status info
long statusbits; // holds status/error information
int DECn; // bit holding decreasing magnet field error data
int INCn; // bit holding increasing magnet field error data
int OCF; // bit holding startup-valid bit
int COF; // bit holding cordic DSP processing error data
int LIN; // bit holding magnet field displacement error data
int debug = 1; // SET THIS TO 0 TO DISABLE PRINTING OF ERROR CODES

void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // visual signal of I/O to chip: heartbeat
pinMode(clockPin, OUTPUT); // SCK
pinMode(CSnPin, OUTPUT); // CSn -- has to toggle high and low to signal chip to start data transfer
pinMode(inputPin, INPUT); // SDA
}

void loop()
{
// CSn needs to cycle from high to low to initiate transfer. Then clock cycles. As it goes high
// again, data will appear on sda
digitalWrite(CSnPin, HIGH); // CSn high
digitalWrite(clockPin, HIGH); // CLK high
delay(1000); // wait for 1 second for no particular reason
digitalWrite(ledPin, HIGH); // signal start of transfer with LED
digitalWrite(CSnPin, LOW); // CSn low: start of transfer
delay(100); // delay for chip -- 1000x as long as it needs to be
digitalWrite(clockPin, LOW); // CLK goes low: start clocking
delay(10); // hold low for 10 ms
for (int x=0; x < 18; x++) // clock signal, 18 transitions, output to clock pin
{
digitalWrite(clockPin, HIGH); // clock goes high
delay(10); // wait 10ms
inputstream = digitalRead(inputPin); // read one bit of data from pin
//Serial.print(inputstream, DEC); // useful if you want to see the actual bits
packeddata = ((packeddata <<1>> 6); // shift 18-digit angle right 6 digits to form 12-digit value
//Serial.print("angleshft:");
//Serial.println(angle, BIN);
//Serial.print("angledec: ");
//Serial.println(angle, DEC);
angle = angle * 0.08789; // angle * (360/4096) == actual degrees
Serial.print("angle: "); // and, finally, print it.
Serial.println(angle, DEC);
//Serial.println("--------------------");
//Serial.print("raw: "); // this was the prefix for the bit-by-bit diag output inside the loop.
if (debug)
{
statusbits = packeddata & statusmask;
DECn = statusbits & 2; // goes high if magnet moved away from IC
INCn = statusbits & 4; // goes high if magnet moved towards IC
LIN = statusbits & 8; // goes high for linearity alarm
COF = statusbits & 16; // goes high for cordic overflow: data invalid
OCF = statusbits & 32; // this is 1 when the chip startup is finished.
if (DECn && INCn) { Serial.println("magnet moved out of range"); }
else
{
if (DECn) { Serial.println("magnet moved away from chip"); }
if (INCn) { Serial.println("magnet moved towards chip"); }
}
if (LIN) { Serial.println("linearity alarm: magnet misaligned? Data questionable."); }
if (COF) { Serial.println("cordic overflow: magnet misaligned? Data invalid."); }
}

packeddata = 0; // reset both variables to zero so they don't just accumulate
angle = 0;
}
MOHIT JINDAL offline
Savvy Roboteer
Savvy Roboteer
Posts: 178
Joined: Wed Nov 10, 2010 7:43 am


6 postsPage 1 of 1
6 postsPage 1 of 1