Manual drive commands

Manual drive commands

Postby conergy » 27 Mar 2008, 10:39

Hi all,

I have a TMCM 310 with two stepper motors and limit switches. A reference run works out fine and positioning in stand alone mode also.
But in my application I also would like to be able to move the motors with external switches manually. Therefore I wanted to use the digital inputs but this seems to be the first problem. In a simple test application I use a digital output as indicator. In a loop I try to poll an input channel, but the result is only depending on the initial input state at the start of the program and every some starts, one motor begins to move ending up stalling although I did not give any drive command.

What do I do wrong? Here is my code:

Code: Select all
csub initial     // alle parameter setzen
csub referenz   // referenzfahrt motoren
csub setpos1 // in SA-Position fahren
csub setnull
csub horizontal

loop:
    GIO 1,0
    JC ZE, doon
    JA donot
ja loop
stop

doon:
     SIO 7,2,1
     rsub

donot:
     SIO 7,2,0
     rsub
     
initial:
        sgp 77, 0, 1       //setzt autostart auf "ein"
        SIO 0, 0, 1        //pull-up einschalten Input0
        SIO 1, 0, 1        //pull-up einschalten Input1
        SIO 2, 0, 1        //pull-up einschalten Input2
        SIO 3, 0, 1        //pull-up einschalten Input3
        SIO 0, 2, 0        //setzt output 0 auf 0
        SIO 1, 2, 0        //setzt output 1 auf 0
        SIO 2, 2, 0        //setzt output 2 auf 0
        SIO 3, 2, 0        //setzt output 3 auf 0
        SIO 4, 2, 0        //setzt output 4 auf 0
        SIO 5, 2, 0        //setzt output 5 auf 0
        SIO 6, 2, 0        //setzt output 6 auf 0
        SIO 7, 2, 0        //setzt output 7 auf 0
        sgp 80, 0, 0
        sgp 80, 0, 1
        sgp 80, 0, 2
        sgp 80, 0, 3
        sap 140, 0, 1      //setzt die Microstepauflösung von Motor 0 auf x Microsteps
        sap 140, 1, 1      //setzt die Microstepauflösung von Motor 1 auf x Microsteps
        sap 154, 0, 4      //Exponent für die Division des Pulsgenerators für Motor 0
        sap 154, 1, 4      //Exponent für die Division des Pulsgenerators für Motor 1
        SAP 5, 0, 2047     //setzt die Motorbeschleunigung für Motor 0
        sap 5, 1, 2047     //setzt die Motorbeschleunigung für Motor 1
        SAP 6, 0, 300      //setzt den Motorarbeitsstrom von Motor 0 auf xxx mA
        SAP 7, 0, 10       //setzt den Motorstandbystrom von Motor 0 auf xxx mA
        SAP 6, 1, 300      //setzt den Motorarbeitsstrom von Motor 1 auf xxx mA
        SAP 7, 1, 10       //setzt den Motorstandbystrom von Motor 1 auf xxx mA
        sap 4, 0, 30       //setzt die maximale Positioniergeschwindigkeit für Motor 0
        sap 4, 1, 30       //setzt die maximale Positioniergeschwindigkeit für Motor 1
        sap 143, 0, 5      //setzt den Motorstopstrom von Motor 0 auf 100% des Motorarbeitsstroms
        sap 143, 1, 5      //setzt den Motorstopstrom von Motor 1 auf 100% des Motorarbeitsstroms
        SAP 205, 0, -7      //Turn on Stall Detection (use other threshold if needed)
        SAP 205, 1, -7      //Turn on Stall Detection (use other threshold if needed)
        mst 0              //stoppt Motor 0
        mst 1              //stoppt Motor 1
        rsub

referenz:
        ror 0, 25    //ror bewegung zum endtaster
        wait limsw ,0, 0 // stopp bei endtaster
        mst 0            // "      "     "
        mvp rel, 0, 100  // etwas weiter fahren
        wait pos, 0, 0
        wait ticks, 0, 100
        rol 1, 25
        wait limsw, 1, 0
        mst 1
        mvp rel, 1, -200
        wait ticks, 1, 300
        rsub

setpos1:
        mvp rel, 0, -4100
        wait pos, 0, 0
        wait ticks, 0, 100
        mvp rel, 1, 9000
        wait pos, 1, 0
        wait ticks, 0, 100
        wait ticks, 1, 100
        rsub

setnull:
        sap 1, 0, 0
        sap 1, 1, 0
        rsub
       
horizontal:
        mvp abs, 0, 2050
        mvp abs, 1, -4500
        wait pos, 0, 0
        wait pos, 1, 0
        rsub


When I manage that problem the next step would be considering limits in this manual movement also.

Or is the solution much easier because of a special mode I don't know by now. Some other systems have extra inputs for manual positioning, is there a possibility to implement this easily?

Greetings,

Jan Hansen
conergy
User
User
 
Posts: 2
Joined: 26 Mar 2008, 20:06

Postby Olav Kahlbaum (TRINAMIC) » 28 Mar 2008, 08:58

The error in your program is simple: in your main loop in line 7..12 (between the label "loop:" and the STOP command), you are jumping to your "doon" and "donot" routines using JC resp. JA commands. This way the routines get called, but the RSUB commands at the ends of these rotuines do not work, because there is no return address on the stack (an RSUB command can only work when there has been a corresponding CSUB command before, but this is not the case here). So in your program the RSUB commands in the "doon" and "donot" routines do not do anything. The program just continues with the next instruction, and this causes the behaviour you are describing.
So please rewrite your main loop this way:
Code: Select all
loop:
    GIO 1, 0
    JC NZ, NoDoon
    CSUB doon
NoDoon:
    CSUB donot
JA loop

This will do what your code was originally ment to do. But, I think that you also do not want to get "donot" always get called, only when the input is high. So we have to extend the code this way:
Code: Select all
Loop:
    GIO 1, 0
    JC NZ, NoDoon
    CSUB doon
    JA NoDonot  //One could also use "JA loop" here, but just in case the main loop is to be extended
NoDoon:
    CSUB donot
NoDonot:
    //more commands could be inserted here
    JA Loop
    STOP  //not really needed, as we will never get here
User avatar
Olav Kahlbaum (TRINAMIC)
Site Admin
 
Posts: 3359
Joined: 11 Aug 2006, 08:02

wait for limit switch

Postby conergy » 31 Mar 2008, 14:03

Thanks a lot for your help, I corercted that silly the mistake with the rsubs and it works fine now.

I started running and stopping the motors by signals from the imputs, and there's another question: the "wait limsw" command is made for moving a motor to a limit switch, the programm execution stops there waiting for the switch. How can I manage to introduce a condition that when the limit switch is pressed the motor stops but if not the programm keeps running?
conergy
User
User
 
Posts: 2
Joined: 26 Mar 2008, 20:06

Postby Olav Kahlbaum (TRINAMIC) » 01 Apr 2008, 07:58

For such cases the WAIT commands can not be used, but the left stop switch and the right stop switch can also be queried using GAP commands: use GAP 10 for the right and GAP 11 for the left limit switch (also called reference switch). With the help of these commands you can create waiting loops that ill fit your needs. This will also have the advantage thzat you can do other things while waiting for a switch (as you could also put other commands into such waiting loops).
You can also make the motor stop automatically when a limit switch is pressed by enabling it using the SAP 12 (right switch, can stop the motor when moving in positivi direction) and SAP 13 (left switch, can stop the motor when moving in negative direction) commands.
User avatar
Olav Kahlbaum (TRINAMIC)
Site Admin
 
Posts: 3359
Joined: 11 Aug 2006, 08:02


Return to Trinamic Motion Control Language (TMCL)

Who is online

Users browsing this forum: No registered users and 1 guest