
|
INFO - FAQ - CC2-Forum - CCPro-Forum |
|
||
|
Hilfe... ist den keiner da, der mit mir sprechen will? > Hallo. > > Ich habe mir eine C-Control 1 M-Unit 2.0 mit Schrittmotorsteuermodul gekauft. Da ich bisher nicht in Basic programmiert habe, sondern nur VBA (das jedoch relativ gut, denke ich) verstehe ich leider die Syntax der Basic-Codes noch nicht besonders gut. Habe ein Beispielcode für die Schrittmotorsteuerung angehängt, welchen ich berits einigermaßen angepaßt habe. Leider verstehe ich nicht was ich ändern muß, damit mein Motor auch deutlich weiter als bis zur Position 5000 fahren kann (z.B. Pos. 100.000). Wer kann mir hier helfen? Vieleicht kann mir auch jemand erklären wie sich die "Positionsschritte" in Strecken umrechnen lassen. > > Vielen Dank im voraus > > Stefan > > 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII > 'IIIIIII DEMO ZUM BASIC-COMPUTER UNIT M 1.2/2.0 (by DIE HARD) IIIII > 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII > '-------------------------------------------------------------------- > ' Beispiel zum BASIC-COMPUTER mit dem Programmer/Application-Board > '-------------------------------------------------------------------- > ' ANWENDUNG: IIC-BUS STEPPERDRIVER-MODUL (198266) > ' ANSTEUERUNG > ' > '-------------------------------------------------------------------- > ' Das STEPPERDRIVER-MODUL ist mit einem ausserst komlexen und vielseitigen > ' Controller ausgesrtattet, der eine sorgfältige Einstellung auf den > ' Schrittmotor und die Anwendung erfordert. > ' In diesem Beispiel sind alle Parameter voreingestellt und sollten für > ' alle Schrittmotoren soweit passen, dass er sich auf jeden Fall dreht. > '--------------------------------------------------------------------- > ' Beim Programmstart wird der Controller initialisiert, seine aktuelle > ' Position (Zählerstand in Controller) ist 0. Die Fehlerflags werden für ca. > ' 1 s angezeigt. > ' Das Programm zeigt in der ersten Zeile des LCD > ' P:XXXX den aktuellen Positionszählerstand > ' T:XXXX die eingegeben Zielposition. > ' Und in der zweiten Zeile eine Eingabeaufforderung für eine Position > ' > ' Die Eingabe der Zielposition erfolgt mit der Tastatur am Application > ' Board. Zulässig sind Eingaben von 0 bis 9999 > ' Nach Eingabe der gewünschten Position und Drücken von Enter fährt der > ' Schrittmotor auf die gewünschte Position und Sie werden zu erneuter > ' Eingabe einer Position aufgefordert. > ' > 'In diesem Beispiel ist die Adresse des DRIVE-CONTROLLERS 192, der JUMPER JP1 > 'ist nach links gesteckt. In diesem Beispiel ist die IIC-BUS Ubertragung > 'überwacht. Wenn eine Übertragung fehlerhaft ist, wird die LCD-Beleuchtung > 'abgeschaltet (was aber nie passieren sollte), das Programm aber ansonsten ausgeführt. > 'Wenn Sie dieses Programm modifizieren oder als Teil in einer eigenen Anwendung > 'verwenden finden sie jetzt eine kurze Beschreibung wie die Unterprogramme zu > 'verwenden sind: > '------------------------------------------------------------------------ > 'GOTO_TARGET > 'Erwartet in der Wort-Variablen TARGETPOS die Position auf welche der Motor > 'gefahren werden soll. Das Unterprogramm übergibt den Wert an den Controller, > 'der Motor läuft unmittelbar darauf an. Es sind Werte von 0 bis 9999 gültig. > '----------------------------------------------------------------------- > 'S2REQUEST > 'Frägt den Status des Controllers ab und liefert in den Wort-Variablen > 'ACTPOS die momentane Position des Motors und in der Wortvariablen > 'TARGETPOS die an den Controller übertragene Zielposition. > 'Hier wird der Status abgefragt um zu ermitteln, ob die Zielposition > 'erreicht ist und eine neue Eingabe angefordert werden kann. > '----------------------------------------------------------------------- > 'S1REQUEST > 'Frägt den Status des Controllers ab und liefert in den Variablen > 'DATA5 und DATA6 die Status-Bytes 2 u. 3 des Controllers. Details dazu > 'erfahren Sie im Datenblatt zum Controller auf Seite 30. > 'Wenn das Programm in Ihrer Anwendung nicht funktionieren sollte, helfen > 'ihnen die Flags den Fehler (Anschlussfehler, Spannung zu gering usw.) > 'zu finden. > '------------------------------------------------------------------------ > ' > '-------------------------- > '------ I/O PORTS --------- > '-------------------------- > define LIGHT port[16] > define ADC8 ad[8] > '-------------------------- > '---- SYSTEM MEMORY ------- > '-------------------------- > define ACTPOS word[1] > define ACTPOSH byte[1] > define ACTPOSL byte[2] > '-------------------------- > define TARGETPOS word[2] > define TARGETPOSH byte[3] > define TARGETPOSL byte[4] > '-------------------------- > define SECPOS word[3] > define SECPOSH byte[5] > define SECPOSL byte[6] > '-------------------------- > define COUNTER word[4] > '---- IIC INTERFACE ------- > define CONFIG byte[20] > define DATA0 byte[21] > define DATA1 byte[22] > define DATA2 byte[23] > define DATA3 byte[24] > define DATA4 byte[25] > define DATA5 byte[26] > define DATA6 byte[27] > define DATA7 byte[28] > define DATA8 byte[29] > define COMMAND byte[30] > '-------------------------- > define KEYCODE byte[31]'DECODIERTE TSTE > define VALUE byte[32]'GELESENER TABELLENWERT > define DIGIT byte[34] > define TMC222 192 > #INIT > LIGHT=off > > > '----------- EINSCHALT MELDUNG------------------------ > print"#ON_LCD#"; > print"#INIT#"; > print" TMC222 DEMO"; > pause 10 > print"#CLR#"; > print"#OFF#"; > > > #START > gosub INIT_MOTOR > gosub RESET_POSITION > gosub S1REQUEST:gosub SHOWERROR:pause 100 > gosub S2REQUEST:gosub showpos:pause 50 > '----------------------------------------------------- > '-- ENTER POSITION AND MOVE STEPPER ---- > '----------------------------------------------------- > #LOOP > print"#ON_LCD#"; > gosub enter_value > print"#L101#";"RUNNING... "; > print"#OFF#"; > '---------------- RUN STEPPER ------------------------ > TARGETPOS=COUNTER > gosub GOTO_TARGET > '--------------- CHECK FOR TARGET REACHED ------------ > #LP1 > gosub S2REQUEST > if ACTPOS<>COUNTER then goto LP1 > gosub S2REQUEST:gosub showpos > goto loop > '----------------------------------------------------- > > > 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII > 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII > > > '----------------------------------------------------- > '--------- LCD - SHOW ACT POSITION -- > '----------------------------------------------------- > #SHOWPOS > print"#ON_LCD#";"#L101#";"P:";ACTPOS;" ";"T:";TARGETPOS;" ";"#OFF#"; > return > '----------------------------------------------------- > '--------- LCD - SHOW STATUS 1/2 (ERROR-FLAGS -- > '----------------------------------------------------- > #SHOWERROR > print"#ON_LCD#";"#L101#"; > COUNTER=DATA5:gosub SHOW_BINARY > print"#L201#";:COUNTER=DATA6:gosub SHOW_BINARY > print"#OFF#";:return > '----------------------------------------------------- > '--------- FULL STATUS 1 REQUEST -- > '----------------------------------------------------- > #INIT_MOTOR > print"#ON_IIC#";"#START#";:put TMC222:put &H89:put&HFF:put&HFF > put&H90' Iru Ihold > put&H0'Vmax Vmin > put &H10'Status > put 0'secpos > put 0'stepmode > print"#STOP#";:print"#OFF#"; > goto IIC_STATUS > '---------------------------------------------------- > #RESET_POSITION > COMMAND=&H86:gosub PUTCOMMAND:return > '---------------------------------------------------- > #HARD_STOP > COMMAND=&H84:gosub PUTCOMMAND:return > '---------------------------------------------------- > #GOTO_SECURE > COMMAND=&H84:gosub PUTCOMMAND:return > '---------------------------------------------------- > #GOTO_TARGET > print"#ON_IIC#";"#START#";:put TMC222:put&H8B:put&HFF > put&HFF:put TARGETPOSH:put TARGETPOSL:print"#STOP#";:print"#OFF#"; > goto IIC_STATUS > '---------------------------------------------------- > #S1REQUEST > COMMAND=&H81:gosub GETSTAT:return > '---------------------------------------------------- > #S2REQUEST > COMMAND=&HFC:gosub GETSTAT:ACTPOSH=DATA2:ACTPOSL=DATA3 > TARGETPOSH=DATA4:TARGETPOSL=DATA5:return > '---------------------------------------------------- > 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII > #GETSTAT > print"#ON_IIC#";"#START#";:put TMC222:put COMMAND:print "#STOP#"; > print"#START#";:put TMC222+1:get DATA1:get DATA2:get DATA3 > get DATA4:get DATA5:get DATA6:get DATA7:get DATA8:print"#STOP#";"#OFF#"; > goto IIC_STATUS > '---------------------------------------------------- > #PUTCOMMAND > print"#ON_IIC#";"#START#";:put TMC222:put COMMAND:print "#STOP#";"#OFF#"; > goto IIC_STATUS > '----------------------------------------------------- > '----- CONFIG REGISTER ABFRAGE UND ERROR CLEAR ------- > '----------------------------------------------------- > #IIC_STATUS > print"#ON_CONFIG#"; 'UMLEITUNG ZUM CONFIG MODULE > get CONFIG 'CONFIG REGISTER LESEN > put (CONFIG and &B10111111)'IIC ERROR FLAG IN CONFIG LÖSCHEN > print"#OFF#"; > if (CONFIG and &B01000000)>0 then LIGHT=on else LIGHT=off > return > '----------------------------------------------------- > ' WERT IN COUNTER BINÄR AUSGEBEN -- > '----------------------------------------------------- > #SHOW_BINARY > if (COUNTER and &H80)=0 then print "0"; else print "1"; > if (COUNTER and &H40)=0 then print "0"; else print "1"; > if (COUNTER and &H20)=0 then print "0"; else print "1"; > if (COUNTER and &H10)=0 then print "0"; else print "1"; > if (COUNTER and &H08)=0 then print "0"; else print "1"; > if (COUNTER and &H04)=0 then print "0"; else print "1"; > if (COUNTER and &H02)=0 then print "0"; else print "1"; > if (COUNTER and &H01)=0 then print "0"; else print "1"; > return > '--------------------------------------------------------------- > '---- ENTER A 4 DIGIT VALUE, USE CLEAR (*) AND ENTER (#) ------ > '--------------------------------------------------------------- > #enter_value > digit=0:counter=0:print"#L201#";:print"EINGABE:";:print COUNTER;:print" "; > #wait_for_key > gosub KEYDECODE > if KEYCODE=255 then goto wait_for_key > if KEYCODE=10 then goto back_space > if KEYCODE=11 then goto process_enter > if digit=4 then goto wait_for_release > counter=counter*10+KEYCODE:digit=digit+1 > print"#L201#";:print"EINGABE:";:print COUNTER;:print" "; > beep 10,3,0 > #wait_for_release > gosub KEYDECODE > if KEYCODE=255 then goto wait_for_key else goto wait_for_release > #back_space > if digit=0 then goto wait_for_release > digit=digit-1:counter=counter/10:print"#L201#";:print"EINGABE:";:print COUNTER;:print" "; > beep 10,3,0 > goto wait_for_release > #process_enter > beep 50,5,0 > print"#L201#";:print"EINGABE:";:print COUNTER;:print" ";:return > '-------------------------------------------------------------------- > ' TASTATURDECODER (RÜCKKEHR MIT TASTENCODE IN KEYCODE) > '-------------------------------------------------------------------- > #KEYDECODE > KEYCODE=255:if ADC8<10 then return > KEYCODE=0:if abs(17-ADC8)<5 then return > KEYCODE=1:if abs(33-ADC8)<5 then return > KEYCODE=2:if abs(50-ADC8)<5 then return > KEYCODE=3:if abs(66-ADC8)<5 then return > KEYCODE=4:if abs(82-ADC8)<5 then return > KEYCODE=5:if abs(98-ADC8)<5 then return > KEYCODE=6:if abs(114-ADC8)<5 then return > KEYCODE=7:if abs(130-ADC8)<5 then return > KEYCODE=8:if abs(147-ADC8)<5 then return > KEYCODE=9:if abs(164-ADC8)<5 then return > KEYCODE=10:if abs(181-ADC8)<5 then return'CLR > KEYCODE=11:if abs(199-ADC8)<5 then return'ENTER > KEYCODE=12:if abs(218-ADC8)<5 then return'F1 > KEYCODE=13:if abs(236-ADC8)<5 then return'F2 > KEYCODE=255:return |
| Antwort schreiben |