Home > Software engineering >  Using VB to control stepping motor for the first time, please explain
Using VB to control stepping motor for the first time, please explain

Time:10-03

This is part of the stepper motor control function, and detailed annotations, outdata do not understand, had better put this piece is also introduced in detail, thank you
Public Declare Function timeGetTime Lib "winmm. DLL () As" Long
Public outdata As Byte (0 To 8)
Public yanshi_jg As Integer
Public inpdata As the Variant
Public temp0 As Integer

'* * * * time delay function, the unit is milliseconds, support the decimal * * * *
The Public Function YanShi (HaoMiao As Double)
Dim t1
T1=timeGetTime
While (timeGetTime - t1) & lt; HaoMiao
DoEvents' return
Wend 'loop statement
End the Function

'* * * * the sum function, to sum of communication in the front of the bytes, generate a checking byte * * * *
The Public Function fun1_sub ()
Dim As a Byte
Dim As Integer b

A=0
B=0
For I=0 To 7
B=outdata (I) a + b
Next I

A=Int (b/256)
A=b - a * 256
Outdata=a (8)
End the Function

Public Function sudu_set (a1 As an Integer, a2 As Double) 'set running speed and deceleration highest frequency
Dim temp0 As Byte
Dim temp1 As Byte
Temp0=0
Temp1=0

Temp0=Int (a2/256)
Temp1=a2 - temp0 * 256

'and the highest speed of the motor configuration deceleration (normal operation)
Outdata (0)=& amp; HFF
Outdata=(1) & amp; HAA
Outdata=a1 (2)
Outdata=& amp; (3) H5
Outdata=50 (4)
Outdata (5)=0 'acceleration frequency 50 hz
Outdata (6)=temp1
Outdata (7)=temp0 speed
'Call fun1_sub
Monitorfrm. MSComm. The Output=outdata
YanShi (yanshi_jg)

End the Function

Public Function okset_sub (a As an Integer, a0 As an Integer, a1 As Integer)

Dim temp0 As Byte
Dim temp1 As Byte
Temp0=0
Temp1=0

Temp0=Int (a0/256)
Temp1=a0 - temp0 * 256
'the configuration of the motor subdivision, step away from the Angle of
Outdata (0)=& amp; HFF
Outdata=(1) & amp; HAA
Outdata number (2)=a 'motor
Outdata=& amp; (3) H1

Outdata (4)=temp1
Outdata=temp0 '(5) 4 segment
Step outdata=a1 '(6) from the Angle of 1.8 degrees
Outdata (7)=& amp; H0
Call fun1_sub
Monitorfrm. MSComm. The Output=outdata
YanShi (yanshi_jg)

End the Function

Public Function fangxqs_set (a1 As an Integer, a2 As an Integer, a3 As Integer) 'setting direction and startup
Dim temp0 As Byte
Dim temp1 As Byte
Temp0=0
Temp1=0

Temp0=Int (a3/256)
Temp1=a3 - temp0 * 256

'configuration straight direction and speed of the motor
Outdata (0)=& amp; HFF
Outdata=(1) & amp; HAA
Outdata=a1 (2)
Outdata=& amp; (3) H4

Outdata=a2 '(4) direction, and 0 for positive, 1 is the inversion of
Outdata (5)=temp1
Outdata (6)=temp0
Outdata (7)=0
Call fun1_sub
Monitorfrm. MSComm. The Output=outdata
YanShi (yanshi_jg)

End the Function

Public Function cdu_set (a1 As an Integer, a2 As Double) 'set running distance
Dim temp4 As Double
Dim temp5 As Double
Dim temp0 As Byte
Dim temp1 As Byte
Dim temp2 As Byte
Temp0=0
Temp1=0
Temp2=0
Temp4=0 #

Temp2=Int (a2/65536)
Temp4=a2 - temp2 * 65536
Temp1=Int (temp4/256)
Temp5=temp1
Temp0=temp4 - temp5 * 256

'configuration motor run length
Outdata (0)=& amp; HFF
Outdata=(1) & amp; HAA
Outdata=a1 (2)
Outdata=& amp; (3) H3
Outdata (4)=temp0
Outdata (5)=temp1
Outdata length (6)=temp2 '
Outdata (7)=0
Call fun1_sub
Monitorfrm. MSComm. The Output=outdata
YanShi (yanshi_jg)
End the Function

CodePudding user response:

This is no standard for individual design of hardware, its communication protocol god knows,
Domestic dog is like you, you call it what calls to eat, the only you know,

CodePudding user response:

Look at your code, the outside should control module and a microcontroller or similar.
And eventually to control the step motor is that module.
Your program is on the run in VB implementation step control and output, the pure external module as the I/O + power amplifier, which is very problematic,
Not to say that can't do that, you may use the external control support you do it. But it is definitely not a good idea.

In general, the correct way is: in the single chip microcomputer (or anything else) write the most basic step in the procedure, the received power output circuit again received a stepper motor.
Then MCU leave some communication parameters for computer is used to "control", what control?
(such as step interval length is provided by single chip microcomputer), the control of the speed of the stepper motor.
Also, the computer directly "one-step" instructions and episodes, it is successive a few steps.

So the instructions on the computer is actually very simple, function implementation is on an external module.

CodePudding user response:

Looking for vendors to technical support,
Who knows who design, ask others is also a white asked,
To spend money to buy the equipment to support is your right, don't do things QiLvZhaoLv,
  • Related