I have an Arduino code which runs decently.
// Read in 10-bits Magnetic Encoder AEAT-6010-A06 into Arduino Uno
// Sampling
// 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..
int analogPin = 3;
int val = 0;
unsigned int sensorWaarde = 0;
void setup() {
Serial.begin(115200);
//Fix de tris
pinMode(CSn, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(DO, INPUT);
//Let's start here
digitalWrite(CLK, HIGH);
digitalWrite(CSn, HIGH);
}
void loop() {
val = analogRead(analogPin);
// val = val - 670;
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.print(dataOut);
Serial.print("");
Serial.print(" ");
Serial.println(val);
Serial.print(" ");
delay(2);
return dataOut;
}
From the delay data i assumed that i will be having approximately a sampling rate of 500 Hz, however it seems that the sampling rate is approximately 300+- Hz, without a proper confirmation.
My system is to be run in a Magnetic Encoder by Avago, but i have difficulties determining the sampling rate.
If possible, may i know what code should i use to indicate the time and sampling number?