我对lz做的产品很感兴趣,这里贡献一段动检测是否能达到指定速度的检测代码,稍微改改就能态生成加速曲线:
Public Function ComputePulse(ByVal Velo As Double, ByVal a As Double, ByVal d As Double, ByRef maxv As Double, ByRef PNum As Long, ByRef t As Double) As Boolean
Dim c0 As Long
Dim c1 As Long
Dim flag As Boolean
PNum = 1
c0 = 0.676 * Frequency * Sqr(2 * d / a) / 2
t = c0 * 2
flag = True
Do
c1 = c0 - c0 / (2 * PNum)
maxv = d / c1 * Frequency / 2
t = t + c1 * 2
PNum = PNum + 1
If c0 <> c1 Then
c0 = c1
Else
flag = False
End If
Loop Until maxv > Velo Or Not flag
PNum = PNum - 1
t = t / Frequency
ComputePulse = flag
End Function
其中Frequency是单片机运行频率。
c0 = 0.676 * Frequency * Sqr(2 * d / a) / 2是初值,除以2的原因是因为通常的步进电机驱动器都是一个脉冲前进一步,不是一个上升沿或者一个下降沿前进一步(除非用STK672-080的16细分模式)。
c1 = c0 - c0 / (2 * PNum)通过之前计算的结果得出下一次发出脉冲的间隔,更精确一点c1 = c0 - c0 * 2 / (4 * PNum - 1))