Shop OBEX P1 Docs P2 Docs Learn Events
ADC Buffering? — Parallax Forums

ADC Buffering?

PhilldapillPhilldapill Posts: 1,283
edited 2008-06-13 11:44 in Propeller 1
I'm making an object for an ADC. There will actually be two ADC's that will read two seperate voltages. The problem is that these readings fluctuate a good bit. I've tried nearly everything hardware side, so I need a software solution too. I'm thinking about making a dedicated cog to run the sampling of these two ADC's. Would it be a good idea to make a buffer of say, 100 longs, and take a sample, add it to the buffer, take another sample x amount of time later, add it, sample, etc. until the buffer is filled, then take the average of the buffer? This should give me a smoother reading, shouldn't it?

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-13 06:36
    Yes that will work. Another common way is to keep only 1 value. When you take a new sample. do the following
    value := (7*value + newsample)/8 or similar equation. It takes a few samples before the value evens out but its then a running average of the last 8 samples. You can increase the number of samples you average over but it then takes longer to react to changes.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-13 06:42
    I'm assuming with your way, you are trading reaction time for virtually no memory, compared to mine at least?

    By the way, I'd like to convert my code to assembly to boost the samples/sec. I have no experience with assembly and need someone that would code for hire.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-13 07:11
    Both ways have a time delay. When you average a buffer, a new different sample will only make a small change to the average, you will need several samples at the new value before it makes a difference to the average. A buffer of samples is used when you need to average over a time window e.g. average 1 second of samples. A running average can't give you that. If what you want is to average noise out then either will work.
  • evanhevanh Posts: 15,432
    edited 2008-06-13 09:33
    They can both be a sort of "running average". One form (Timmoore's recursive one) is the Infinite Impulse Response or IIR method which is basically an R-C filter and the other (Windowed average) is the Finite Impulse Response or FIR.

    A FIR filter is just an average that is applied with each and every new sample but still including a fixed number of previous samples. This is the rolling or running window.

    One more effect can be applied on top of that - each data point in the window can have it's own individual multipler. So, it's not just a bland divide by the number of data points. The standard average, ie: divide by number of data points, is also called a "flat" or "box" FIR filter.

    I imagine there has been topics in here covering this in the past ...


    Evan
  • evanhevanh Posts: 15,432
    edited 2008-06-13 11:44
    The way to make a digital filter really perform, I think, is to add dither in front of the ADC. Then you not only get the smoother result you also achieve higher precision. I have never tried this though, I presume it requires a carefully tuned and synchronised current source and sink to create an accurate dither pattern.

    It's prolly not unlike the sigma-delta process.


    Evan
Sign In or Register to comment.