Shop OBEX P1 Docs P2 Docs Learn Events
Using a FIFO register to stable my incoming ADC values — Parallax Forums

Using a FIFO register to stable my incoming ADC values

ArchiverArchiver Posts: 46,084
edited 2004-07-15 20:32 in General Discussion
Hi stampworkers,

I'm reading in an 4-20mA pressure sensor with an LTC1298. This works
very good but my values keep changing a little bit and I want to
make them as stable as I can so I thought an FIFO register software
loop would do the trick. My idea is to create an 10 adress FIFO
register, to make the sum of the 10 values en the devide it by 10 so
I get an average value of the reading wich will be stable
(hopefully). I searched a lot in nuts & volts and in my printed
manuals but didn't found a proper article about creating such
register. Do I need some kind of IC to make my idea work or could i
do this by inserting some program text? Could anyone help me with me
very enoying problem?


Greetings,

Tim (happy but not satisfied)

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-07-14 16:20
    If I understand your question, you really want a rolling average. That is at
    T10 you want to average samples T1 to T10 and at T11 you want T2 to T11, is
    that right?

    In theory, this is easy enough, but there are some caveats. The easy thing
    to do is create an array of 10 items and keep a "pointer" to the current
    entry. So putting an entry in this list would be something like:

    List(current)=value
    current=current+1
    if current>9 then current=0


    But there are a few problems. First, the LTC1298 is 12 bit. So you'd need 10
    words or 20 bytes for the list, and an extra nibble for the pointer. That
    leaves less than 6 bytes for other things. In addition, consider this
    averaging code:

    V=0
    For I=0 to 9
    V=V+List(I)
    Next
    V=V/10

    Of course, this uses more variables. But worse still is that at the worst
    case, List(I) could be $FFF (say 4000 for round numbers) and you are
    multiplying by 10 which would be 40000. That's less than 65535 so you should
    be OK there. But if the values were possibly larger, or you tried to
    increase the number of samples (doubtful with limited memory) you'd overflow
    the Stamp.

    Answers? You could use a BS2/P's scratch pad memory for the list. You could
    reduce the number of samples in the average. You could go with a "spot"
    average:

    V=0
    For I=1 to 10
    V=V+Input_Value_From_LTC
    Next
    V=V/10

    Next time you just read 10 more values.

    Another approach is to oversample. If you decide you only need, say, 8 bits
    of resolution, you can simply round the 12 bits to 8 by shifting and taking
    the last shifted bit into account for rounding:

    V8=v12>>4 + v12.bit3

    You could probably use a PAK-II to do the average, by storing the list in
    the PAKs memory. This would also give you a floating point number and a way
    to convert to engineering units. Or use a PAK-IX or PAK-XII to do the A/D.
    These are only 10 bit, but averaging adds bits in the presence of random
    noise. Both chips do floating point and can average samples right out of the
    box (spot average, though -- you'd have to do your own rolling averages).
    See http://www.awce.com/pak12.htm or http://www.awce.com/pak9.htm (or
    http://www.awce.com/pak1.htm if you don't want the A/D onboard).

    A better approach might be to identify the noise in your system and reduce
    it first. Keep in mind that 12 bits at 5V is about one and quarter
    millivolts per step. That's not a lot of voltage. Decoupling, ground design,
    etc. get very important when you are trying to measure things down to the
    millivolt. If you put a scope on AC coupling and turn the vertical gain up
    high, you'll see that most DC sources have a few millivolts of up and down
    riding on them -- many quite a few millivolts!

    Hope that helps.

    Al Williams
    AWC
    * 8 Channels of PWM from your Stamp
    http://www.awce.com/pak5.htm



    Original Message
    From: ikenniemandanders [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=LNRiw3SEt3T0t6XOR4C7C2A3QMib41gSkp31CoKN1fU-zOrHmFXxMJhMuUYh7oZ_21VFA70KUYORHg]tld-nv@s...[/url
    Sent: Wednesday, July 14, 2004 9:34 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming ADC
    values


    Hi stampworkers,

    I'm reading in an 4-20mA pressure sensor with an LTC1298. This works
    very good but my values keep changing a little bit and I want to
    make them as stable as I can so I thought an FIFO register software
    loop would do the trick. My idea is to create an 10 adress FIFO
    register, to make the sum of the 10 values en the devide it by 10 so
    I get an average value of the reading wich will be stable
    (hopefully). I searched a lot in nuts & volts and in my printed
    manuals but didn't found a proper article about creating such
    register. Do I need some kind of IC to make my idea work or could i
    do this by inserting some program text? Could anyone help me with me
    very enoying problem?


    Greetings,

    Tim (happy but not satisfied)



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-14 17:07
    --- In basicstamps@yahoogroups.com, "ikenniemandanders" <tld-nv@s...>
    wrote:
    > Hi stampworkers,
    >
    > I'm reading in an 4-20mA pressure sensor with an LTC1298. This
    works
    > very good but my values keep changing a little bit and I want to
    > make them as stable as I can so I thought an FIFO register software
    > loop would do the trick. My idea is to create an 10 adress FIFO
    > register, to make the sum of the 10 values en the devide it by 10
    so
    > I get an average value of the reading wich will be stable
    > (hopefully). I searched a lot in nuts & volts and in my printed
    > manuals but didn't found a proper article about creating such
    > register. Do I need some kind of IC to make my idea work or could i
    > do this by inserting some program text? Could anyone help me with
    me
    > very enoying problem?
    >
    >
    > Greetings,
    >
    > Tim (happy but not satisfied)



    Hi Tim,

    If you use a spreadsheet, try to enter a few hundred points of raw
    data to experiment with.

    I use a 10 point filter that adds a new reading, averages the
    readings and then deletes the average.

    The can take 150 readings to resolve a full scale shift, but one
    question is how fast you take readings.

    One problem is adding up large values and memory use.

    but I read one point, add it to my old running total, then divide by
    10 to get the average. that average is then sent to the porgram for
    use or readout.

    that avearage is also subtracted from the running total to keep the
    running total something close to the value of the last 10 points.

    I don't have a 2,000 point data stream to play with on my
    spreadsheet, but I'll put it on my to-do list (around page 75 ?)

    The way you are talking about a FIFO buffer I did the long way.

    X10=X9
    X9=X8
    X8=X7
    X7=X6
    X6=X5
    X5=X4
    X4=X3
    X3=X2
    X2=X1
    X1=new adc input

    The old value of X10 would be lost and replaced with X9 and so on.
    X1 would get the new data.

    But, as anyone will tell you, averaging your data in some hardware
    filter (butteworth, or op-amp or RC or something) will go a long way
    to get better input readings.

    Dave
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-14 17:33
    Another possibility is a software lowpass filter. Example:

    ' from http://owlogic.com/BS2math5.htm#Smoothing
    X var word ' current noisy value, filter input 0<=X<4096
    Y var word ' accumulator
    Z var word ' smoothed filter output

    inititalize:
    gosub getX ' get current value, not shown, X<4096
    Y=X*16 'initialize, note multiplication *16

    main:
    gosub getX ' get current value, not shown, X<4096
    Y = Y ** 61441 + X ' smoothing function
    Z = Y/16
    debug dec X, tab,dec Z, CR ' show values
    goto main


    Basically each new sample contributes a weight of 1/16 to the pool of
    past samples. The article shows other weightings too.

    It is possible to implement the kind of windowed or boxcar average
    that you describe. However, as Al pointed out, you would need more
    RAM memory, available in the scratchpad memory of the multibank
    Stamps, to implement that.

    -- Tracy



    >Hi stampworkers,
    >
    >I'm reading in an 4-20mA pressure sensor with an LTC1298. This works
    >very good but my values keep changing a little bit and I want to
    >make them as stable as I can so I thought an FIFO register software
    >loop would do the trick. My idea is to create an 10 adress FIFO
    >register, to make the sum of the 10 values en the devide it by 10 so
    >I get an average value of the reading wich will be stable
    >(hopefully). I searched a lot in nuts & volts and in my printed
    >manuals but didn't found a proper article about creating such
    >register. Do I need some kind of IC to make my idea work or could i
    >do this by inserting some program text? Could anyone help me with me
    >very enoying problem?
    >
    >
    >Greetings,
    >
    >Tim (happy but not satisfied)

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-15 18:56
    I use this technique with a 12-bit ADC. Division is simplified if you
    use a power of 2, so I use a rolling average of n=16. With Al's
    example, 16 * 4000 = 64000, so this is still within a 2-byte boundary (<
    65535). Code is also simplified if you add the first 16 values and
    store it in a 2-byte buffer, and then recursivly add the 17th, subtract
    the first, divide by 16, send the result to a PC, and continue this
    logic forever. The main message is that you never have to actually
    store all 16 values, just the cumulative buffer.

    Remember that a rolling average is a low-pass filter, with filter cutoff
    determined by the sampling rate and n.

    Dennis

    Original Message
    From: Al Williams [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=t_WPY41A8OMG1GnOt71tHHwDmr9p-Tsys1mETAPfmzBT1pcY-mKF_-fTuUwhTAhxhpCKCzfRn8Jb]alw@a...[/url
    Sent: Wednesday, July 14, 2004 8:21 AM
    To: basicstamps@yahoogroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming
    ADC values


    If I understand your question, you really want a rolling average. That
    is at T10 you want to average samples T1 to T10 and at T11 you want T2
    to T11, is that right?

    In theory, this is easy enough, but there are some caveats. The easy
    thing to do is create an array of 10 items and keep a "pointer" to the
    current entry. So putting an entry in this list would be something like:

    List(current)=value
    current=current+1
    if current>9 then current=0


    But there are a few problems. First, the LTC1298 is 12 bit. So you'd
    need 10 words or 20 bytes for the list, and an extra nibble for the
    pointer. That leaves less than 6 bytes for other things. In addition,
    consider this averaging code:

    V=0
    For I=0 to 9
    V=V+List(I)
    Next
    V=V/10

    Of course, this uses more variables. But worse still is that at the
    worst case, List(I) could be $FFF (say 4000 for round numbers) and you
    are multiplying by 10 which would be 40000. That's less than 65535 so
    you should be OK there. But if the values were possibly larger, or you
    tried to increase the number of samples (doubtful with limited memory)
    you'd overflow the Stamp.

    Answers? You could use a BS2/P's scratch pad memory for the list. You
    could reduce the number of samples in the average. You could go with a
    "spot"
    average:

    V=0
    For I=1 to 10
    V=V+Input_Value_From_LTC
    Next
    V=V/10

    Next time you just read 10 more values.

    Another approach is to oversample. If you decide you only need, say, 8
    bits of resolution, you can simply round the 12 bits to 8 by shifting
    and taking the last shifted bit into account for rounding:

    V8=v12>>4 + v12.bit3

    You could probably use a PAK-II to do the average, by storing the list
    in the PAKs memory. This would also give you a floating point number and
    a way to convert to engineering units. Or use a PAK-IX or PAK-XII to do
    the A/D. These are only 10 bit, but averaging adds bits in the presence
    of random noise. Both chips do floating point and can average samples
    right out of the box (spot average, though -- you'd have to do your own
    rolling averages). See http://www.awce.com/pak12.htm or
    http://www.awce.com/pak9.htm (or http://www.awce.com/pak1.htm if you
    don't want the A/D onboard).

    A better approach might be to identify the noise in your system and
    reduce it first. Keep in mind that 12 bits at 5V is about one and
    quarter millivolts per step. That's not a lot of voltage. Decoupling,
    ground design, etc. get very important when you are trying to measure
    things down to the millivolt. If you put a scope on AC coupling and turn
    the vertical gain up high, you'll see that most DC sources have a few
    millivolts of up and down riding on them -- many quite a few millivolts!

    Hope that helps.

    Al Williams
    AWC
    * 8 Channels of PWM from your Stamp http://www.awce.com/pak5.htm



    Original Message
    From: ikenniemandanders [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=DySVav7KPI9Wt_m0cHfnHMHTLEsoUWV0geuHbb9zEtQdjNP7yRqZM2oI64pRmR90CXGP3OH_r_RzkXg]tld-nv@s...[/url
    Sent: Wednesday, July 14, 2004 9:34 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming ADC
    values


    Hi stampworkers,

    I'm reading in an 4-20mA pressure sensor with an LTC1298. This works
    very good but my values keep changing a little bit and I want to
    make them as stable as I can so I thought an FIFO register software
    loop would do the trick. My idea is to create an 10 adress FIFO
    register, to make the sum of the 10 values en the devide it by 10 so
    I get an average value of the reading wich will be stable
    (hopefully). I searched a lot in nuts & volts and in my printed
    manuals but didn't found a proper article about creating such
    register. Do I need some kind of IC to make my idea work or could i
    do this by inserting some program text? Could anyone help me with me
    very enoying problem?


    Greetings,

    Tim (happy but not satisfied)



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.

    Yahoo! Groups Links









    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.

    Yahoo! Groups Links
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-15 19:03
    Agreed, this is computationally simpler, but to compute:

    S(i+1)=S(i)+V(i+1)-V(i-16) { or whatever }

    You still have to store V(0) to V(15) so that you can supply the V(i-16)
    part. Or did I misunderstand you?

    Regards,

    Al Williams
    AWC
    * NEW: I2C PC Interface
    http://www.awce.com/gp7.htm




    Original Message
    From: Dennis O'Leary [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=e4Ky0kPY_Uy_1NItdHZQWbmXvcEsjRz8Q-IsNk-i8wtom0nGRORYtqsdQvcWeYHmrxM4GYXN-5xTG8Im]doleary@e...[/url
    Sent: Thursday, July 15, 2004 12:57 PM
    To: basicstamps@yahoogroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming ADC
    values


    I use this technique with a 12-bit ADC. Division is simplified if you use a
    power of 2, so I use a rolling average of n=16. With Al's example, 16 *
    4000 = 64000, so this is still within a 2-byte boundary (< 65535). Code is
    also simplified if you add the first 16 values and store it in a 2-byte
    buffer, and then recursivly add the 17th, subtract the first, divide by 16,
    send the result to a PC, and continue this logic forever. The main message
    is that you never have to actually store all 16 values, just the cumulative
    buffer.

    Remember that a rolling average is a low-pass filter, with filter cutoff
    determined by the sampling rate and n.

    Dennis

    Original Message
    From: Al Williams [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=qe7hKIJvjItjjy-4WpCmzTNHHt9seRTJbbZy37fs5RNvVCJfJPBy51ANbKgd5ezyx5Ylt0lt4HEoJ9g]alw@a...[/url
    Sent: Wednesday, July 14, 2004 8:21 AM
    To: basicstamps@yahoogroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming ADC
    values


    If I understand your question, you really want a rolling average. That is at
    T10 you want to average samples T1 to T10 and at T11 you want T2 to T11, is
    that right?

    In theory, this is easy enough, but there are some caveats. The easy thing
    to do is create an array of 10 items and keep a "pointer" to the current
    entry. So putting an entry in this list would be something like:

    List(current)=value
    current=current+1
    if current>9 then current=0


    But there are a few problems. First, the LTC1298 is 12 bit. So you'd need 10
    words or 20 bytes for the list, and an extra nibble for the pointer. That
    leaves less than 6 bytes for other things. In addition, consider this
    averaging code:

    V=0
    For I=0 to 9
    V=V+List(I)
    Next
    V=V/10

    Of course, this uses more variables. But worse still is that at the worst
    case, List(I) could be $FFF (say 4000 for round numbers) and you are
    multiplying by 10 which would be 40000. That's less than 65535 so you should
    be OK there. But if the values were possibly larger, or you tried to
    increase the number of samples (doubtful with limited memory) you'd overflow
    the Stamp.

    Answers? You could use a BS2/P's scratch pad memory for the list. You could
    reduce the number of samples in the average. You could go with a "spot"
    average:

    V=0
    For I=1 to 10
    V=V+Input_Value_From_LTC
    Next
    V=V/10

    Next time you just read 10 more values.

    Another approach is to oversample. If you decide you only need, say, 8 bits
    of resolution, you can simply round the 12 bits to 8 by shifting and taking
    the last shifted bit into account for rounding:

    V8=v12>>4 + v12.bit3

    You could probably use a PAK-II to do the average, by storing the list in
    the PAKs memory. This would also give you a floating point number and a way
    to convert to engineering units. Or use a PAK-IX or PAK-XII to do the A/D.
    These are only 10 bit, but averaging adds bits in the presence of random
    noise. Both chips do floating point and can average samples right out of the
    box (spot average, though -- you'd have to do your own rolling averages).
    See http://www.awce.com/pak12.htm or http://www.awce.com/pak9.htm (or
    http://www.awce.com/pak1.htm if you don't want the A/D onboard).

    A better approach might be to identify the noise in your system and reduce
    it first. Keep in mind that 12 bits at 5V is about one and quarter
    millivolts per step. That's not a lot of voltage. Decoupling, ground design,
    etc. get very important when you are trying to measure things down to the
    millivolt. If you put a scope on AC coupling and turn the vertical gain up
    high, you'll see that most DC sources have a few millivolts of up and down
    riding on them -- many quite a few millivolts!

    Hope that helps.

    Al Williams
    AWC
    * 8 Channels of PWM from your Stamp http://www.awce.com/pak5.htm



    Original Message
    From: ikenniemandanders [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=N4Qp2UJwTkbsMUjQtw-CtR_yMLFBZjDoOMbbcDHCIBjGAULG8FqUwMJb1UA5Ur4FW00ZmeNv]tld-nv@s...[/url
    Sent: Wednesday, July 14, 2004 9:34 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming ADC
    values


    Hi stampworkers,

    I'm reading in an 4-20mA pressure sensor with an LTC1298. This works
    very good but my values keep changing a little bit and I want to
    make them as stable as I can so I thought an FIFO register software
    loop would do the trick. My idea is to create an 10 adress FIFO
    register, to make the sum of the 10 values en the devide it by 10 so
    I get an average value of the reading wich will be stable
    (hopefully). I searched a lot in nuts & volts and in my printed
    manuals but didn't found a proper article about creating such
    register. Do I need some kind of IC to make my idea work or could i
    do this by inserting some program text? Could anyone help me with me
    very enoying problem?


    Greetings,

    Tim (happy but not satisfied)



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links









    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links









    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-15 20:32
    Yes, that is correct. For novices (that's not you, Al), it is useful to
    note that dividing by 16 is done by right shifting bits 4 places.

    Regards,
    Dennis
    WSR, Inc.
    www.4wsr.com

    Original Message
    From: Al Williams [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=SFFQ-j-ndEGVQ7oKGQA0bmIOgxFQ16LfzpFYOuvKZpytbwMw9aosq1ma0sJivZ2tmyCj_dukJyN2ow]alw@a...[/url
    Sent: Thursday, July 15, 2004 11:03 AM
    To: basicstamps@yahoogroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming
    ADC values


    Agreed, this is computationally simpler, but to compute:

    S(i+1)=S(i)+V(i+1)-V(i-16) { or whatever }

    You still have to store V(0) to V(15) so that you can supply the V(i-16)
    part. Or did I misunderstand you?

    Regards,

    Al Williams
    AWC
    * NEW: I2C PC Interface
    http://www.awce.com/gp7.htm




    Original Message
    From: Dennis O'Leary [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=1D06w-Z_t8XQ0nxkYrHeOOo6fG_OPkR4ThJvHF6CTKFThyLtffRvncAu5S6yTbaL-dnukL5qfPmS-ZV9xPuh]doleary@e...[/url
    Sent: Thursday, July 15, 2004 12:57 PM
    To: basicstamps@yahoogroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming
    ADC values


    I use this technique with a 12-bit ADC. Division is simplified if you
    use a power of 2, so I use a rolling average of n=16. With Al's
    example, 16 * 4000 = 64000, so this is still within a 2-byte boundary (<
    65535). Code is also simplified if you add the first 16 values and
    store it in a 2-byte buffer, and then recursivly add the 17th, subtract
    the first, divide by 16, send the result to a PC, and continue this
    logic forever. The main message is that you never have to actually
    store all 16 values, just the cumulative buffer.

    Remember that a rolling average is a low-pass filter, with filter cutoff
    determined by the sampling rate and n.

    Dennis

    Original Message
    From: Al Williams [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=SFFQ-j-ndEGVQ7oKGQA0bmIOgxFQ16LfzpFYOuvKZpytbwMw9aosq1ma0sJivZ2tmyCj_dukJyN2ow]alw@a...[/url
    Sent: Wednesday, July 14, 2004 8:21 AM
    To: basicstamps@yahoogroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming
    ADC values


    If I understand your question, you really want a rolling average. That
    is at T10 you want to average samples T1 to T10 and at T11 you want T2
    to T11, is that right?

    In theory, this is easy enough, but there are some caveats. The easy
    thing to do is create an array of 10 items and keep a "pointer" to the
    current entry. So putting an entry in this list would be something like:

    List(current)=value
    current=current+1
    if current>9 then current=0


    But there are a few problems. First, the LTC1298 is 12 bit. So you'd
    need 10 words or 20 bytes for the list, and an extra nibble for the
    pointer. That leaves less than 6 bytes for other things. In addition,
    consider this averaging code:

    V=0
    For I=0 to 9
    V=V+List(I)
    Next
    V=V/10

    Of course, this uses more variables. But worse still is that at the
    worst case, List(I) could be $FFF (say 4000 for round numbers) and you
    are multiplying by 10 which would be 40000. That's less than 65535 so
    you should be OK there. But if the values were possibly larger, or you
    tried to increase the number of samples (doubtful with limited memory)
    you'd overflow the Stamp.

    Answers? You could use a BS2/P's scratch pad memory for the list. You
    could reduce the number of samples in the average. You could go with a
    "spot"
    average:

    V=0
    For I=1 to 10
    V=V+Input_Value_From_LTC
    Next
    V=V/10

    Next time you just read 10 more values.

    Another approach is to oversample. If you decide you only need, say, 8
    bits of resolution, you can simply round the 12 bits to 8 by shifting
    and taking the last shifted bit into account for rounding:

    V8=v12>>4 + v12.bit3

    You could probably use a PAK-II to do the average, by storing the list
    in the PAKs memory. This would also give you a floating point number and
    a way to convert to engineering units. Or use a PAK-IX or PAK-XII to do
    the A/D. These are only 10 bit, but averaging adds bits in the presence
    of random noise. Both chips do floating point and can average samples
    right out of the box (spot average, though -- you'd have to do your own
    rolling averages). See http://www.awce.com/pak12.htm or
    http://www.awce.com/pak9.htm (or http://www.awce.com/pak1.htm if you
    don't want the A/D onboard).

    A better approach might be to identify the noise in your system and
    reduce it first. Keep in mind that 12 bits at 5V is about one and
    quarter millivolts per step. That's not a lot of voltage. Decoupling,
    ground design, etc. get very important when you are trying to measure
    things down to the millivolt. If you put a scope on AC coupling and turn
    the vertical gain up high, you'll see that most DC sources have a few
    millivolts of up and down riding on them -- many quite a few millivolts!

    Hope that helps.

    Al Williams
    AWC
    * 8 Channels of PWM from your Stamp http://www.awce.com/pak5.htm



    Original Message
    From: ikenniemandanders [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=TP4qp1PUSp6-iAwXKQqLzXpCWy6IAWKQYVwZhg727eOetvi4KJ9lDC9w2h_AXeyBOuXfzDvNig_uzNg]tld-nv@s...[/url
    Sent: Wednesday, July 14, 2004 9:34 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Using a FIFO register to stable my incoming ADC
    values


    Hi stampworkers,

    I'm reading in an 4-20mA pressure sensor with an LTC1298. This works
    very good but my values keep changing a little bit and I want to
    make them as stable as I can so I thought an FIFO register software
    loop would do the trick. My idea is to create an 10 adress FIFO
    register, to make the sum of the 10 values en the devide it by 10 so
    I get an average value of the reading wich will be stable
    (hopefully). I searched a lot in nuts & volts and in my printed
    manuals but didn't found a proper article about creating such
    register. Do I need some kind of IC to make my idea work or could i
    do this by inserting some program text? Could anyone help me with me
    very enoying problem?


    Greetings,

    Tim (happy but not satisfied)



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.

    Yahoo! Groups Links









    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.

    Yahoo! Groups Links









    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.

    Yahoo! Groups Links









    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.

    Yahoo! Groups Links
Sign In or Register to comment.