Driving a Linear Stage With the TMC4671 – Setup
The TMC4671 is Trinamic‘s FOC servo controller IC, capable of controlling BLDC, DC and stepper motors. In this post, I’d like to show you how to configure the TMC4671-Eval Board with our Landungsbrücke interface board to drive a linear stage.
In my hardware setup I use a QSH4218-51-10-049-10000-AT, which has 50 pole pairs (200 full steps) and a rated current of 1A. The encoder has 10,000 lines resulting in 40,000 PPR. I also use the Landungsbrücke, a TMC4671-Eval board, and the UPS_2A_24V-Eval power stage board. My belt drive linear stage is of type igus ZLW-0630 Basic and travels at 54 mm/revolution.
To monitor and tune my system I use the USB-2-RTMI adapter. My goal is to initialize the TMC4671 – especially the encoder and the current measurement.
Step 1: Preparation
At the beginning of this project I download and install the software toolchain according to Appnote 038 and download the Evalsystem Firmware sources from Trinamic’s github accordingly. I can compile the latest firmware and upload the .hex file to my Landungsbrücke via the TMCL-IDE using the BL (bootloader) option.
Next, I set up my evaluation kit and power it with 24V.
Step 2: Finding initial settings with the Configuration Wizard
As I need to set up the TMC4671 for correct operation, I use the Configuration Wizard inside the TMCL-IDE to find basic parameters. It’s similar to the approach used in this video by Onno Martens.
In the first step, I choose the stepper motor and power stage.
In the second step, I click on the “set defaults” button and ramp up the slider to 3500. The motor spins now until it reaches the end of the track. I reduce the velocity to 1 rpm so it takes some time to make the distance. If the travel distance is too short in your application, turning the motor in open-loop mode is not required. This is just an example. Furthermore, we don’t need that at every startup once we have configured our parameters.
In the next step of the wizard, I calibrate the current measurement by letting some periods pass to find good values for the offsets. For this, I click on the set button and check the phase. Later on, I will implement a different offset calculation algorithm.
I check for correct mapping of ADC channels to phase currents by checking phase alignment of voltages and currents in the lower graphs of the ADC configuration step. On the TMC4671, phase V is measured by ADC_I2 and phase WY by ADC_I1. This means I have to adjust the default selections as depicted in the image below in order to align the phases. You can see this in the following video as well:
In the next step, I set the encoder parameters, encoder PPR (=40,000 PPR = 4*10,000 encoder lines), the direction bit if necessary, and I perform the encoder initialization as I click on the button “Init with offset estimation (wizard)”. Later, I want to do this in the firmware.
What happens during encoder initialization?
The firmware enables the open-loop mode and sets the commutation angle PHI_E to zero. By setting a voltage U_D, the motor current rises and the rotor aligns with the external field generated by the current. The firmware waits for the motor to settle and writes a zero on the ABN_DECODER_COUNT register. The procedure forces the motor to go to the zero position, which is where we set our zero position. Unfortunately, this procedure requires the motor to move during initialization. We will explain other alignment procedures in future blog posts.
Sometimes this encoder alignment procedure fails. For example, if the rotor is stuck and cannot align. For my linear drive stage, this would be the case if I am already at the end stop. So, it is always good to do a plausibility check. But how do I do that?
I could set a different commutation angle then the zero value and see if my measured encoder angle follows my commanded position. I can do that for a full rotation. If the rotor does not follow or if the offset is too big, I can correct my offset or at least raise a flag that the motor is stuck.
With my PWM, current measurement, and encoder feedback configured, I can operate the “drive in closed-loop torque mode”. I do so in the test drive wizard slide and click the “Set Defaults” button. The IDE automatically sets the PHI_E to PHI_E_ABN, the motion mode to TORQUE_MODE and the controller parameters to 256 as these are small values that should be ok for most motors. It also sets the target torque to 500.
We can now choose which angle we want to use on each cascade level. In my example, I use phi_e_abn for PHI_E_SELECTION. The selectors dialog in the device tree shows all major selections I made. I need to choose a higher value for PID_TORQUE_FLUX_LIMITS because our motor is already connected to a load and won’t move with the default value of 1000 due to limited torque.
At the end of the wizard, I can generate a TMCL PC script or C-Code for initialization. I choose C-Code, save the generated code for later usage, and proceed with controller tuning.
You can choose either the option “Open loop” or “ABN Encoder” for the generated code.
This concludes the first steps within the wizard. In the next post, I will show you how to tune your P-I-parameters for torque/flux mode, velocity mode, and position mode.
February 25, 2020 / Klemens Konhäuser / 1
Tags: code, code snippet, drive, eval kit, evaluation kit, Field Oriented Control, FOC, GUI, guide, How-To, IC, linear stage, programming, rtmi, servo, servo controller IC, setup, TMC4671, TMCL-IDE, tuning