//This program demonstrates the stall detection that can be used when
//the module is equipped with TMC246 motor drivers.
//Motor 0 will run until it is stalled, then it will run in the other direction ofter one second
//until it is stalled, and so on.

//Values that have to be adapted
StallValue=3  //1=highest sensitivity ... 7=lowest sensitivity (0=off)
Velocity=350
Acceleration=100


//Initialization
        SAP 205, 0, StallValue
        SAP 5, 0, Acceleration
        SAP 203, 0, 2048

//Main Loop
Loop:   WAIT TICKS, 0, 100
        SIO 0, 2, 0
        ROL 0, Velocity
        CSUB WaitUntilRunning
        CSUB WaitUntilStalled
        SIO 0, 2, 1
        WAIT TICKS, 0, 100
        SIO 0, 2, 0
        ROR 0, Velocity
        CSUB WaitUntilRunning
        CSUB WaitUntilStalled
        SIO 0, 2, 1
        JA Loop

WaitUntilRunning:
       GAP 3, 0
       COMP 0
       JC EQ, WaitUntilRunning
       RSUB

WaitUntilStalled:
       GAP 3, 0
       COMP 0
       JC NE, WaitUntilStalled
       RSUB

