step motor kontrolü hakkında yardım

mobilspy

Üye
Katılım
13 Eki 2006
Mesajlar
122
Puanları
1
Yaş
44
arkadaslar 16f84 ile tekbuton kullanarak bir step motor kontrol etmek istiyorum
devrenin çalışması:
butona basıldıgında motor sag yöne 16 adım donecek ve buton basılı oldugu surece duracak buton basılması kesildiginde tekrar ilk konumuna yani sola 16 adım donecek ancak 16 adım dolmadan misal 7. adımda buton basılması kesilirse 7 adım geri donmesini istiyorum.

bunun için asagıdaki kodu hazırladım ama bi sorunum var bundada ilk calıs etiktindeki for..next döngüsünü

( FOR X=0 TO 10 STEP 1) yapıp (x=x+1) satırını sildiğimde program çalışmıyor aşagıdaki şekilde çalışıyor fakat ileri çalışırken ikişer ikişer atlıyor geri tek tek dönüyor. bir yorumu olan varmı acaba

Kod:
TRISA=1
TRISB=0
PULS VAR BYTE
X VAR BYTE
Y VAR BYTE
PULS=0
PORTB=%00000001
X=0
Y=0

BASLA:
button PORTA.1, 1, 255,255,PULS,1,CALIS
GOTO BASLA
CALIS:
        FOR X=0 TO 16 
        x=x+1    
        gosub TABLO
        IF PORTA.1=0 THEN GOTO DUR
PAUSE 500
            NEXT X
GOTO BEKLE

BEKLE:
    IF PORTA.1=1 THEN GOTO bekle
GOTO    dur

DUR:
Y=X-1
 FOR Y=Y TO Y=0 step -1
        GOSUB TABLOY
        IF PORTA.1=1 THEN GOTO BASLA
PAUSE 500
            NEXT
GOTO    BASLA

TABLO:
SELECT CASE x
CASE 1
PORTB =%00000001
RETURN
CASE 2
PORTB =%00000011
RETURN
CASE 3
PORTB =%00000010
RETURN
CASE 4
PORTB =%00000110
RETURN
CASE 5
PORTB =%00000100
RETURN
CASE 6
PORTB =%00001100
RETURN
CASE 7
PORTB =%00001000
RETURN
CASE 8
PORTB =%00001001
RETURN
CASE 9
PORTB =%00000001
RETURN
CASE 10
PORTB =%00000011
RETURN
CASE 11
PORTB =%00000010
RETURN
CASE 12
PORTB =%00000110
RETURN
CASE 13
PORTB =%00000100
RETURN
CASE 14
PORTB =%00001100
RETURN
CASE 15
PORTB =%00001000
RETURN
CASE 16
PORTB =%00001001
RETURN
CASE IS > 16
PORTB =%00001001
RETURN
CASE ELSE
PORTB =%00000001
END SELECT 

TABLOY:
SELECT CASE Y
CASE 1
PORTB =%00000001
RETURN
CASE 2
PORTB =%00000011
RETURN
CASE 3
PORTB =%00000010
RETURN
CASE 4
PORTB =%00000110
RETURN
CASE 5
PORTB =%00000100
RETURN
CASE 6
PORTB =%00001100
RETURN
CASE 7
PORTB =%00001000
RETURN
CASE 8
PORTB =%00001001
RETURN
CASE 9
PORTB =%00000001
RETURN
CASE 10
PORTB =%00000011
RETURN
CASE 11
PORTB =%00000010
RETURN
CASE 12
PORTB =%00000110
RETURN
CASE 13
PORTB =%00000100
RETURN
CASE 14
PORTB =%00001100
RETURN
CASE 15
PORTB =%00001000
RETURN
CASE 16
PORTB =%00001001
RETURN
CASE IS > 16
PORTB =%00001001
RETURN
CASE ELSE
PORTB =%00000001
END SELECT 
END


denemek isterseniz isis dosyası ekte:
 

Ekli dosyalar

  • step motor.rar
    15.2 KB · Görüntüleme: 55
arkadaslar sorunumu cozdum programın daha pratik cozumu olabilecegini dusunen arkadaslardan yorumlarını bekliyorum.


Kod:
'****************************************************************
'*  Name    : Step.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 20.04.2009                                        *
'*  Version : 1.0                                               *
'*  Notes   : Step Motor Kontrolu                               *
'*          :                                                   *
'****************************************************************
TRISA=1
TRISB=0
PULS VAR BYTE
X VAR BYTE
Y VAR BYTE
PULS=0
PORTB=%00000001
X=0
Y=0

BASLA:
button PORTA.1, 1, 255,255,PULS,1,CALIS
GOTO BASLA
CALIS:
        FOR X=0 TO 16 STEP 1
        Gosub TABLO
        IF PORTA.1=0 THEN GOTO DUR
PAUSE 500
            NEXT 
GOTO BEKLE

BEKLE:
    IF PORTA.1=1 THEN GOTO bekle
GOTO    dur

DUR:
Y=X-1
 FOR Y=Y TO Y=0 step -1
        GOSUB TABLOY
        IF PORTA.1=1 THEN GOTO YARIDA
PAUSE 500
            NEXT
GOTO    BASLA

YARIDA:
FOR X=Y TO 16 STEP 1
        Gosub TABLO
        IF PORTA.1=0 THEN GOTO DUR
PAUSE 500
            NEXT 
GOTO BEKLE


TABLO:
SELECT CASE x
CASE 1
PORTB =%00000001
RETURN
CASE 2
PORTB =%00000011
RETURN
CASE 3
PORTB =%00000010
RETURN
CASE 4
PORTB =%00000110
RETURN
CASE 5
PORTB =%00000100
RETURN
CASE 6
PORTB =%00001100
RETURN
CASE 7
PORTB =%00001000
RETURN
CASE 8
PORTB =%00001001
RETURN
CASE 9
PORTB =%00000001
RETURN
CASE 10
PORTB =%00000011
RETURN
CASE 11
PORTB =%00000010
RETURN
CASE 12
PORTB =%00000110
RETURN
CASE 13
PORTB =%00000100
RETURN
CASE 14
PORTB =%00001100
RETURN
CASE 15
PORTB =%00001000
RETURN
CASE 16
PORTB =%00001001
RETURN
CASE IS > 16
PORTB =%00001001
RETURN
CASE ELSE
PORTB =%00000001
RETURN
END SELECT 

TABLOY:
SELECT CASE Y
CASE 1
PORTB =%00000001
RETURN
CASE 2
PORTB =%00000011
RETURN
CASE 3
PORTB =%00000010
RETURN
CASE 4
PORTB =%00000110
RETURN
CASE 5
PORTB =%00000100
RETURN
CASE 6
PORTB =%00001100
RETURN
CASE 7
PORTB =%00001000
RETURN
CASE 8
PORTB =%00001001
RETURN
CASE 9
PORTB =%00000001
RETURN
CASE 10
PORTB =%00000011
RETURN
CASE 11
PORTB =%00000010
RETURN
CASE 12
PORTB =%00000110
RETURN
CASE 13
PORTB =%00000100
RETURN
CASE 14
PORTB =%00001100
RETURN
CASE 15
PORTB =%00001000
RETURN
CASE 16
PORTB =%00001001
RETURN
CASE IS > 16
PORTB =%00001001
RETURN
CASE ELSE
PORTB =%00000001
RETURN
END SELECT 
END
 
Arkadaşım bu devreyi çalıştırabildinmi?

banada böyle bir devre lazım
 
Yukarıdaki kodu MPASMWIN ile hex e çevirirken hata çıkıyor hexe çevirmiyor bunu nasıl düzeltiriz ?
Error[122] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 3 : Illegal opcode (VAR)
Error[122] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 4 : Illegal opcode (VAR)
Error[122] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 5 : Illegal opcode (VAR)
Error[128] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 7 : Missing argument(s)
Error[122] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 12 : Illegal opcode (PORTA.1)
Warning[203] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 13 : Found opcode in column 1. (GOTO)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 15 : Found label after column 1. (FOR)
Error[122] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 15 : Illegal opcode (X)
Warning[207] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 16 : Found label after column 1. (Gosub)
Error[122] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 16 : Illegal opcode (TABLO)
Error[113] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 17 : Symbol not previously defined (PORTA.1)
Error[108] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 17 : Illegal character (=)
Warning[212] C:\DOCUME~1\ADMINI~1\DESKTOP\STEPASM\STEP.ASM 100 : Expected (ENDIF)

MPASM 02.61 Released STEP.ASM 8-11-2009 10:43:34 PAGE 1


LOC OBJECT CODE LINE SOURCE TEXT
VALUE

00000001 00001 TRISA=1
00000000 00002 TRISB=0
Error[122] : Illegal opcode (VAR)
00000000 00003 PULS VAR BYTE
Error[122] : Illegal opcode (VAR)
00000000 00004 X VAR BYTE
Error[122] : Illegal opcode (VAR)
00000000 00005 Y VAR BYTE
00000000 00006 PULS=0
Error[128] : Missing argument(s)
00000000 00007 PORTB=%00000001
00000000 00008 X=0
00000000 00009 Y=0
00010
0000 00011 BASLA:
Error[122] : Illegal opcode (PORTA.1)
0000 00012 button PORTA.1, 1, 255,255,PULS,1,CALIS
Warning[203]: Found opcode in column 1. (GOTO)
0000 2800 00013 GOTO BASLA
0001 00014 CALIS:
Warning[207]: Found label after column 1. (FOR)
Error[122] : Illegal opcode (X)
0001 00015 FOR X=0 TO 16 STEP 1
Warning[207]: Found label after column 1. (Gosub)
Error[122] : Illegal opcode (TABLO)
0001 00016 Gosub TABLO
Error[113] : Symbol not previously defined (PORTA.1)
Error[108] : Illegal character (=)
00017 IF PORTA.1=0 THEN GOTO DUR
00018 PAUSE 500
00019 NEXT
00020 GOTO BEKLE
00021
00022 BEKLE:
00023 IF PORTA.1=1 THEN GOTO bekle
00024 GOTO dur
00025
00026 DUR:
00027 Y=X-1
00028 FOR Y=Y TO Y=0 step -1
00029 GOSUB TABLOY
00030 IF PORTA.1=1 THEN GOTO YARIDA
00031 PAUSE 500
00032 NEXT
00033 GOTO BASLA
00034
00035 YARIDA:
00036 FOR X=Y TO 16 STEP 1
00037 Gosub TABLO
00038 IF PORTA.1=0 THEN GOTO DUR
00039 PAUSE 500
00040 NEXT
00041 GOTO BEKLE
MPASM 02.61 Released STEP.ASM 8-11-2009 10:43:34 PAGE 2


LOC OBJECT CODE LINE SOURCE TEXT
VALUE

00042
00043
00044 TABLO:
00045 SELECT CASE x
00046 CASE 1
00047 PORTB =%00000001
00048 RETURN
00049 CASE 2
00050 PORTB =%00000011
00051 RETURN
00052 CASE 3
00053 PORTB =%00000010
00054 RETURN
00055 CASE 4
00056 PORTB =%00000110
00057 RETURN
00058 CASE 5
00059 PORTB =%00000100
00060 RETURN
00061 CASE 6
00062 PORTB =%00001100
00063 RETURN
00064 CASE 7
00065 PORTB =%00001000
00066 RETURN
00067 CASE 8
00068 PORTB =%00001001
00069 RETURN
00070 CASE 9
00071 PORTB =%00000001
00072 RETURN
00073 CASE 10
00074 PORTB =%00000011
00075 RETURN
00076 CASE 11
00077 PORTB =%00000010
00078 RETURN
00079 CASE 12
00080 PORTB =%00000110
00081 RETURN
00082 CASE 13
00083 PORTB =%00000100
00084 RETURN
00085 CASE 14
00086 PORTB =%00001100
00087 RETURN
00088 CASE 15
00089 PORTB =%00001000
00090 RETURN
00091 CASE 16
00092 PORTB =%00001001
00093 RETURN
00094 CASE IS > 16
MPASM 02.61 Released STEP.ASM 8-11-2009 10:43:34 PAGE 3


LOC OBJECT CODE LINE SOURCE TEXT
VALUE

00095 PORTB =%00001001
00096 RETURN
00097 CASE ELSE
00098 PORTB =%00000001
00099 RETURN
Warning[212]: Expected (ENDIF)
00100 END SELECT
MPASM 02.61 Released STEP.ASM 8-11-2009 10:43:34 PAGE 4


SYMBOL TABLE
LABEL VALUE

BASLA 00000000
CALIS 00000001
PORTB 00000000
PULS 00000000
TRISA 00000001
TRISB 00000000
X 00000000
Y 00000000
__16F84 00000001


MEMORY USAGE MAP ('X' = Used, '-' = Unused)

0000 : X--------------- ---------------- ---------------- ----------------

All other memory blocks unused.

Program Memory Words Used: 1
Program Memory Words Free: 1023


Errors : 9
Warnings : 4 reported, 0 suppressed
Messages : 0 reported, 0 suppressed

 
Son düzenleme:
bende yeniyim bu pic işinde , ama codu daha kısa olusturman mumkun.. belki işini görür
ekde isis çizimide var.. bekle değişkenini degıstırerek hızı artırıp azaltabilirsin.. anahtar on iken saat yönunde off iken saat yönü tersinde donuyor, sinyal.1=0 ve sinyal.1=1 yer değiştirirsen anahtarın durumuna gore donus yonude degısecektır..
picbasic proton ile hazırladım, microbasıc icn degısıklık yapman gerekebilir derleme sorunu cıkar...





Device 16F877
XTAL = 20
Dim adim As Byte
Dim tekrar As Byte
Dim bekle As Word
Dim adimlar[8] As Byte


TRISD=0
PORTD=0
TRISB=255
TRISB=0
Symbol sinyal=PORTB
Symbol a1=PORTD
adimlar[0]=%00001001
adimlar[1]=%00000001
adimlar[2]=%00000011
adimlar[3]=%00000010
adimlar[4]=%00000110
adimlar[5]=%00000100
adimlar[6]=%00001100
adimlar[7]=%00001000
sinyal=0
adim=0
a1=0
tekrar=0
bekle=5 ' 30 ms adım arası süre
basla:


If sinyal.1=1 And tekrar <= 15 Then
Inc adim
If adim=8 Then adim=0
a1=adimlar[adim]
Inc tekrar
EndIf

If sinyal.1=0 And tekrar>1 Then
Dec adim
If adim=-1 Then adim=7
a1=adimlar[adim]
Dec tekrar
EndIf
DelayMS bekle
GoTo basla
 

Forum istatistikleri

Konular
128,200
Mesajlar
915,783
Kullanıcılar
449,982
Son üye
admik

Yeni konular

Geri
Üst