Translate

Membuat Alat Kendali 3 Buah Motor DC ( Smooth Start dan Smooth Stop )

Membuat Alat Kendali 3 Buah Motor DC ( Smooth Start dan Smooth Stop )


             Kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat untuk kendali 3 buah motor DC atau nama lainnya 3 channel. Alat ini bisa mengendalikan kecepatan putaran motor dc dan arah putarannya, maksimal arus motor dc atau arus beban adalah 2A karena menggunakan L298. Alat ini memiliki keunggulan yaitu smooth start dan smooth stop, maksudnya jika motor akan berjalan atau running, dia tidak langsung berputar cepat melainkan berjalan secara perlahan hingga mencapai kecepatan yang telah diatur menggunakan potensiometer, begitu pula dengan saat motor berhenti, motor tidak langsung berhenti melainkan akan mengurangi secara perlahan hingga dia berhenti. untuk lebih jelasnya berikut skema dan programnya.



a. Minimum System 




b. Joystick X-Y




c. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 11059200
$baud = 9600

'setting pwm
Config Timer1 = Pwm , Pwm = 8 , Prescale = 64 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up
Config Timer2 = Pwm , , Prescale = 1024 , Compare Pwm = Clear Up

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Dim X As Word
Dim Y As Word
Dim Z As Word

Dim A As Word
Dim B As Word
Dim G As Word
G = 0
Dim Mark As Integer
Mark = 0
Dim Jj As Integer
Dim Kk As Integer
Jj = 0
Kk = 0

Ddrc = &B11111111
Enable Timer2
Timer2 = 0
Start Timer2
Enable Interrupts

Ddrb.0 = 0
Ddrb.1 = 0

Set Portb.0
Set Portb.1


Start Adc

Main:
G = 0
Do
Portc.5 = 0
Portc.4 = 0

Ocr2 = 0

Portc.3 = 0
Portc.2 = 0

Pwm1a = 0

Portc.1 = 0
Portc.0 = 0

Pwm1b = 0

'X = Getadc(1)
'Y = Getadc(0)
'Z = Getadc(2)

A = Getadc(3)
B = Getadc(4)

'Print A
'Print B
'Waitms 200


'motor1
If A > 500 Then
Waitms 200
Portc.3 = 0
Portc.2 = 1
Goto Startup1

Elseif A < 10 Then
Waitms 200
Portc.3 = 1
Portc.2 = 0
Goto Startup1

Else
Portc.3 = 0
Portc.2 = 0

Pwm1a = 0

End If


'motor2
If B > 500 Then
Waitms 200
Portc.1 = 0
Portc.0 = 1
Goto Startup2

Elseif B < 10 Then
Waitms 200
Portc.1 = 1
Portc.0 = 0
Goto Startup2

Else
Portc.1 = 0
Portc.0 = 0
Pwm1b = 0

End If


'motor 3
If Pinb.0 = 0 Then
Waitms 200
Portc.5 = 1
Portc.4 = 0

Goto Startup


Elseif Pinb.1 = 0 Then
Waitms 200
Portc.5 = 0
Portc.4 = 1

Goto Startup

Else
Portc.5 = 0
Portc.4 = 0

If Z > 255 Then
Z = 255
End If

Ocr2 = Z

End If

Loop



Startup:

G = 0
Do

Z = Getadc(2)
Y = Getadc(0)

If Z > 255 Then
Z = 255
End If

If Pinb.0 = 0 Or Pinb.1 = 0 Then
G = G + 1
Ocr2 = G
End If


If G > Z Then
G = Z
Ocr2 = Z

End If

Portb.0 = 1
Portb.1 = 1
If Pinb.0 = 1 And Pinb.1 = 1 Then
Waitms 200
G = Z
Goto Stopx
End If

Waitms Y

Loop



Stopx:
Do
Y = Getadc(0)

If G < 1 Then
G = 0
Portc.5 = 0
Portc.4 = 0
Goto Main
End If


Ocr2 = G

G = G - 1

Waitms Y

Loop


Startup1:

G = 0
Do

Z = Getadc(1)
Y = Getadc(0)
A = Getadc(3)

If Z > 255 Then
Z = 255
End If

If A < 10 Or A > 500 Then
G = G + 1
Pwm1a = G
End If


If G > Z Then
G = Z
Pwm1a = Z

End If

If A > 100 And A < 500 Then
G = Z
Goto Stopx1
End If

Waitms Y

Loop



Stopx1:

Do
Y = Getadc(0)

If G < 1 Then
G = 0
Portc.3 = 0
Portc.2 = 0
Goto Main
End If


Pwm1a = G

G = G - 1

Waitms Y

Loop



Startup2:

G = 0
Do

Z = Getadc(1)
Y = Getadc(0)
B = Getadc(4)

If Z > 255 Then
Z = 255
End If

If B < 10 Or B > 500 Then
G = G + 1
Pwm1b = G
End If


If G > Z Then
G = Z
Pwm1b = Z

End If

If B > 100 And B < 500 Then
G = Z
Goto Stopx2
End If

Waitms Y

Loop



Stopx2:

Do
Y = Getadc(0)

If G < 1 Then
G = 0
Portc.1 = 0
Portc.0 = 0
Goto Main
End If


Pwm1b = G

G = G - 1

Waitms Y

Loop




d. Program 3 AXIS X Y Z

$regfile = "m32def.dat"
$crystal = 11059200
$baud = 9600

'setting pwm
Config Timer1 = Pwm , Pwm = 8 , Prescale = 64 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up
Config Timer2 = Pwm , , Prescale = 1024 , Compare Pwm = Clear Up

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Dim X As Word
Dim Y As Word
Dim Z As Word

Dim A As Word
Dim B As Word

Dim L As Integer
Dim K As Integer
Dim S As Integer
L = 0
K = 0
S = 0

Ddrc = &B11111111
Enable Timer2
Timer2 = 0
Start Timer2
Enable Interrupts

Ddrb.0 = 0
Ddrb.1 = 0

Set Portb.0
Set Portb.1


Start Adc

Main:

Do
'motor 3
Portc.5 = 0
Portc.4 = 0

Ocr2 = 0

'motor 1
Portc.3 = 0
Portc.2 = 0

Pwm1a = 0

'motor 2
Portc.1 = 0
Portc.0 = 0

Pwm1b = 0

X = Getadc(1)
Y = Getadc(0)
Z = Getadc(2)

A = Getadc(3)
B = Getadc(4)



'kondisi 1
If A > 1000 And B > 1000 And Pinb.0 = 0 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup



Elseif A > 1000 And B > 1000 And Pinb.1 = 0 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 1
Goto Startup


Elseif A > 1000 And B > 1000 And Pinb.0 = 1 And Pinb.1 = 1 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 0
Goto Startup





'kondisi 2
Elseif A > 1000 And B > 10 And B < 1000 And Pinb.0 = 0 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup


Elseif A > 1000 And B > 10 And B < 1000 And Pinb.1 = 0 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 1
Goto Startup


Elseif A > 1000 And B > 10 And B < 1000 And Pinb.0 = 1 And Pinb.1 = 1 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 0
Goto Startup




'kondisi 3
Elseif A > 1000 And B < 10 And Pinb.0 = 0 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup



Elseif A > 1000 And B < 10 And Pinb.1 = 0 Then

'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 0
Portc.4 = 1
Goto Startup




Elseif A > 1000 And B < 10 And Pinb.0 = 1 And Pinb.1 = 1 Then
'motor 1
Portc.3 = 1
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 0
Portc.4 = 0
Goto Startup




'kondisi 4
Elseif A > 10 And A < 1000 And B < 10 And Pinb.0 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup


Elseif A > 10 And A < 1000 And B < 10 And Pinb.1 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 0
Portc.4 = 1
Goto Startup


Elseif A > 10 And A < 1000 And B < 10 And Pinb.0 = 1 And Pinb.1 = 1 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 0
Portc.4 = 0
Goto Startup



'kondisi 5
Elseif A < 10 And B < 10 And Pinb.0 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup


Elseif A < 10 And B < 10 And Pinb.1 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 0
Portc.4 = 1
Goto Startup


Elseif A < 10 And B < 10 And Pinb.0 = 1 And Pinb.1 = 1 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 0
Portc.0 = 1
'motor 3
Portc.5 = 0
Portc.4 = 0
Goto Startup



'kondisi 6
Elseif A < 10 And B > 10 And B < 1000 And Pinb.0 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 1
Portc.4 = 0

Goto Startup


Elseif A < 10 And B > 10 And B < 1000 And Pinb.1 = 0 Then

'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 1

Goto Startup


Elseif A < 10 And B > 10 And B < 1000 And Pinb.0 = 1 And Pinb.1 = 1 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 0
Goto Startup



'kodisi 7
Elseif A < 10 And B > 1000 And Pinb.0 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup


Elseif A < 10 And B > 1000 And Pinb.1 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup


Elseif A < 10 And B > 1000 And Pinb.0 = 1 And Pinb.1 = 1 Then
'motor 1
Portc.3 = 0
Portc.2 = 1
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 0
Goto Startup



'kondisi 8
Elseif A > 10 And A < 1000 And B > 1000 And Pinb.0 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup

Elseif A > 10 And A < 1000 And B > 1000 And Pinb.1 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 1
Goto Startup

Elseif A > 10 And A < 1000 And B > 1000 And Pinb.0 = 1 And Pinb.1 = 1 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 1
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 0

Goto Startup


'kondisi 9
Elseif A > 10 And A < 1000 And B > 10 And B < 1000 And Pinb.0 = 0 And Pinb.1 = 1 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 1
Portc.4 = 0
Goto Startup

Elseif A > 10 And A < 1000 And B > 10 And B < 1000 And Pinb.0 = 1 And Pinb.1 = 0 Then
'motor 1
Portc.3 = 0
Portc.2 = 0
'motor 2
Portc.1 = 0
Portc.0 = 0
'motor 3
Portc.5 = 0
Portc.4 = 1
Goto Startup

End If
Loop


Startup:
L = 0
K = 0
S = 0

Do
X = Getadc(1)
Y = Getadc(0)
Z = Getadc(2)

If Pinb.0 = 0 Then
Portc.5 = 1
Portc.4 = 0
Elseif Pinb.1 = 0 Then
Portc.5 = 0
Portc.4 = 1
End If



If A > 1000 Then
Portc.3 = 1
Portc.2 = 0
Elseif A < 10 Then
Portc.3 = 0
Portc.2 = 1

End If


If B > 1000 Then
Portc.1 = 1
Portc.0 = 0
Elseif B < 10 Then
Portc.1 = 0
Portc.0 = 1

End If


If X > 255 Then
X = 255
End If
If Y > 255 Then
Y = 255
End If
If Z > 255 Then
Z = 255
End If

A = Getadc(3)
B = Getadc(4)

Pwm1a = L
Pwm1b = K
Ocr2 = S

Incr L
Incr K
Incr S

If L > X Then
L = X
End If

If K > Y Then
K = Y
End If

If S > Z Then
S = Z
End If

Waitms 10

If A > 10 And A < 600 And B > 10 And B < 600 And Pinb.0 = 1 And Pinb.1 = 1 Then
Goto Berhenti
End If

Loop


Berhenti:
Do

Pwm1a = L
Pwm1b = K
Ocr2 = S

Decr L
Decr K
Decr S

If L < 1 Then
L = 0
End If

If K < 1 Then
K = 0
End If

If S < 1 Then
S = 0
End If

If L < 1 And K < 1 And S < 1 Then
Goto Main
End If

Waitms 10

Loop




e. VIDEO HASILNYA







No comments:

Post a Comment