Vertical spikes on ADC readings

Hi everyone :slight_smile:

I have been using fatlib v1 (since there is new fatlib v2 still under beta) library specifically AnalogBinLogger.
My settings were:

  • reading inputs from A0,A1,A2
  • sampling rate set to 500sps
  • adc_prescaler 7 , equivalent to 125kHz
  • I have connected AREF to 3.3V with setting ADC_REF - 0

Here is the code:

p/s: I cant preview the code because total characters exceeded 9k as allowed by this forum, hence I attach instead. Sorry.

Along with AnalogBinLogger.h

However, the result when I have converted to CSV produced some weird vertical lines.

What I have tested:

  • I have tested with an Arduino Uno board as well as another 3 Arduino Nano (as I thought at first my Arduino is broken. Pardon my extras to test to way more than I need).
  • I have tested changing to lower and higher sampling rate
  • I have tried to change the ADC clock to higher
  • I have also tested with plugging in A0 to the sensor, while A1 to 3.3V and A2 to GND

With all the changes, the spikes are still there.
I have read somewhere that the spikes are due to timer.

Can someone either:

  • Tell me what is the real problem (and perhaps way to mitigate this?)
  • Replicate this and confirm it is recurring problem, not just my hardware.

Anyway, I have tested the same configuration but with using SdFat beta library >> ExFatLogger.ino along with Arduino Due and the spikes are not there. Well, ARM-based and AVR-based, different architecture, hence I hypothesized that is the AVR problem.

Many thanks.

AnalogBinLogger.h (1.55 KB)

AnalogBinLogger.ino.ino (24.9 KB)

Hey even I am facing the same thing when I sense the voltages from the senors. Their can be many different reasons.

Is their any Power converter in the system?

SYRE-ERYS:
Here is the code:

p/s: I cant preview the code because total characters exceeded 9k as allowed by this forum, hence I attach instead. Sorry.

Then what you do is write a minimal sketch that shows the problem. No-one in their right mind is going to read through a 24 kB sketch without knowing exactly what to look for, or getting paid a significant hardship bonus. So in your case: a sketch that just reads the three inputs (that'd be three lines of code), plus whatever is needed to write out the data (to Serial console, SD card, or whatever is convenient).

Then looking at your image:


The first thing that I notice is "x-axis", "y-axis" and "z-axis". Are you by chance reading an accelerometer or so? Don't you think that the source of the signal may be a very good bit of information to include?

The next thing I noticed are the spikes. They come not only at seemingly regular intervals (some 60 counts on the x axis between each spike), they're also at the exact same moment in all three channels. That should tell you something. What happens every 1 minute in your system? In your home? To the table the project sits on?

chamarthi:
Is their any Power converter in the system?

A switching power supply is known to add noise, but it's typically somewhere between 50 kHz and 1 MHz: the switching frequency of the power supply. A frequency so high it doesn't usually mess much with ADC readings.

Okk.

I tried to control the Boost converter once. I was having the noise in my system.

Strange that the spikes seem to be equal positive and negative and equal on all 3 channels. That's not analog interference. That's something digital. I'm guessing something to do with the 512-byte block write. Maybe accessing the SD card is interfering with the interrupts?

What you are seeing is EMR, conducted or radiated or both, I do not know. I have no idea what your setup is so I can only make a few guesses however I am assuming all grounds are properly connected to a single point ground. Ground the scope probes to the arduino ground, then the power supply ground, and see how much noise you have, I have a feeling there will be a lot. This problem can be from your power supply, is it adequately filtered. 3 lead regulators can cause this type of pattern if not properly bypassed. I would not be surprised if the spikes were on the pins when your code is not running. Try this with the blink sketch. This should get you started, remember the wider the scope bandwidth the more you see. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

Almost certainly disturbance on the supply (perhaps from writing a block to the SDcard - that's a high current operation, as the flash memory has to be erased and then overwritten using the SDcards internal programming circuitry at full power.)

Perhaps you are inadvertently sharing power or ground wiring between sensor and SDcard? The pulse current draw from the SDcard could be dropping out the voltage at the sensor - perhaps some substantial extra decoupling on the sensor supply might help (100µF or more).

The best way to suppress spike noise from a power source is to add a simple median filter.

uint16_t getMedian(void)
{
  uint16_t data[3] = {0, 0, 0};
  uint16_t middle  = 0;
  
  for (int8_t i = 0; i < 3; i++)
  {
    data[i] = analogRead(A0); 
  }

  if ((data[0] <= data[1]) && (data[0] <= data[2]))
  {
    middle = (data[1] <= data[2]) ? data[1] : data[2];
  }
  else if ((data[1] <= data[0]) && (data[1] <= data[2]))
  {
    middle = (data[0] <= data[2]) ? data[0] : data[2];
  }
  else
  {
    middle = (data[0] <= data[1]) ? data[0] : data[1];
  }

  return middle;

This is a new one for me what is a simple median filter?

Median means "middle". If you have 5 readings 10, 10, 11, 15, 220 then the median is 11.

The average of those 5 readings is much higher because of the one reading of 220. But you can see that the "normal" readings are all much closer to 11.

Thank you MorganS.

gilshultz, did you try to use google? The first link in the search leads to the answer.