基本信息
源码名称:基于VB6.0步进电机S曲线生成器
源码大小:0.01M
文件格式:.rar
开发语言:ASP
更新时间:2020-02-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
VB6.0实现步进电机S曲线控制数组生成器【VB6源代码工程文件】,具体的使用方法、硬件电路、单片机程序可以到我的博客里面查看。

VB源码-步进电机S曲线生成器.rar

VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "步进电机速度S型曲线生成器(微信ID:saskingku)"
   ClientHeight    =   8550
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   14115
   LinkTopic       =   "Form1"
   ScaleHeight     =   150.813
   ScaleMode       =   6  'Millimeter
   ScaleWidth      =   248.973
   StartUpPosition =   3  '窗口缺省
   Begin VB.PictureBox Picture1 
      Height          =   3495
      Left            =   6360
      ScaleHeight     =   60.59
      ScaleMode       =   6  'Millimeter
      ScaleWidth      =   131.498
      TabIndex        =   27
      Top             =   4920
      Width           =   7515
   End
   Begin VB.Frame Frame2 
      Caption         =   "硬件参数"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   4695
      Left            =   10380
      TabIndex        =   15
      Top             =   120
      Width           =   3495
      Begin VB.TextBox Text2 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   1860
         TabIndex        =   20
         Text            =   "1.8"
         Top             =   420
         Width           =   1395
      End
      Begin VB.TextBox Text3 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   1860
         TabIndex        =   19
         Text            =   "11059200"
         Top             =   975
         Width           =   1395
      End
      Begin VB.TextBox Text4 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   1860
         TabIndex        =   18
         Text            =   "1"
         Top             =   2070
         Width           =   1395
      End
      Begin VB.TextBox Text8 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   1860
         TabIndex        =   17
         Text            =   "4"
         Top             =   1500
         Width           =   1395
      End
      Begin VB.TextBox Text11 
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   180
         TabIndex        =   16
         Top             =   3600
         Width           =   3135
      End
      Begin VB.Label Label13 
         Caption         =   "ATMEGA16 time1定时器"
         Enabled         =   0   'False
         Height          =   195
         Left            =   240
         TabIndex        =   26
         Top             =   4260
         Width           =   3195
      End
      Begin VB.Label Label1 
         Caption         =   "步距角"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   240
         TabIndex        =   25
         Top             =   420
         Width           =   1455
      End
      Begin VB.Label Label2 
         Caption         =   "硬件频率"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   240
         TabIndex        =   24
         Top             =   975
         Width           =   1455
      End
      Begin VB.Label Label3 
         Caption         =   "定时器分频"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   240
         TabIndex        =   23
         Top             =   2145
         Width           =   1455
      End
      Begin VB.Label Label7 
         Caption         =   "驱动器细分"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   240
         TabIndex        =   22
         Top             =   1560
         Width           =   1455
      End
      Begin VB.Label Label10 
         Caption         =   "最小启动转速(转/秒)"
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   180
         TabIndex        =   21
         Top             =   3180
         Width           =   3075
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "速度曲线参数"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3675
      Left            =   6360
      TabIndex        =   2
      Top             =   120
      Width           =   3855
      Begin VB.TextBox Text10 
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   2220
         TabIndex        =   12
         Top             =   2520
         Width           =   1395
      End
      Begin VB.TextBox Text12 
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   2220
         TabIndex        =   11
         Top             =   3060
         Width           =   1395
      End
      Begin VB.TextBox Text5 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   2220
         TabIndex        =   6
         Text            =   "1"
         Top             =   1425
         Width           =   1395
      End
      Begin VB.TextBox Text6 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   2220
         TabIndex        =   5
         Text            =   "5"
         Top             =   1965
         Width           =   1395
      End
      Begin VB.TextBox Text7 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   2220
         TabIndex        =   4
         Text            =   "18"
         Top             =   360
         Width           =   1395
      End
      Begin VB.TextBox Text9 
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   435
         Left            =   2220
         TabIndex        =   3
         Text            =   "5"
         Top             =   870
         Width           =   1395
      End
      Begin VB.Label Label9 
         Caption         =   "步进电机步数"
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   180
         TabIndex        =   14
         Top             =   2580
         Width           =   1455
      End
      Begin VB.Label Label11 
         Caption         =   "总时间(ms)"
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   180
         TabIndex        =   13
         Top             =   3120
         Width           =   1455
      End
      Begin VB.Label Label4 
         Caption         =   "启动转速(转/秒)"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   180
         TabIndex        =   10
         Top             =   1440
         Width           =   2175
      End
      Begin VB.Label Label5 
         Caption         =   "最大转速(转/秒)"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   180
         TabIndex        =   9
         Top             =   1995
         Width           =   2115
      End
      Begin VB.Label Label6 
         Caption         =   "角度(度)"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   180
         TabIndex        =   8
         Top             =   405
         Width           =   1455
      End
      Begin VB.Label Label8 
         Caption         =   "加速快慢"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   12
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   180
         TabIndex        =   7
         Top             =   915
         Width           =   1455
      End
   End
   Begin VB.CommandButton Command1 
      Caption         =   "曲线计算"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   21.75
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   6360
      TabIndex        =   1
      Top             =   3900
      Width           =   3855
   End
   Begin VB.TextBox Text1 
      Height          =   8295
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Top             =   120
      Width           =   6135
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim BuJuJiao As Double '步进电机步距角
Dim F0 As Double '硬件频率
Dim Nf As Double '定时器分频
Dim v0 As Double '加速段启动速度
Dim vt As Double '加速段最大速度
Dim JSBuShu As Long '加速步数
Dim JSJiaoDu As Double '加速段角度
Dim XiFen As Double '驱动器细分
Dim JSKuaiMan As Double '加速快慢,数值越大越慢
Dim JSshijian As Double '加速时间
Dim FenDuan As Double '将曲线分成梯形图
Dim MCCiShu As Long '每个速断段脉冲次数
Dim MCYuShu As Integer '分段不整除时最后的余数

Dim Fmin As Double 'V0对应的脉冲频率
Dim Fmax As Double 'Vt对应的脉冲频率
Dim Fcurrent As Double '实时频率

Dim DSChuZhi As Long '定时器1初值,采用溢出中断
Dim i As Integer '计数
Dim a0 As Long 'A0第一个脉冲的初值
Dim DingShiQiFenPing As Integer '定时器1预分频数
Dim ZhuanXiang As String '电机转动方向
Public Function Max(a As Double, b As Double) As Double '求最大值
    If a < b Then
        Max = b
    ElseIf a >= b Then
        Max = a
    End If
End Function
Public Function ST(ax As Double, ay As Double, n As Double, m As Double) '图框初始化
'图框初始化
    Dim Kuandanwei As Double
    Picture1.ScaleMode = 6 '设置图片框单位
    Kuandanwei = Picture1.Width / 400
    Picture1.ScaleTop = -Picture1.Height / 2 '定义坐标原点x
    Picture1.ScaleLeft = -Picture1.Width / 2 '-10 * Kuandanwei '定义坐标原点y
    Picture1.Circle (0, 0), 1000
'X轴
    Picture1.Line (-8 * Kuandanwei, 0)-(380 * Kuandanwei, 0)
    Picture1.Line (380 * Kuandanwei, 0)-(370 * Kuandanwei, 10 * Kuandanwei)
    Picture1.Line (380 * Kuandanwei, 0)-(370 * Kuandanwei, -10 * Kuandanwei)
    Picture1.CurrentX = 380 * Kuandanwei
    Picture1.CurrentY = 0
    Picture1.Print "t"
'Y轴
    Picture1.Line (0, 0.45 * Picture1.Height)-(0, -0.45 * Picture1.Height)
    Picture1.Line (0, -0.45 * Picture1.Height)-(-10 * Kuandanwei, -0.45 * Picture1.Height   10 * Kuandanwei)
    Picture1.Line (0, -0.45 * Picture1.Height)-(10 * Kuandanwei, -0.45 * Picture1.Height   10 * Kuandanwei)
    Picture1.CurrentX = 0
    Picture1.CurrentY = -0.5 * Picture1.Height
    Picture1.Print "S"
'绘制坐标点
    Picture1.PSet (n * Kuandanwei, -ax * m / 3), vbRed
    Picture1.PSet (n * Kuandanwei, -ay * m / 3), vbBlue
    n = n   1
    If n >= 360 Then
        n = n - 360
        Picture1.Cls
    End If
End Function
Public Function QuXian() '曲线图框初始化,BS步进电机步数为x轴,vt为Y轴
'图框初始化
    
    Picture1.Cls
    Picture1.DrawWidth = 1
    Dim Bili As Double '绘图比例
    Bili = 0.7
    Dim Kuandanwei As Double 'x方向图片放缩比例
    Dim Gaodanwei As Double 'y方向图片放缩比例
    Form1.ScaleMode = 6 '设置FORM框单位
    Picture1.ScaleMode = 6 '设置图片框单位
    Kuandanwei = Picture1.Width / (JSBuShu) '根据步进电机总时间计算图片放缩比例
    Gaodanwei = Picture1.Height / Max(v0, vt)
    Picture1.ScaleTop = -Picture1.Height   5 * Kuandanwei '定义坐标原点y
    Picture1.ScaleLeft = -5 * Kuandanwei '定义坐标原点x
    Picture1.CurrentX = 0
    Picture1.CurrentY = 0
    Picture1.Print "0"
'X轴
    Dim x1 As Double
    Dim y1 As Double
    Dim x2 As Double
    Dim y2 As Double
    Dim x3 As Double
    Dim y3 As Double
    x1 = Bili * (JSBuShu * Kuandanwei)
    y1 = Bili * 0
    x2 = Bili * (x1 - 3) ' 5 * Kuandanwei)
    y2 = Bili * (y1   3) '5 * Kuandanwei)
    x3 = x2
    y3 = -y2
    Picture1.Line (0, 0)-(x1, y1)
    Picture1.Line (x1, y1)-(x2, y2)
    Picture1.Line (x1, y1)-(x3, y3)
    Picture1.CurrentX = x1
    Picture1.CurrentY = y1
    Picture1.Print Int(JSshijian * 1000) & "ms"
'Y轴
    Dim x4 As Double
    Dim y4 As Double
    Dim x5 As Double
    Dim y5 As Double
    Dim x6 As Double
    Dim y6 As Double
    x4 = Bili * 0
    y4 = Bili * (-Max(v0, vt) * Gaodanwei)
    x5 = Bili * (x4 - 3) '-5* Kuandanwei)
    y5 = Bili * (y4 - 3) '-5* Kuandanwei)
    x6 = -x5
    y6 = y5
    Picture1.Line (0, 0)-(x4, y4)
    Picture1.Line (x4, y4)-(x5, y5)
    Picture1.Line (x4, y4)-(x6, y6)
    Picture1.CurrentX = x4   Kuandanwei
    Picture1.CurrentY = y4
    Picture1.Print Max(v0, vt) & "r/s"
    
'绘制坐标点
    Picture1.DrawWidth = 5
    Dim i As Integer
    For i = 1 To JSBuShu
        Picture1.PSet (Bili * i * Kuandanwei, Bili * -Gaodanwei * (v0   (vt - v0) / (1   Exp(-JSKuaiMan * (i - JSBuShu / 2) / (JSBuShu / 2))))), vbRed
    Next
End Function
Private Sub Command1_Click()
BuJuJiao = Text2.Text
F0 = Text3.Text
Nf = Text4.Text
v0 = Text5.Text
vt = Text6.Text
JSJiaoDu = Text7.Text
XiFen = Text8.Text
JSKuaiMan = Text9.Text
If Text4.Text = 1 Then
DingShiQiFenPing = 1
ElseIf Text4.Text = 8 Then
DingShiQiFenPing = 2
ElseIf Text4.Text = 64 Then
DingShiQiFenPing = 3
ElseIf Text4.Text = 256 Then
DingShiQiFenPing = 4
ElseIf Text4.Text = 1024 Then
DingShiQiFenPing = 5
End If

JSBuShu = JSJiaoDu / (BuJuJiao / XiFen)
Fmin = v0 * 360 / (BuJuJiao / XiFen)
Fmax = vt * 360 / (BuJuJiao / XiFen)

Text1 = ""
JSshijian = 0

''''''''''''''''''''''''''''加速段A0数组生成'''''''''''
    For i = 1 To JSBuShu
        Fcurrent = Fmin   (Fmax - Fmin) / (1   Exp(-JSKuaiMan * (i - JSBuShu / 2) / (JSBuShu / 2)))
        DSChuZhi = 65535 - 1 / (Fcurrent * 2) * F0 / Nf '16位定时器
        If i <> JSBuShu Then
            Text1 = Text1 & "0X" & Hex(DSChuZhi) & ","
        Else
            Text1 = Text1 & "0X" & Hex(DSChuZhi)
        End If
        JSshijian = JSshijian   1 / Fcurrent
    Next

a0 = 65535 - 1 / ((Fmin   (Fmax - Fmin) / (1   Exp(-JSKuaiMan * (1 - JSBuShu / 2) / (JSBuShu / 2)))) * 2) * F0 / Nf
Text10 = JSBuShu
Text12 = JSshijian * 1000
Text1 = "A[" & JSBuShu & "]={" & Text1 & "};" & vbCrLf & vbCrLf

''''''''''''''''''''''''''''
Text11.Text = (2 * F0 * BuJuJiao) / (65535 * Nf * 360 * XiFen) '计算最小启动速度

QuXian '绘制速度曲线
End Sub