-
TMCL: Using the stallGuard Interrupt
TMCL is the simple way to implement your motion control application. With this series of simple coding examples we want to provide you an easy start.
This program demonstrates the stall detection with stallGuard2™. Motor 0 will run until it is stalled, then MCL program flow will be interrupted and the interrupt handling routine (here: returnToZero) will be called. After the detection of a stall the motor will run to postion zero. For more details concerning stallGuard2™ look at Applikation Note AN002_stallGuard2.pdf – http://www.trinamic.com/design-center/application-notes.
Before use: Restore Factory Defaults
// *** Values that have to be adapted *** // stallGuardValue = 2 //-64 = highest sensitivity ... 63 = lowest sensitivity vmax = 2000 //max. speed (0 ... 2047) amax = 1000 //max. acceleration (0 ... 2047) cmax = 100 //max. current (0 ... 255) // *** Initialization / Set up axis parameter *** // SAP 1, 0, 0 //reset actual position to 0 SAP 4, 0, vmax //set max. positioning speed SAP 5, 0, amax //set max. acceleration SAP 6, 0, cmax //set max. current // *** stallGuard™ initialization *** // SAP 173, 0, 1 //set stallGuard™ filter disable SAP 174, 0, stallGuardValue //stallGuard™ threshold SAP 181, 0, 1900 //min. speed for motor to be stopped by stallGuard™ // *** Interrupt initialization *** // VECT 15, returnToZero //defines the interrupt vector for the stallGuard™ interrupt EI 15 //enable stall interrupt EI 255 //globally switch on interrupt processing // *** Main Loop *** // loop: GAP 3, 0 //get current speed JC NZ, loop //jump to loop if speed not zero ROL 0, vmax //turn motor left at vmax JA loop //jump to loop // *** Interrupt routine *** // returnToZero: MVP ABS, 0, 0 //turn motor 0 to postion zero WAIT POS, 0, 0 //wait until position zero reached WAIT TICKS, 0, 500 //wait 5 seconds. 500 * 10ms RETI //end of interrupt
For more details look at TMCL_reference.pdf at http://www.trinamic.com/software-tools/tmcl-ide
This sample is tested with TMCM-1140, TMCM-1161, TMCM-6110.
Related
December 5, 2015 / Jonas P. Proeger / 5
Categories: Code Snippet, Tutorial
Tags: interrupt, sensorless, stallGuard, TMCL
TMCL: Door Contact with Position Mode TMCL: Interrupt Input Change
Comments are currently closed.
5 thoughts on “TMCL: Using the stallGuard Interrupt”
Hi,
Im currently working with the TMCM 1021 module. I’m programming it to stop the motor on stall. It does not seem to work with your above stated interrupt routine. Can you help me understand it with a simple program to show how it works?
Your help will be much appreciated. Thanks.
Please note that for using stallGuard to find the reference position, you normally do not need the interrupt at all. Just run the motor until it has been automatically stopped by stallGuard. You can check this either by polling the actual speed or the stallGuard flag (axis parameter #207). Then, zero the position and switch off stallGuard (by setting parameter #181 to zero). Like this:
SAP 6, 0, 64 //Change this value to fit your needs
SAP 174, 0, 2 //Change this value to fit your needs (with the help of the stallGuard2 tool)
SAP 181, 0, 500 //Minimum speed for stop on stall (change as needed)
//Run until obstructed
ROR 0, 1000 //Let the motor run until obstructed (or ROL as needed)
Loop: GAP 207, 0 //See if the motor has been stopped due to a stall
JC ZE, Loop
//Set actual position as the zero position
SAP 0, 0, 0
SAP 1, 0, 0
//Switch off stallGuard
SAP 181, 0, 0
So, stallGuard gets activated just with parameter #181. If this parameter is zero, then the automatic stop-on-stall is switched off. If it is >0 then stop-on-stall will be active when the actual velocity is greater then this value.
Hello,
I confirm the program with the correction works on a TMCM 6110 module. I am using the stallGuard feature and monitoring the reply from the module however the GAP 207, 0 command does not give the right answer. What method you suggest as alternative to detect the stall in real-time?
How to use above program for reversing the direction after every interrupt
Hi Purva,
Thanks for your feedback and input. Do you need help in realizing this? If so, please let us know and we support you.
Best regards,
Lars