03-17-2008 12:46 PM
03-17-2008 04:21 PM
What do you need to control with this stepper? Will you need the position to be sinusoidal as well, without any "creep?" Or are you needing a sinusoidal variation superimposed on a nominal constant freq?
Here's the problem: you *do* have the ability to change output freq on-the-fly, but the exact timing of when those changes occur are at the mercy of your software code and OS. At best, you'll create a piecewise-constant approximation of a sine wave as each programmed frequency is liable to generate multiple pulses before your next update. Further, you won't be able to count on this stairstepping frequency to be entirely consistent.
So I'm going to point you in another direction that's a bigger hassle and more complicated to deal with, but which stands a chance of doing exactly what you need. Instead of generating the step pulses with an onboard counter, generate them with your DIO port 0 which can generate hardware clocked digital states.
One thing working in your favor here is that you can define a buffer that represents 1 cycle of this sinusoidally-varying frequency and have the board keep regenerating. This frees up your software from having to perform continuous computations on the fly. However, defining that array of digital states isn't quite trivial.
Your board lets you generate digital patterns at up to 1 MHz, so you can define your step pulse edges with 1 microsec precision. You just have to figure out where to place those state changes so that the intervals between them correspond to your sinusoidally-varying frequency. This shouldn't be horrendously difficult, but it *does* require some careful attention to detail. Think carefully about how the digital generation will wrap around from the last defined value in the buffer back to the first. The interval between step pulse edges during this wraparound will also need to be the right duration.
-Kevin P.
03-17-2008 04:24 PM
03-18-2008 08:22 AM
03-18-2008 11:14 AM
For general help on setting up a hardware-clocked digital output task (see also "correlated" digital io), you can look over shipping examples and here on ni's site. There should be some simple demonstrations of how you send a buffer of data to a digital task which will then generate the physical signals.
For specific help on defining the 000100000000000000000000001 array of bit values, well, I can give you a few general thoughts to get you started.
Let's suppose your nominal desired speed is given by g(t) = A + B*sin(2*pi*f*t). Well, you are only going to be able to define this at the discrete points in time corresponding to step pulse edges. So you would integrate g(t) to get an expression for position as a function of time. That'll be something like h(t) = C + At - (B / (2*pi*f))*cos(2*pi*f*t). Then you could solve h(t) at the discrete positions corresponding to integer numbers of steps.
That's a nice mathematical approach, but is a pain to implement. Here's another way. Assume an initial step rate to define your initial time interval. This should correspond to A in the g(t) function above. Well, that value A for step freq implicitly defines the next point in time where you will compute g(t). So, at the time t=1/A, you can recompute g(t) to come up with your next step rate. And so on until you've figured out a full sine wave period worth of step rates.
Either way, it'll probably still be tricky to define a a nice transition as you wrap around from the end of the buffer back to the beginning. By defining an array of varying step rates, you've also defined your step pulse edge times. Assuming an active high step pulse, put a 1 or a T into the positions corresponding to step times. Put them into succeeding positions too until you've generated a wide enough step pulse for your hardware to recognize.
-Kevin P.