user13259: 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?

user10794: At 115200 baud your serial prints will take 1/11520 seconds per byte.

Serial.print("");

What does that do?

I count 14 bytes here:
  Serial.print(dataOut);  // 5 bytes, say
  Serial.print("");       // zero bytes, lol
  Serial.print(" ");      // one byte
  Serial.println(val);    // 5 bytes + cr/lf = 7 bytes
  Serial.print(" ");      // 1 byte

Multiply 1/11520 (0.0000868) by 14 and you get 1215 µs.

Now add in your delays: 
  delay(2);  // 2000 µs


And this:
 for (int x = 0; x < 10; x++) {
    ...
    delayMicroseconds(1); //Tclk/2
    ...
    delayMicroseconds(1); //Tdo valid, like Tclk/2
  }

Another 20 µs.

  val = analogRead(analogPin);   // 104 µs
  ...
  delayMicroseconds(1); // 1 µs


Total:
1215 + 2000 + 20 + 104 + 1 = 3340 µs

Inverse:
1 / 0.003340 = 299


So yes, I would expect around 299 iterations per second. That isn't counting the time for the other code to execute.

Suggestions

Get rid of the serial prints
Get rid of delay(2)


13259: <p>I have an Arduino code which runs decently.</p>

<pre><code>// 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 &lt; 10; x++) {
    digitalWrite(CLK, LOW);
    delayMicroseconds(1); //Tclk/2
    digitalWrite(CLK, HIGH);
    delayMicroseconds(1); //Tdo valid, like Tclk/2
    dataOut = (dataOut &lt;&lt; 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;

}
</code></pre>

<p>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.</p>

<p>My system is to be run in a Magnetic Encoder by Avago, but i have difficulties determining the sampling rate.</p>

<p>If possible, may i know what code should i use to indicate the time and sampling number?</p>
 10794: 

<p>At 115200 baud your serial prints will take 1/11520 seconds per byte.</p>

<hr>

<pre class="lang-C++ prettyprint-override"><code>Serial.print("");
</code></pre>

<p>What does that do?</p>

<hr>

<p>I count 14 bytes here:</p>

<pre class="lang-C++ prettyprint-override"><code>  Serial.print(dataOut);  // 5 bytes, say
  Serial.print("");       // zero bytes, lol
  Serial.print(" ");      // one byte
  Serial.println(val);    // 5 bytes + cr/lf = 7 bytes
  Serial.print(" ");      // 1 byte
</code></pre>

<p>Multiply 1/11520 (0.0000868) by 14 and you get 1215 µs.</p>

<hr>

<p>Now add in your delays: </p>

<pre class="lang-C++ prettyprint-override"><code>  delay(2);  // 2000 µs
</code></pre>

<hr>

<p>And this:</p>

<pre class="lang-C++ prettyprint-override"><code> for (int x = 0; x &lt; 10; x++) {
    ...
    delayMicroseconds(1); //Tclk/2
    ...
    delayMicroseconds(1); //Tdo valid, like Tclk/2
  }
</code></pre>

<p>Another 20 µs.</p>

<hr>

<pre class="lang-C++ prettyprint-override"><code>  val = analogRead(analogPin);   // 104 µs
  ...
  delayMicroseconds(1); // 1 µs
</code></pre>

<hr>

<p>Total:</p>

<pre class="lang-C++ prettyprint-override"><code>1215 + 2000 + 20 + 104 + 1 = 3340 µs
</code></pre>

<p>Inverse:</p>

<pre class="lang-C++ prettyprint-override"><code>1 / 0.003340 = 299
</code></pre>

<hr>

<p>So yes, I would expect around 299 iterations per second. That isn't counting the time for the other code to execute.</p>

<hr>

<h3>Suggestions</h3>

<ul>
<li>Get rid of the serial prints</li>
<li>Get rid of <code>delay(2)</code></li>
</ul>
