Timing with the 18F458

Started by July 15, 2004
Hey, I'm using an Accelerometer to measure velocity, so timing is
critical. Any ideas on how to keep accurate track of how long each
cycle of a loop runs? I would like to be as accurate as humanly
possible. I am using CCS and my code is as follows:

while( input(PIN_C2) ); // wait until low
while( !input(PIN_C2) ); // wait until high
while( input(PIN_C2) ) { // count high-time
high++;
}
while( !input(PIN_C2) ) { // count low-time
low++;
}

I want to know how much time has elapsed while it was doing those
counts.

Thanks for ANY help.
Shamoon





wrote:
>
> Hey, I'm using an Accelerometer to measure velocity, so timing is
> critical. Any ideas on how to keep accurate track of how long each
> cycle of a loop runs? I would like to be as accurate as humanly
> possible. I am using CCS and my code is as follows:
>
> while( input(PIN_C2) ); // wait until low
> while( !input(PIN_C2) ); // wait until high
> while( input(PIN_C2) ) { // count high-time
> high++;
> }
> while( !input(PIN_C2) ) { // count low-time
> low++;
> }
>
> I want to know how much time has elapsed while it was doing those
> counts.
>
> Thanks for ANY help.

Having been there, you MUST use interrupts and CCP capture if you
want any kind of accuracy. Anything else will have too much
jitter to be usable. Change the interrupt edge to get
accurate rising and falling times off the freerunning counter,
and compute your width and period and then do the duty cycle.
If you're using the ADXLs
you MUST do full duty cycle computation. e.g. width over Period
since these sensors have significant temperature drift.

If absolute value is not important, PW is suffient, but it
will drift with temp. Absolute timing is not important
because every channel and device has a different zero point.

Robert




Hello,
I am using the ADXL, and I am using the full period, by adding high
and low. How do I change the interrupt edge? Absolute timing will
help me calculate the velocity based on the acceleration. Do you
have any C code that could be useful?

Shamoon

--- In , Robert Rolf <robert.rolf@u...> wrote:
>
>
> honamos@y... wrote:
> >
> > Hey, I'm using an Accelerometer to measure velocity, so timing is
> > critical. Any ideas on how to keep accurate track of how long
each
> > cycle of a loop runs? I would like to be as accurate as humanly
> > possible. I am using CCS and my code is as follows:
> >
> > while( input(PIN_C2) ); // wait until low
> > while( !input(PIN_C2) ); // wait until high
> > while( input(PIN_C2) ) { // count high-time
> > high++;
> > }
> > while( !input(PIN_C2) ) { // count low-time
> > low++;
> > }
> >
> > I want to know how much time has elapsed while it was doing those
> > counts.
> >
> > Thanks for ANY help.
>
> Having been there, you MUST use interrupts and CCP capture if you
> want any kind of accuracy. Anything else will have too much
> jitter to be usable. Change the interrupt edge to get
> accurate rising and falling times off the freerunning counter,
> and compute your width and period and then do the duty cycle.
> If you're using the ADXLs
> you MUST do full duty cycle computation. e.g. width over Period
> since these sensors have significant temperature drift.
>
> If absolute value is not important, PW is suffient, but it
> will drift with temp. Absolute timing is not important
> because every channel and device has a different zero point.
>
> Robert




How can I use interrupts with this to accurately gauge time so that
I can integrate with respect to time?

Shamoon

--- In , Robert Rolf <robert.rolf@u...> wrote:
>
>
> honamos@y... wrote:
> >
> > Hey, I'm using an Accelerometer to measure velocity, so timing is
> > critical. Any ideas on how to keep accurate track of how long
each
> > cycle of a loop runs? I would like to be as accurate as humanly
> > possible. I am using CCS and my code is as follows:
> >
> > while( input(PIN_C2) ); // wait until low
> > while( !input(PIN_C2) ); // wait until high
> > while( input(PIN_C2) ) { // count high-time
> > high++;
> > }
> > while( !input(PIN_C2) ) { // count low-time
> > low++;
> > }
> >
> > I want to know how much time has elapsed while it was doing those
> > counts.
> >
> > Thanks for ANY help.
>
> Having been there, you MUST use interrupts and CCP capture if you
> want any kind of accuracy. Anything else will have too much
> jitter to be usable. Change the interrupt edge to get
> accurate rising and falling times off the freerunning counter,
> and compute your width and period and then do the duty cycle.
> If you're using the ADXLs
> you MUST do full duty cycle computation. e.g. width over Period
> since these sensors have significant temperature drift.
>
> If absolute value is not important, PW is suffient, but it
> will drift with temp. Absolute timing is not important
> because every channel and device has a different zero point.
>
> Robert