Shop OBEX P1 Docs P2 Docs Learn Events
Averaging numbers over a long time — Parallax Forums

Averaging numbers over a long time

ArchiverArchiver Posts: 46,084
edited 2004-05-05 08:17 in General Discussion
In a message dated 5/4/2004 12:52:18 PM Eastern Daylight Time,
laurasdog@w... writes:


> I am trying to gather power data from a small wind generator.
> Voltage and current are sampled aprox twice per second
> with a 12-bit ADC and data is fed to a BS2.
> Numbers are crunched and instantaneous and peak
> voltage, current, and power are displayed on an LCD display.
> There is no real time clock, so the number of samples
> in a day is only approximately known
>

One of the problems here is that if you continually sum the satts, it won't
be long before you reach 65535 and roll over, thus losing your total. I have a
scheme I am using in a data logger that might help if you care to contact me
off line. I'm not guaranteeing a solution, only a bit of help.

Sid Weaver
256K of plugin EEPROM................
http://www.visualmuses.com/chipcircuit/index.html





[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-05-04 17:50
    Greetings group,

    I am trying to gather power data from a small wind generator.
    Voltage and current are sampled aprox twice per second
    with a 12-bit ADC and data is fed to a BS2.
    Numbers are crunched and instantaneous and peak
    voltage, current, and power are displayed on an LCD display.
    There is no real time clock, so the number of samples
    in a day is only approximately known

    The problem I'm having is with the "average watts" portion of it.
    I need to average the watts over time (possibly as long
    as a month) and keep a running *average* (not total) on the
    watts produced. The peak watts at any time could go as
    high as 700. (but anything over 500 is pretty scary!)
    Output could also be zero for hours or days at a time.

    I seem to be having trouble finding a solution to this without
    using up a ton of memory space. Wish I'd paid more
    attention in math class all those years ago...

    Could anyone help get me started in the right direction?

    Thanks much,
    Steve
    ===The computer this message====
    ===was sent from runs exclusively==
    ===on renewable energy sources===


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-04 18:31
    >
    > > I am trying to gather power data from a small wind generator.
    > > Voltage and current are sampled aprox twice per second
    > > with a 12-bit ADC and data is fed to a BS2.
    > > Numbers are crunched and instantaneous and peak
    > > voltage, current, and power are displayed on an LCD display.
    > > There is no real time clock, so the number of samples
    > > in a day is only approximately known
    > >
    >
    >One of the problems here is that if you continually sum the satts, it won't
    >be long before you reach 65535 and roll over, thus losing your total. I
    >have a
    >scheme I am using in a data logger that might help if you care to contact me
    >off line. I'm not guaranteeing a solution, only a bit of help.
    >
    >Sid Weaver

    Thanks Sid,
    I was hoping there might be some sort of slick way to "average as you go".
    Perhaps save samples until you get close to the 65K limit, then average.
    Save that number and grab the next load of samples and average those..
    or something like that. The *average* is unlikely to exceed a few hundred
    watts. I suppose I could add more memory, but due to bad planning I'm
    just about out of I/O and 3 more lines would be tough to come up with...

    Steve
    ===The computer this message====
    ===was sent from runs exclusively==
    ===on renewable energy sources===


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-04 18:42
    --- In basicstamps@yahoogroups.com, laurasdog@w... wrote:
    > Greetings group,
    >
    > I am trying to gather power data from a small wind generator.
    > Voltage and current are sampled aprox twice per second
    > with a 12-bit ADC and data is fed to a BS2.
    > Numbers are crunched and instantaneous and peak
    > voltage, current, and power are displayed on an LCD display.
    > There is no real time clock, so the number of samples
    > in a day is only approximately known
    >
    > The problem I'm having is with the "average watts" portion of it.
    > I need to average the watts over time (possibly as long
    > as a month) and keep a running *average* (not total) on the
    > watts produced. The peak watts at any time could go as
    > high as 700. (but anything over 500 is pretty scary!)
    > Output could also be zero for hours or days at a time.
    >
    > I seem to be having trouble finding a solution to this without
    > using up a ton of memory space. Wish I'd paid more
    > attention in math class all those years ago...
    >
    > Could anyone help get me started in the right direction?
    >
    > Thanks much,
    > Steve
    > ===The computer this message====
    > ===was sent from runs exclusively==
    > ===on renewable energy sources===
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]



    It is simple to do a running average with a few variables.


    RD = Raw data is, well, raw data.
    AVG = average is well, average.
    HLD = holder is a holder for the math


    if you take

    HLD = HLD + RD ; simple enough, you are just adding a new value.
    AVG = HLD / 10 ; this makes the average,
    ;make sure HLD never exceeds your maximum value

    HLD = HLD-AVG ; here is the way to keep the
    ; total counts in the holder low

    It will take about 100 readings for a change to be fully implemented.

    This would not be trying to call a do loop or anything fancy, it
    would just take each new reading, add it to the total, then divide by
    a number. I used 10 for an example.

    The main thing is that you can't have a WORD as the variable and
    average 10 values of 60,000.

    the problem with this is that it acts like a noise filter. If you
    ran near 100% for 30 days, then near zero, it would report zero in
    short order.


    A variance is to take your raw data and divide that by 10. since it
    is only an average, the last number is not important anyway.

    Another method might be to look at the differences in the readings
    and average those.

    But, if you are looking for a usage meter then a whole different
    approach would be needed.

    Assuming you take one reading a minute.
    you could check to see if that reading is less than 10%, between 10
    and 20, between 20-30 or 30-40 and so on.
    Then just keep a value of how many times the reading is less than
    10%, between 10 and 20 and so on.
    You only increment your value by one regardless of the real value.
    Then if you also keep track of how many readings, you can figure the
    average.

    you could use a look-up table with 100 points to get an accuracy of
    1%.

    One problem is how often you need to take a reading. once per second
    will yield 86,400 seconds per day. if you increment by 1 for each
    reading you will soon run out of space.

    Once a minute is 44,640 in 31 days.

    If you really wanted one reading per second and had 100 levels to
    read, you could multiply that by having another counter of each time
    any reading hit say, 60,000. a second variable would see the reading
    reaching 60,000 then adding one to it's value and resetting the
    60,000 back to zero.

    Another option is data logging.
    A 512k EEPROM would hold a lot of data, but packing it in there is a
    challenge. If you tried to time stamp, the time would take up half
    of the space.

    Dave

    CC-EEPROM is waiting photos, but currently in the pending product
    link.
    http://www.visualmuses.com/chipcircuit/index.html
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-04 19:24
    At 10:31 AM 5/4/04 -0700, laurasdog@w... wrote:

    >>
    >> > I am trying to gather power data from a small wind generator.
    >> > Voltage and current are sampled aprox twice per second
    >> > with a 12-bit ADC and data is fed to a BS2.
    >> > Numbers are crunched and instantaneous and peak
    >> > voltage, current, and power are displayed on an LCD display.
    >> > There is no real time clock, so the number of samples
    >> > in a day is only approximately known
    >> >
    >>
    >>One of the problems here is that if you continually sum the satts, it won't
    >>be long before you reach 65535 and roll over, thus losing your total. I
    >>have a
    >>scheme I am using in a data logger that might help if you care to contact me
    >>off line. I'm not guaranteeing a solution, only a bit of help.
    >>
    >>Sid Weaver
    >
    >Thanks Sid,
    >I was hoping there might be some sort of slick way to "average as you go".
    >Perhaps save samples until you get close to the 65K limit, then average.
    >Save that number and grab the next load of samples and average those..
    >or something like that. The *average* is unlikely to exceed a few hundred
    >watts. I suppose I could add more memory, but due to bad planning I'm
    >just about out of I/O and 3 more lines would be tough to come up with...
    >
    >Steve
    >===The computer this message====
    > ===was sent from runs exclusively==
    > ===on renewable energy sources===

    Steve -

    You may find it of interest to glance through some of Tracy Allen's notes here
    on developing statistics and the Stamp:
    http://www.emesystems.com/BS2math5.htm

    You may also want to scan the archives here, and look for both "averaging", and "boxcar averaging". Both topics have been discussed at length in the past.

    Regards,

    Bruce Bates
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-04 19:25
    At 10:42 AM 5/4/2004, Dave wrote:
    <snip>
    >HLD = HLD + RD ; simple enough, you are just adding a new value.
    >AVG = HLD / 10 ; this makes the average,
    > ;make sure HLD never exceeds your maximum value
    >
    >HLD = HLD-AVG ; here is the way to keep the
    > ; total counts in the holder low
    <snip>
    >the problem with this is that it acts like a noise filter. If you
    >ran near 100% for 30 days, then near zero, it would report zero in
    >short order.

    Dave, I'm actually using this type of scheme already as a noise
    filter for the voltage processing part. Works great! But, alas... it
    doesn't work well for long term averaging for the reason you
    mentioned.


    >But, if you are looking for a usage meter then a whole different
    >approach would be needed.
    >
    >Assuming you take one reading a minute.
    >you could check to see if that reading is less than 10%, between 10
    >and 20, between 20-30 or 30-40 and so on.
    >Then just keep a value of how many times the reading is less than
    >10%, between 10 and 20 and so on.
    >You only increment your value by one regardless of the real value.
    >Then if you also keep track of how many readings, you can figure the
    >average.
    >
    >you could use a look-up table with 100 points to get an accuracy of
    >1%.

    Hmmm. This may be promising. An accuracy of 5% would be
    acceptable for this project. I'll have to think about this one for a bit.

    Maybe I'll have to rip up some of my circuitry and redesign to
    recover some of my I/O so I can use an external EEPROM. Sigh...

    Thanks very much,
    Steve
    ===The computer this message====
    ===was sent from runs exclusively==
    ===on renewable energy sources===



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-04 21:21
    --- In basicstamps@yahoogroups.com, laurasdog@w... wrote:
    >
    > >
    > > > I am trying to gather power data from a small wind generator.
    > > > Voltage and current are sampled aprox twice per second
    > > > with a 12-bit ADC and data is fed to a BS2.
    > > > Numbers are crunched and instantaneous and peak
    > > > voltage, current, and power are displayed on an LCD display.
    > > > There is no real time clock, so the number of samples
    > > > in a day is only approximately known
    > > >
    > >
    > >One of the problems here is that if you continually sum the watts,
    it won't
    > >be long before you reach 65535 and roll over, thus losing your
    total. I
    > >have a
    > >scheme I am using in a data logger that might help if you care to
    contact me
    > >off line. I'm not guaranteeing a solution, only a bit of help.
    > >
    > >Sid Weaver
    >
    > Thanks Sid,
    > I was hoping there might be some sort of slick way to "average as
    you go".
    > Perhaps save samples until you get close to the 65K limit, then
    average.
    > Save that number and grab the next load of samples and average
    those..
    > or something like that. The *average* is unlikely to exceed a few
    hundred
    > watts. I suppose I could add more memory, but due to bad planning
    I'm
    > just about out of I/O and 3 more lines would be tough to come up
    with...
    >
    > Steve
    > ===The computer this message====
    > ===was sent from runs exclusively==
    > ===on renewable energy sources===

    Interesting, if you have any serial already, all you need is one
    line for the SPI to select the chip. If I2C, you may be able to get
    by with a hardware address on the memory.

    But, if you added a chip riser, with a port expander or even a 595
    and then re-direct some output pins....

    Some of this is just not simple !

    Dave
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-05 08:17
    Hi Steve,

    Try a variety of exponential smoothing. It is fairly clearly explained
    in MS Excel's help. Hardly any memory used.

    Dov Yassky
    5, Shapira Street
    Tel Aviv 64358
    Israel



    Original Message
    From: laurasdog@w...
    [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=zyrLGhaYj4rI6vGJjyMEqLnwf3V6ao_nf_HOZlbQofs0D6ndfq37VVktzxMpu2fxOijj9QczcbZM2vqUBl0cBfkVHbkNTg]laurasdog@w...[/url
    Sent: Tuesday, May 04, 2004 6:50 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Averaging numbers over a long time


    Greetings group,

    I am trying to gather power data from a small wind generator. Voltage
    and current are sampled aprox twice per second with a 12-bit ADC and
    data is fed to a BS2. Numbers are crunched and instantaneous and peak
    voltage, current, and power are displayed on an LCD display. There is no
    real time clock, so the number of samples in a day is only approximately
    known

    The problem I'm having is with the "average watts" portion of it. I need
    to average the watts over time (possibly as long as a month) and keep a
    running *average* (not total) on the watts produced. The peak watts at
    any time could go as high as 700. (but anything over 500 is pretty
    scary!) Output could also be zero for hours or days at a time.

    I seem to be having trouble finding a solution to this without using up
    a ton of memory space. Wish I'd paid more attention in math class all
    those years ago...

    Could anyone help get me started in the right direction?

    Thanks much,
    Steve
    ===The computer this message====
    ===was sent from runs exclusively==
    ===on renewable energy sources===


    [noparse][[/noparse]Non-text portions of this message have been removed]



    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.