delayMicroseconds values

Hello Group, I am new to this and a total amateur when it comes to Arduino processors. I am trying to use a A4988 Stepper Driver. to operate a telescope drive. I have it now to the point of rotating the scope to within 18 seconds error per day. (23h56m04seconds)by changing the micro second on time plus or minus 1 microsecond, between 799 and 800 time base. I obtain a speed accuracy of plus or minus 18 seconds which is ok for time exposure photography but id like to get it tighter if I can. Can I use fractional values, ie 799.75 as the processor clock speed of the uno is 16MHZ I am wondering if this might work. With PLCS I could use a scan counter eg ( reg4086 plus one to reg4086. when count equals 69,450 move 0 to reg4086 and pulse output.)
I put in a value tonight of 799.75 and it did compile and load, but I don't know if it will actually lengthen the pulse by .75 microseconds or not.
comments will be appreciated
Thanks Joe

When using an Arduino for timing, be aware of a few things regarding getting an affordable product to market. The operative word here is affordable. Just as when you by resistors, you can specify 5, 10 or even 20% tolerance and pay accordingly. Dig deeper into your pocket and you can get 1% and even 0.1% (add the zero you took off to the price).

Most of my 'cheap' Arduinos have had their 16MHz clocks timed to be 15.88 MHz. This is well within spec as laid out by our friends in Italy, but will wreck havoc with any app that relies on precise timing. There are several options. One is to scope your board and get the true freq of the system clock and work this into your calculations along with compensation for temperature swings over the period of a day. The other is to invest a small amount in an RTC. There are RTCs available with accuracy as high as 4 seconds per month I read. Another option is a small GPS module that continues to receive network time 24/7. I use the GPS and can resync my timing every second.

hanging the micro second on time plus or minus 1 microsecond

The "delayMicroseconds()" call has a resolution of 4us. :frowning:
You might get a bit better with _delay_us (beware it's limitations!), but then you still run into the accuracy issues DKWatson mentions, plus there are periodic interrupt events that will come along and sometimes (approximatelt every ms) delay your code by more than 1us.

joe4095:
Can I use fractional values, ie 799.75

I don't think it works like that. I think it will just treat 799.75 as 799.

Why not just use 800 the first three times, and 799 the fourth time? That way, it would average out to 799.75. (This same kind of logic is used in the calendar, for leap years. Three 365-day years and one 366-day year average out to 365.25 days per year.)

In order to better help you with your problem, it would help us if we had more detail about exactly what problem you are trying to solve. What kind of telescope drive is it? How did you arrive at this figure 799.75 ? Was it the result of calculation, or experimentation, or both?

Does the 799.75 refer to milliseconds? That works out to about 107739 pulses per sidereal day, or 299.27 pulses per degree. If your motor is 300 pulses per degree (or, 108000 pulses per revolution), then you would want one pulse about every 797.82 milliseconds.

If you access the avr timer registers directly you'll be able to see sub-microsecond periods. You could get to a quarter of a microsecond if you are not doing much else.

westfw:
The "delayMicroseconds()" call has a resolution of 4us. :frowning:

No. micros() has 4 µs resolution, but delayMicroseconds() is accurate to 1 µs. (It does not use micros().)

Thanks for your help group.
I have the stepper set up for 1/4 stepping, the motor is 200 steps per turn x 1/4 stepping = 800 pulses per turn etc hooked up to a 100/1 gearbox, from there it goes to a 622/1 worm gear. The motor is from robot shop (Product Code : RB-Phi-267)
At this point the scope and drive is complete. I have a polar lock bolt that is used as a zero reference. I remove the bolt, let the drive run for 23hr56m/04seconds and check at time out if the axis has rotated 360 deg, back to the lock bolt position. At this point, it is out by plus 12sec to minus 18 seconds, depending on if the on time is 799 or 800 microseconds.
Thanks again Joe