PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : سوال درباره step motor



Deadman
03-11-2013, 16:19
من یک step motor دارم که 4*4 و step 1.8 پنج سیمه هست با ترانزیستور

c945 راه اندازیش کردم و وصلش کردم به یه mega32 برنامه به این صورته که

شما درجه رو میدی و موتور همون مقدار میچرخه. مشکل اینجاست که مثلا

360 درجه رو که میزنم حدود 10 یا 15 درجه بیشتر میچرخه .

حالا میخواستم بدونم اگه مشکل از برنامه نباشه (که نیست) از جی میتونه باشه

ضمنا موتور موقع چرخش نوسان داره

من از حالتی استفاده میکنم که در هر لحظه از زمان فقط یکی از پایه ها 1

هست و بقیه صفرن . روش کار هم اینطوریه که یه متغیر بایتی در نظر میگیرم و اونو مقدار

اولیه میدم و بعد شیفتش میدم به چپ یا راست . ضمنا تاخیر بین هر چرخش اول 50 میلی

ثانیه بود که باز هم همین مشکل رو داشت

اینم برنامه خودتون ببینید :


$regfile = "m32def.dat"
$crystal = 8000000
Config Lcdpin = Pin , Db4 = Pb.0 , Db5 = Pb.1 , Db6 = Pb.2 , Db7 = _
Pb.3 , E = Pb.5 , Rs = Pb.4
Config Porta = Output
Dim I As Byte , A As Byte , E As Byte
Cls
Dim B As Word
Dim C As Word
Dim D As Word
Dim K As Byte
Dim X As Byte
Config Kbd = Portd , Debounce = 100 , Delay = 70
Cls

Main0:
Do
K = Getkbd()
Loop Until K = 16
Do
K = Getkbd()
Loop Until K <> 16
If K = 15 Then
Goto Cal_isr
End If
If K = 14 Then
X = 1
Locate 2 , 1 : Lcd "Rotate right"
Goto Main0
End If
If K = 13 Then
X = 2
Locate 2 , 1 : Lcd "Rotate left"
Goto Main0
End If
B = B * 10
B = B + K
Locate 1 , 1 : Lcd B
Goto Main0


Cal_isr:
C = B / 7.2
D = B Mod 7.2

'---------------------------------- baghi mande---------------------
Select Case D
Case 0
Goto Main

Case 1
If X = 1 Then
E = 128
Rotate E , Left
Porta = E
Waitms 100
Goto Main
End If
If X = 2 Then
E = 16
Rotate E , Right
Porta = E
Waitms 100
Goto Main
End If

Case 2
If X = 1 Then
E = 128
Rotate E , Left
Porta = E
Waitms 100
Rotate E , Left
Porta = E
Waitms 100
Goto Main
End If
If X = 2 Then
E = 16
Rotate E , Right
Porta = E
Waitms 100
Rotate E , Right
Porta = E
Waitms 100
Goto Main
End If

Case 3
If X = 1 Then
E = 128
Rotate E , Left
Porta = E
Waitms 100
Rotate E , Left
Porta = E
Waitms 100
Rotate E , Left
Porta = E
Waitms 100
End If
If X = 2 Then
E = 16
Rotate E , Right
Porta = E
Waitms 100
Rotate E , Right
Porta = E
Waitms 100
Rotate E , Right
Porta = E
Waitms 100
Goto Main
End If


Case 4
If X = 1 Then
E = 128
Rotate E , Left
Porta = E
Waitms 100
Rotate E , Left
Porta = E
Waitms 100
Rotate E , Left
Porta = E
Waitms 100
Rotate E , Left
Porta = E
Waitms 100
End If
If X = 2 Then
E = 16
Rotate E , Right
Porta = E
Waitms 100
Rotate E , Right
Porta = E
Waitms 100
Rotate E , Right
Porta = E
Waitms 100
Rotate E , Right
Porta = E
Waitms 100
Goto Main
End If

Case 5
If X = 1 Then
Porta = 1
Waitms 100
Porta = 2
Waitms 100
Porta = 4
Waitms 100
Porta = 8
Waitms 100
Porta = 1
Waitms 100
End If
If X = 2 Then
Porta = 1
Waitms 100
Porta = 8
Waitms 100
Porta = 4
Waitms 100
Porta = 2
Waitms 100
Porta = 1
Waitms 100
Goto Main
End If

Case 6
If X = 1 Then
Porta = 1
Waitms 100
Porta = 2
Waitms 100
Porta = 4
Waitms 100
Porta = 8
Waitms 100
Porta = 1
Waitms 100
Porta = 2
Waitms 100
End If
If X = 2 Then
Porta = 1
Waitms 1000
Porta = 8
Waitms 100
Porta = 4
Waitms 100
Porta = 2
Waitms 100
Porta = 1
Waitms 100
Porta = 8
Waitms 100
Goto Main
End If

Case 7
If X = 1 Then
Porta = 1
Waitms 100
Porta = 2
Waitms 100
Porta = 4
Waitms 100
Porta = 8
Waitms 100
Porta = 1
Waitms 100
Porta = 2
Waitms 100
Porta = 4
Waitms 100
End If
If X = 2 Then
Porta = 1
Waitms 100
Porta = 8
Waitms 100
Porta = 4
Waitms 100
Porta = 2
Waitms 100
Porta = 1
Waitms 100
Porta = 8
Waitms 100
Porta = 4
Waitms 100
Goto Main
End If
End Select
'------------------------------ adad asli----------------------
Main:
Select Case X
Case 1
For A = 1 To C
E = 128
For I = 1 To 4
Rotate E , Left
Porta = E
Waitms 100
Next I
Next A
Cls : Locate 1 , 1 : Lcd "stop_stop"
Do : Loop

Case 2
For A = 1 To C
E = 16
For I = 1 To 4
Rotate E , Right
Porta = E
Waitms 100
Next I
Next A
Cls : Locate 1 , 1 : Lcd "stop_stop"
Do : Loop
End Select
End