Dear members,
for a school project I have to implement a 10-bits magnetic encoder on a plant.
To explain the plant, I will give you a similar example: Arduino + Matlab: Controlador PID - test 1 - YouTube
I have to inplement PID controle with LabVIEW and an Arduino Uno..
Instead of the potentiometer to check the angle of the bar, and use PID depending on the angle, I now have to use a 10-bits magnetic encoder.
The following one: AEAT-6010-A06 10-bits Magnetic Encoder
Link tot the datasheet: http://www.avagotech.com/docs/AV02-0188EN
The AEAT-6010 magnetic angular based rotary detector uses a serial data stream and clock to be able to read out the absolute position in digital form.
The CLOCK and DATA signals are transmitted according RS-422 standards.
About the code:
As you can see in the characteristics in datasheet I have to "produce" a 10 times "HIGH" and "LOW" signal for the CLOCK.
I also have to watch the delay times which are given in the datasheet and making the Chip select and CLK high as given in the characteristics.
I have allready made the following code, but on the Serial Monitor I only get a "1" out..
My pin connection is the following one:
1: VDD (5V supply voltage): 5V power supply Arduino
2: CSn (Chip select): Digital output 4 Arduino
3: VSS (GND): GND Arduino
4: CLK (Serial clock-input): Digital output 7 Arduino
5: DO (Serial Data-Output): Digital output 8 Arduino
Does anyone has some experience with reading this kind of sensor into the Arduino?
I would appreciate your help a lot!
// Read in 10-bits Magnetic Encoder AEAT-6010-A06 into Arduino Uno
// RobinL
// Declarate
const int CSn = 4; // Chip select
const int CLK = 7; // Clock signal
const int DO = 8; // Digital Output from the encoder which delivers me a 0 or 1, depending on the bar angle..
unsigned int sensorWaarde = 0;
void setup(){
//Fix de tris
pinMode(CSn, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(DO, INPUT);
//Let's start here
digitalWrite(CLK, HIGH);
digitalWrite(CSn, HIGH);
}
void loop() {
sensorWaarde = readSensor();
delayMicroseconds(1); //Tcs waiting for another read in
}
unsigned int readSensor(){
unsigned int dataOut = 0;
digitalWrite(CSn, LOW);
delayMicroseconds(1); //Waiting for Tclkfe
//Passing 10 times, from 0 to 9
for(int x=0; x<10; x++){
digitalWrite(CLK, LOW);
delayMicroseconds(1); //Tclk/2
digitalWrite(CLK, HIGH);
delayMicroseconds(1); //Tdo valid, like Tclk/2
dataOut = (dataOut << 1) | digitalRead(DO); //shift all the entering data to the left and past the pin state to it. 1e bit is MSB
}
digitalWrite(CSn, HIGH); //
Serial.println(dataOut);
return dataOut;
}
Best regards,
RobinL