My primary concerns are regarding the sampling speed of the ATMEGA328P
The ATmega328 can sample up to ~10ksps (kilo-samples-per-second) in normal configuration and at 10-bit ADC resolution, or reliably and with good (near 10-bit) resolution up to ~50ksps if you speed up the ADC clock. You can get even faster if you want to sacrifice a lot on sample resolution, but at faster speeds this processor is too slow to even reliably grab the data and transmit it or store it, so you should go to a much much beefier and better microcontroller, such as a 32-bit Arduino Zero, Portenta, or non-Arduino STM32 or something.
Example of speeding up the ATmega328 to sample up to ~50kHz:
See my library here, and my initial article on it here.
adc.setADCSpeed(ADC_FAST); // now analogRead() will operate up to ~50 kHz
// these readings can now be done up to ~50 kHz
uint16_t reading = analogRead(A3);
I don't remember the exact details of configuring the ADC clock, but it's all in the ATmega328 datasheet, and in my code--which you can study at the library link above, and you can look at Nick Gammon's website on it here: https://www.gammon.com.au/adc.
How fast do you need to sample? Only you can answer that question.
Perhaps you read some academic paper that says that vibrations of 102kHz on a 5cm diameter motor made of material X can cause microfractures in the material if exposed for 100 hours. Well, in this case, you need to sample at at least 204kHz (2x the frequency of interest) to see if 102kHz vibrations exist.
Or, perhaps you just want to use FFT to determine the RPMs of the motor since it will almost certainly have a dominating frequency at its rotational frequency due to imperfect balance of the motor. In that case, sampling at 2x the max RPM (but in samples per second, not minute) is sufficient. You stated a max rotational speed of 3000 RPM, so that's
3000 rot/min x 1 min/60 sec = 50 Hz. To detect your RPM, therefore, by sampling vibration, you need to sample at least 2x as fast as this, or 100 Hz or higher.
Remember, this is all Nyquist frequency stuff. All that the Nyquist frequency says is [in my own words]:
you can only detect a frequency up to 1/2 as high as your sampling rate
...or otherwise stated [in my own words]:
you must sample at 2x whatever frequency it is you are trying to measure
Any sample rate lower than this, and you get aliasing and it is mathematically and physically impossible to determine if a higher frequency exists. Any frequencies higher than 1/2x your sample rate which appear to exist in your FFT analysis must be thrown out, as they are invalid.
So, what max vibrational frequency do you need to measure? That's for you to find out. If you're looking to find gear tooth wear (ex: a broken, cracked, or missing gear tooth), you can come up with some estimations based on number of teeth per rotation, and knowing your motor's max rotational speed in rotations per second.
Example: assuming 32 teeth per revolution, you will be rotating at 3000 rot/min / 60 sec/min = 50 rot/sec x 32 teeth/rot = 1600 teeth/sec. But, to identify a broken tooth maybe you need to do a waveform analysis of the shape of the wave over that broken tooth, so you should sample at 5x to 10x that rate, or perhaps 1600 teeth/sec x 10 samples/tooth = 16000 samples/sec = 16 kSps. But...5 samples per tooth might be enough, or only 8 kSps...
See how some of this analysis might work? You have to figure out what it is you're trying to figure out, and sample accordingly. If you don't know what you're trying to figure out, just sample as fast as you can and then with that data try to see what you can figure out from what you just sampled! Such are the ways of engineering and curious minds! :)
With that being said, assuming you use my library's
adc.setADCSpeed(ADC_FAST); trick, you can sample 1 channel up to 50kHz or 3 channels up to 50/3 = ~16kHz, meaning the max vibrational frequency you can detect with FFT for 3 channels is ~8kHz with an ATmega328. Is that enough?
BUT, you will have jitter problems unless you put the ADC into continuous sample mode at a fixed interval, and you cannot sample all 3 channels at once, so there will naturally be an offset between them all, as they happen in sequence one after the other.
How fast can the ADXL335 sample? (ie: what's its "bandwidth", or frequency response?)
As for the ADXL335, its datasheet reveals it to be an analog 3-axis accelerometer, not a digital one, so you are limited by:
- how fast the ADC you have on your microcontroller can sample the sensor (we already came up with ~16khz (kSps)/channel, for 3 channels, above) and
- what the ADXL335's bandwidth, or max frequency response, is.
The datasheet (see image below) says you get a bandwidth of 0.5 Hz to 1600 Hz for the X and Y axes, and 0.5 Hz to 550 Hz for the Z axis, all depending on the chosen bypass capacitors, cx, cy, and cz you choose for it. See the image and highlighting below.
Bandwidth means simply [in my own words]:
Bandwidth is the maximum frequency at which a device can respond to changes in the thing is it measuring (ex: an accelerometer to changes in acceleration).
By definition, a bandwidth for a low-pass filter, or a sensor responding to a high-frequency input, is equal to the frequency at which point the measurement of the thing being measured is attenuated by 3 db, or in other words, is 1/sqrt(2) = 0.707 times as big as the actual thing being measured. So, if the bandwidth of an accelerometer is 50 Hz, then that means if it tries to measure a 50 Hz vibration, then the measurement it outputs at that frequency is attenuated to 0.707x as large as the actual amplitude of that vibration. Therefore, it is said that this sensor cannot be reliably used to measure higher frequencies than this. Note that since
Power = V^2/R, and the 0.707 rule applies to voltage, the attenuation is 0.707^2 = 0.5 for power.
If you bought your ADXL335 sensor from Adafruit here for $15 (https://www.adafruit.com/product/163), they state:
The XYZ filter capacitors are 0.1uF for a 50 Hz bandwidth
...which means they chose capacitors to give it a 50 Hz bandwidth, or frequency response. This means the sensor is limited to reliably measuring vibrations only up to 50Hz. You should sample at least 2x this bandwidth then in order to adequately capture frequencies up to that value, again, based on Nyquist. This means for this Adafruit version of the device and with these chosen bypass capacitors you can sample at 100 Hz or higher to detect vibrations up to 50 Hz (that's Hertz, not kiloHertz!). Even if you sample much much faster, the maximum reliable frequency this device can measure is only up to 50 Hz before attenuation of its measurements becomes a significant concern. Whether sampling at 100 Hz or 1000 Hz, the frequency this sensor can measure, in this configuration, is only up to 50 Hz, which is only 50/sec x 60sec/min = 3000 RPM if your goal is to just detect the rotational frequency, but not any higher-frequency vibrating modes, for your device.
A 50 Hz bandwidth (max frequency response), FYI, is optimized to reduce sample noise for handheld tilt-based game controllers, as it intentionally attenuates any frequencies above 50 Hz, and 50 Hz input from a human is a good expectation for human control signals. You might sample this sensor for such a game controller anywhere from 50 Hz to 1 KHz, but again, it can't detect vibrations any faster than about 50 Hz. So, the Adafruit version of the ADXL335 is optimized to be used to make home-made tilt-based hand controllers for games, toys, smart devices, radio control devices, etc.
Extra note on sampling frequency
Even though the Nyquist frequency says you only need to sample 2x the frequency of interest to detect the frequency of interest through FFT or similar, you need to realize that if you ever want to plot a given signal or inspect its shape or waveform, you should sample at least 5x to 10x as fast as the frequency of the signal you are trying to record and inspect.
This is how oscilloscopes are rated. A "100 Mhz" bandwidth oscilloscope will have a sample rate of at least 5x to 10x that, or 500 MSps (Mega-samples-per-second) to 1 GSps (Giga-samples-per-second). This makes sense because the purpose of an oscilloscope is to plot waveform shapes, and that requires at least 5 to 10 points per period, or 5x to 10x the sample rate of the rated bandwidth in order to display a reasonably-nice picture of the waveform.
For pure FFT or frequency analysis, where you just want to know the frequency of the thing being measured, but don't need to know how the waveform looks, a sample rate exactly 2x or higher than the frequency of the thing being measured is physically and mathematically sufficient.