Shop OBEX P1 Docs P2 Docs Learn Events
Accurate data acquisition timing — Parallax Forums

Accurate data acquisition timing

ArchiverArchiver Posts: 46,084
edited 2002-09-20 07:01 in General Discussion
Hi!

I'm trying to accurately time some data acquisition on the basic
stamp. I'm reading two axes of acceleration from the ADXL202
accelerometer and I'd like to accurately do this say, 8 times a
second - ie read it every 125ms. The problem is, if I execute the
code to read the accelerometer and then pause for 125ms (using PAUSE
125), the total time between readings is more than 125ms!

Does anyone have ideas for a way around this? Is there a way I can
accurately find out how many ms it takes to execute the accelerometer
reading code or can I read a time stamp from RAM or something??

Any comments appreciated!

Thanks!

Brad.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 03:49
    Why not stick it in a loop that executes say, 1000 times. Subtract the time
    after the loop from the time before and divide by 1000. If 1000 times is
    not enough to get the resolution you want, do it 10,000 times.


    Original Message
    From: "Brad" <brad_j_schultz@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, September 19, 2002 6:42 PM
    Subject: [noparse][[/noparse]basicstamps] Accurate data acquisition timing


    > Hi!
    >
    > I'm trying to accurately time some data acquisition on the basic
    > stamp. I'm reading two axes of acceleration from the ADXL202
    > accelerometer and I'd like to accurately do this say, 8 times a
    > second - ie read it every 125ms. The problem is, if I execute the
    > code to read the accelerometer and then pause for 125ms (using PAUSE
    > 125), the total time between readings is more than 125ms!
    >
    > Does anyone have ideas for a way around this? Is there a way I can
    > accurately find out how many ms it takes to execute the accelerometer
    > reading code or can I read a time stamp from RAM or something??
    >
    > Any comments appreciated!
    >
    > Thanks!
    >
    > Brad.
    >
    >
    > 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.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 04:00
    Why do you need to time it? If you do something for an undetermined amount
    of time, then do something for 125 ms, the total will be greater than 125
    ms. I would make my pause shorter and shorter until I got the number of
    reads per second you need.


    Original Message


    > Why not stick it in a loop that executes say, 1000 times. Subtract the
    time
    > after the loop from the time before and divide by 1000. If 1000 times is
    > not enough to get the resolution you want, do it 10,000 times.

    > > I'm trying to accurately time some data acquisition on the basic
    > > stamp. I'm reading two axes of acceleration from the ADXL202
    > > accelerometer and I'd like to accurately do this say, 8 times a
    > > second - ie read it every 125ms. The problem is, if I execute the
    > > code to read the accelerometer and then pause for 125ms (using PAUSE
    > > 125), the total time between readings is more than 125ms!
    > >
    > > Does anyone have ideas for a way around this? Is there a way I can
    > > accurately find out how many ms it takes to execute the accelerometer
    > > reading code or can I read a time stamp from RAM or something??
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 04:12
    >Hi!
    >
    >I'm trying to accurately time some data acquisition on the basic
    >stamp. I'm reading two axes of acceleration from the ADXL202
    >accelerometer and I'd like to accurately do this say, 8 times a
    >second - ie read it every 125ms. The problem is, if I execute the
    >code to read the accelerometer and then pause for 125ms (using PAUSE
    >125), the total time between readings is more than 125ms!
    >
    >Does anyone have ideas for a way around this? Is there a way I can
    >accurately find out how many ms it takes to execute the accelerometer
    >reading code or can I read a time stamp from RAM or something??
    >
    >Any comments appreciated!
    >
    >Thanks!
    >
    >Brad.

    Hi Brad,

    The most accurate way to do this is to use an external chip for the
    timing. Maybe you will have a real time clock as part of your data
    acquisition system? Lock into the 1 second tick of the real time
    clock. Some real time clock chips like the DS1307 have a dedicated
    one second period square wave output. There are other options using
    an external chip, including an CD4060 chip with 32khz crystal, or
    timed to the 60hz power line, or to WWVB, or an external timer chip
    like the one from Peter Anderson or the PAK from Al Williams.
    http://www.phanderson.com/clock.html
    http://www.al-williams.com/awce/pak7.htm

    It is possible to write Stamp programs that execute a fixed loop with
    very accurate timing, if you don't want to go the route with an
    external chip. Say your code takes 7 milliseconds to run the loop.
    Then you use a PAUSE 118 instead of PAUSE 125. If you want to cut
    the error even closer, you can pad the code with extra instructions
    that burn up "exactly" the right amount of time. The PULSOUT command
    is a good one for this because you can cut it down to microseconds.
    However, it will not be as accurate as the external chip over the
    long term. Be ready to tear out your hair when you go to change
    anything!

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 04:33
    For true accuracy, you need the interrupt capabilities of PICs using
    TIMER0, and an external crystal oscillator without the overhead of a
    PBASIC interpreter.
    Just my .02,
    Dennis

    Original Message
    From: Rodent [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=k2INvLuCCGo9AfUycp1lZ1f4TCBraj5uIQFiYvtL90YK58zO-i-jgCCh36RYD7Sg5tVIv1GWrO1Z]daweasel@s...[/url
    Sent: Thursday, September 19, 2002 8:01 PM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Accurate data acquisition timing


    Why do you need to time it? If you do something for an undetermined
    amount of time, then do something for 125 ms, the total will be greater
    than 125 ms. I would make my pause shorter and shorter until I got the
    number of reads per second you need.


    Original Message


    > Why not stick it in a loop that executes say, 1000 times. Subtract
    > the
    time
    > after the loop from the time before and divide by 1000. If 1000 times

    > is not enough to get the resolution you want, do it 10,000 times.

    > > I'm trying to accurately time some data acquisition on the basic
    > > stamp. I'm reading two axes of acceleration from the ADXL202
    > > accelerometer and I'd like to accurately do this say, 8 times a
    > > second - ie read it every 125ms. The problem is, if I execute the
    > > code to read the accelerometer and then pause for 125ms (using PAUSE

    > > 125), the total time between readings is more than 125ms!
    > >
    > > Does anyone have ideas for a way around this? Is there a way I can
    > > accurately find out how many ms it takes to execute the
    > > accelerometer reading code or can I read a time stamp from RAM or
    > > something??
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 04:34
    I think y'all missed his original problem -- he was trying to do a read 8
    times a second -- 125 ms apart. However, he did not take into consideration
    how long the read takes -- he was pausing for 125 ms and not 125 ms minus
    the time it takes to do the read.

    Original Message
    From: "Tracy Allen" <tracy@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, September 19, 2002 10:12 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Accurate data acquisition timing


    > >Hi!
    > >
    > >I'm trying to accurately time some data acquisition on the basic
    > >stamp. I'm reading two axes of acceleration from the ADXL202
    > >accelerometer and I'd like to accurately do this say, 8 times a
    > >second - ie read it every 125ms. The problem is, if I execute the
    > >code to read the accelerometer and then pause for 125ms (using PAUSE
    > >125), the total time between readings is more than 125ms!
    > >
    > >Does anyone have ideas for a way around this? Is there a way I can
    > >accurately find out how many ms it takes to execute the accelerometer
    > >reading code or can I read a time stamp from RAM or something??
    > >
    > >Any comments appreciated!
    > >
    > >Thanks!
    > >
    > >Brad.
    >
    > Hi Brad,
    >
    > The most accurate way to do this is to use an external chip for the
    > timing. Maybe you will have a real time clock as part of your data
    > acquisition system? Lock into the 1 second tick of the real time
    > clock. Some real time clock chips like the DS1307 have a dedicated
    > one second period square wave output. There are other options using
    > an external chip, including an CD4060 chip with 32khz crystal, or
    > timed to the 60hz power line, or to WWVB, or an external timer chip
    > like the one from Peter Anderson or the PAK from Al Williams.
    > http://www.phanderson.com/clock.html
    > http://www.al-williams.com/awce/pak7.htm
    >
    > It is possible to write Stamp programs that execute a fixed loop with
    > very accurate timing, if you don't want to go the route with an
    > external chip. Say your code takes 7 milliseconds to run the loop.
    > Then you use a PAUSE 118 instead of PAUSE 125. If you want to cut
    > the error even closer, you can pad the code with extra instructions
    > that burn up "exactly" the right amount of time. The PULSOUT command
    > is a good one for this because you can cut it down to microseconds.
    > However, it will not be as accurate as the external chip over the
    > long term. Be ready to tear out your hair when you go to change
    > anything!
    >
    > -- regards,
    > Tracy Allen
    > electronically monitored ecosystems
    > mailto:tracy@e...
    > http://www.emesystems.com
    >
    >
    >
    >
    >
    > 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.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 04:34
    I think y'all missed his original problem -- he was trying to do a read 8
    times a second -- 125 ms apart. However, he did not take into consideration
    how long the read takes -- he was pausing for 125 ms and not 125 ms minus
    the time it takes to do the read.

    Original Message
    From: "Tracy Allen" <tracy@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, September 19, 2002 10:12 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Accurate data acquisition timing


    > >Hi!
    > >
    > >I'm trying to accurately time some data acquisition on the basic
    > >stamp. I'm reading two axes of acceleration from the ADXL202
    > >accelerometer and I'd like to accurately do this say, 8 times a
    > >second - ie read it every 125ms. The problem is, if I execute the
    > >code to read the accelerometer and then pause for 125ms (using PAUSE
    > >125), the total time between readings is more than 125ms!
    > >
    > >Does anyone have ideas for a way around this? Is there a way I can
    > >accurately find out how many ms it takes to execute the accelerometer
    > >reading code or can I read a time stamp from RAM or something??
    > >
    > >Any comments appreciated!
    > >
    > >Thanks!
    > >
    > >Brad.
    >
    > Hi Brad,
    >
    > The most accurate way to do this is to use an external chip for the
    > timing. Maybe you will have a real time clock as part of your data
    > acquisition system? Lock into the 1 second tick of the real time
    > clock. Some real time clock chips like the DS1307 have a dedicated
    > one second period square wave output. There are other options using
    > an external chip, including an CD4060 chip with 32khz crystal, or
    > timed to the 60hz power line, or to WWVB, or an external timer chip
    > like the one from Peter Anderson or the PAK from Al Williams.
    > http://www.phanderson.com/clock.html
    > http://www.al-williams.com/awce/pak7.htm
    >
    > It is possible to write Stamp programs that execute a fixed loop with
    > very accurate timing, if you don't want to go the route with an
    > external chip. Say your code takes 7 milliseconds to run the loop.
    > Then you use a PAUSE 118 instead of PAUSE 125. If you want to cut
    > the error even closer, you can pad the code with extra instructions
    > that burn up "exactly" the right amount of time. The PULSOUT command
    > is a good one for this because you can cut it down to microseconds.
    > However, it will not be as accurate as the external chip over the
    > long term. Be ready to tear out your hair when you go to change
    > anything!
    >
    > -- regards,
    > Tracy Allen
    > electronically monitored ecosystems
    > mailto:tracy@e...
    > http://www.emesystems.com
    >
    >
    >
    >
    >
    > 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.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 05:01
    Well, that's why interrupts with external timers were invented, and I
    still have most of my hair [noparse];)[/noparse] .

    Dennis

    Original Message
    From: Rodent [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=UZXFcrl4Jdncko8ZMjClZLiUOpBZoZC-fX7vqRQ2aVsZzwb4Lr1PCl1XxbzYADMxrCSmnhJ3Y1RKTvTqI4Y]daweasel@s...[/url
    Sent: Thursday, September 19, 2002 8:34 PM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Accurate data acquisition timing


    I think y'all missed his original problem -- he was trying to do a read
    8 times a second -- 125 ms apart. However, he did not take into
    consideration how long the read takes -- he was pausing for 125 ms and
    not 125 ms minus the time it takes to do the read.

    Original Message
    From: "Tracy Allen" <tracy@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, September 19, 2002 10:12 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Accurate data acquisition timing


    > >Hi!
    > >
    > >I'm trying to accurately time some data acquisition on the basic
    > >stamp. I'm reading two axes of acceleration from the ADXL202
    > >accelerometer and I'd like to accurately do this say, 8 times a
    > >second - ie read it every 125ms. The problem is, if I execute the
    > >code to read the accelerometer and then pause for 125ms (using PAUSE
    > >125), the total time between readings is more than 125ms!
    > >
    > >Does anyone have ideas for a way around this? Is there a way I can
    > >accurately find out how many ms it takes to execute the accelerometer

    > >reading code or can I read a time stamp from RAM or something??
    > >
    > >Any comments appreciated!
    > >
    > >Thanks!
    > >
    > >Brad.
    >
    > Hi Brad,
    >
    > The most accurate way to do this is to use an external chip for the
    > timing. Maybe you will have a real time clock as part of your data
    > acquisition system? Lock into the 1 second tick of the real time
    > clock. Some real time clock chips like the DS1307 have a dedicated
    > one second period square wave output. There are other options using
    > an external chip, including an CD4060 chip with 32khz crystal, or
    > timed to the 60hz power line, or to WWVB, or an external timer chip
    > like the one from Peter Anderson or the PAK from Al Williams.
    > http://www.phanderson.com/clock.html
    > http://www.al-williams.com/awce/pak7.htm
    >
    > It is possible to write Stamp programs that execute a fixed loop with
    > very accurate timing, if you don't want to go the route with an
    > external chip. Say your code takes 7 milliseconds to run the loop.
    > Then you use a PAUSE 118 instead of PAUSE 125. If you want to cut the

    > error even closer, you can pad the code with extra instructions that
    > burn up "exactly" the right amount of time. The PULSOUT command is a
    > good one for this because you can cut it down to microseconds.
    > However, it will not be as accurate as the external chip over the
    > long term. Be ready to tear out your hair when you go to change
    > anything!
    >
    > -- regards,
    > Tracy Allen
    > electronically monitored ecosystems
    > mailto:tracy@e...
    > http://www.emesystems.com
    >
    >
    >
    >
    >
    > 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.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >



    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.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-20 07:01
    Thanks for the quick responses everybody! I'll have to go let this
    churn in my head for a while... I'd like to avoid using an external
    interupt, but I would also like it to be flexible, ie easy to change
    the number of reads per second so the 'fiddle' approach may not be
    the best...

    Thanks again!

    Brad

    --- In basicstamps@y..., "Brad" <brad_j_schultz@y...> wrote:
    > Hi!
    >
    > I'm trying to accurately time some data acquisition on the basic
    > stamp. I'm reading two axes of acceleration from the ADXL202
    > accelerometer and I'd like to accurately do this say, 8 times a
    > second - ie read it every 125ms. The problem is, if I execute the
    > code to read the accelerometer and then pause for 125ms (using
    PAUSE
    > 125), the total time between readings is more than 125ms!
    >
    > Does anyone have ideas for a way around this? Is there a way I can
    > accurately find out how many ms it takes to execute the
    accelerometer
    > reading code or can I read a time stamp from RAM or something??
    >
    > Any comments appreciated!
    >
    > Thanks!
    >
    > Brad.
Sign In or Register to comment.