afb
Member
I'm using the "time" variable (at 4Mhz) to time periods up to 20 seconds using an 08M2.
Initially I disable "time" immediately following it being detected to have been updated so I when I later start my timer (and enable "time") it gives a complete second upon the first update update of the "time" variable.
Then I start a simple loop that checks when the time variable reaches the target (eg 20 seconds)
In the loop I flash a LED each time the time variable increments and keep two servos refreshed (by "pulsout") so there is also a "pause" statement to govern the loop time to 20mSec. There are also a couple of "IF" statements which are not actioned in a normal timing run.
For testing, I've eliminated my inconsistent reaction times by making an Arduino stopwatch that times to 1/1000 sec and connecting it to a spare 08M2 pin that goes high for the duration of the timing period.
Poor timekeeping accuracy was traced to the inclusion of the "pulsout" commands in the loop which though not 'blocking' like "pulsin" for example presumably access some internal timer register and interfere with the "time" variable as would the "servo" command. The IF, pause and LED driving statements appear to be blameless.
With the Arduino "stopwatch" the native time keeping of the chip (an empty loop) was established to be accurate to about 0.015 sec in a 20 second run. I can add all the other statements without deterioration, but driving a single servo with "pulsout" degrades the accuracy to about 0.15 secs in a 20 sec run, which is just about acceptable in my application. However, adding the second servo gives a disproportionately large error of about 1.5 secs - and I'm at a loss to reason why that is so large.
Instead of using the 'pulsout' command, by flipping a servo output, pausing for two milliseconds then flipping it back I can recover the original native accuracy but now the servos give tiny twitches as these commands sometimes take slightly different times to execute as presumably the chip is doing its own housekeeping in the background. Note that the significant command execution time at 4Mhz means that a 2mSec servo pulse was generated by a high, a dummy high, a 1mSec pause and a low.
Any thoughts, commiserations or alternative ways of skinning the cat are welcomed !
Alan
Initially I disable "time" immediately following it being detected to have been updated so I when I later start my timer (and enable "time") it gives a complete second upon the first update update of the "time" variable.
Then I start a simple loop that checks when the time variable reaches the target (eg 20 seconds)
In the loop I flash a LED each time the time variable increments and keep two servos refreshed (by "pulsout") so there is also a "pause" statement to govern the loop time to 20mSec. There are also a couple of "IF" statements which are not actioned in a normal timing run.
For testing, I've eliminated my inconsistent reaction times by making an Arduino stopwatch that times to 1/1000 sec and connecting it to a spare 08M2 pin that goes high for the duration of the timing period.
Poor timekeeping accuracy was traced to the inclusion of the "pulsout" commands in the loop which though not 'blocking' like "pulsin" for example presumably access some internal timer register and interfere with the "time" variable as would the "servo" command. The IF, pause and LED driving statements appear to be blameless.
With the Arduino "stopwatch" the native time keeping of the chip (an empty loop) was established to be accurate to about 0.015 sec in a 20 second run. I can add all the other statements without deterioration, but driving a single servo with "pulsout" degrades the accuracy to about 0.15 secs in a 20 sec run, which is just about acceptable in my application. However, adding the second servo gives a disproportionately large error of about 1.5 secs - and I'm at a loss to reason why that is so large.
Instead of using the 'pulsout' command, by flipping a servo output, pausing for two milliseconds then flipping it back I can recover the original native accuracy but now the servos give tiny twitches as these commands sometimes take slightly different times to execute as presumably the chip is doing its own housekeeping in the background. Note that the significant command execution time at 4Mhz means that a 2mSec servo pulse was generated by a high, a dummy high, a 1mSec pause and a low.
Any thoughts, commiserations or alternative ways of skinning the cat are welcomed !
Alan