> An application I'm working on needs a variable number of pulses > to be fitted into a 32ms window. The number of pulses can be > anything from 20 to 5000. The ideal is to completely fill up the > 32ms with evenly-spaced pulses, but in practice, because this > has to be done every 32ms with new data, it is necessary to get > as close to 32ms without going over > > For the first test I've tried simple division to find the pulse spacing, > but because the resolution is whole instruction cycle times, there > is a gap after the pulses. This isn't desirable because a servo in > the system stops dead at this gap and causes the mechanism to > shudder evry 32ms Sounds like the pulse rate controlls the speed of a servo (like a stepper motor?), that the total number of pulses must be correct, that they should come "smoothly", and that you get new speed information every 32mS. Why not start with that problem statement and work out a scheme? Assuming the above is true, I would low pass filter the input value, and adjust the pulse *frequency* several times per input value. Since the pulse generator is always running, it is always producing a continuous stream of pulses. Only its frequency will change occasionally. These changes are made less abrupt by filtering the input value, and by adjusting the output frequency "often", like every few mS or so. You also keep track of the total number of pulses that should have been emitted minus the total number that were actually emitted. This feeds back into the filtered value to guarantee no long term errors. This scheme will instroduce a short lag in the step response, but it should be possible to get that less than one 32mS data time. Since this is driving a mechanical system, it probably won't matter, but you would have to decide that. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu