AprilDC
AprilDC

Reputation: 11

"Read Analog Voltage" sample rate

In this arduino example:

ReadAnalogVoltage

What would the samplerate be if I run it on a MEGA 2560? And what should I do to set the samplerate to 6kHz?

Thank you.

Upvotes: 0

Views: 57

Answers (1)

KIIV
KIIV

Reputation: 3739

In this case you should add delay(166), that would be something around 6.024Hz. But also floating point is super slow on Arduinos, so it might get slower than that. And also one millisecond in Arduino is not 1000us but 1024us, so it might be even less than 6Hz.

The best way is setting up one timer to auto trigger ADC and use ADIF (AD Interrupt Flag) to read value from ADC register pair, clear the flag, do the math and wait for another reading. But this is the hard way for a newbie.

Edit: For 6kHz it would be much more auto trigger mode and values in mV as an integer. Floating point arithmetics is extremely slow as it's just emulated by software.

Upvotes: 0

Related Questions