Re: Kulago/Mauch DRO ISA quadrature feedback kit
Matt Shaver wrote:
> > From: Doug Fortune <pentam-at-home.com>
> > Ok, I know there is a limit to how fast you can step a stepper (in rpm).
>
> It's more a problem of the granularity of the frequency control during
> accel/decel ....
> 1. Forget the interrupt idea and use a software timing loop. Much better
> control of the step frequency is possible if moves are mostly planned out in
> advance and a short loop (maybe written in assembly) simply clocks out the
> pulses.
Here it is (only for pentiums, not for 386/486 as they do not have a pentiumtimer.
// pentiumtimer.c - short program to demonstrate getting the pentiumtimer
// ticks which goes from 0 (bootup) to some big 64 bit
number
// (the 64 bit counter wraps to 0 every 430,000 days
or so)
// I think in 2 ns increments on a 500 Mhz cpu.
// the idea is to precompute the 64 bit value you want
to start
// your code at (which represents a time), set the
interrupt to
// get you there shortly before, then go into a busy
cycle
// until you reach the target 64 bit value
//
// when the second column reaches 2**32, it resets to
0
// and the first column increments by one.
// Thanks to the RTL guys who helped me on this prog.
//gcc pentiumtimer.c -o pentiumtimer -O2 ; ./pentiumtimer
#include <stdio.h>
#ifndef __RDTSC_H
#define __RDTSC_H
inline long long rdtsc(void)
{
union { long L[2]; long long LL; } W;
asm __volatile__ (".byte 0x0F,0x31" : "=a"(W.L[0]), "=d"(W.L[1]));
return W.LL;
}
#endif
main()
{
unsigned long prev = 0L;
union { unsigned long L[2];
unsigned long long LL;
}X;
// this delta shows the absolute value (in two longs) and the timing
// difference (granularity) of two successive calls.
X.LL = rdtsc();
printf("cnt %u %u\n", X.L[1], prev = X.L[0]);
X.LL = rdtsc();
printf("cnt %u %u delta %u\n", X.L[1], X.L[0], X.L[0] - prev );
}
a quick demo:
./pentiumtimer ;
./pentiumtimer ;
./pentiumtimer ;
> May the torque be with you,
May the torque be with all of us
Doug Fortune
Date Index |
Thread Index |
Back to archive index |
Back to Mailing List Page
Problems or questions? Contact