TMC428 –Application Note –TMC428 Getting Started –Including StallGuardTM 3
(v. 2.00 / April 14, 2008)
Copyright © 2005-2008 TRINAMIC Motion Control GmbH & Co. KG
2. Initialization of the TMC428
On first sight, the sample C code included within the ZIP archive 'tmc428demo.zip' might give the
impression that the initialization of the TMC428 is a complicated task due to a couple of different
routines used. The intent of this sample C code and its different routines is to demonstrate how to
access the registers of the TMC428. All together, these routines just perform a sequence of SPI
datagrams that perform the initialization of the TMC428. So, for those who are familiar with the
TMC428 and its SPI datagrams, the program structure might become more compact and the
initialization code might look like
for (i=0; i<(128-2); i+=2) // initialize TMC428 RAM table (SPI conf. & quarter sine wave LUT)
{
spo = 0x80000000 | (i<<(25-1)) | (tmc428_ram_tab[i+1]<<8) | (tmc428_ram_tab[i]); // RRS=1, RW=0
spi = tmc428spi( spo );
}
spi = tmc428spi(0x7E010701); // initialize stepper motor global parameter register, LSMD=1 for EvalKit
spi = tmc428spi(0x........); // initialize . . .
where tmc428_ram_tab[] is an array representing the content of the TMC428 configuration RAM
(see section 1) and tmc428spi(long int spo) represents a routine that sends a 32 bit wide SPI
datagram to the TMC428 and receives a 32 bit wide SPI datagram from the TMC428. The TMC428
needs to be initialized after each power on. A micro controller is suitable to do the initialization of the
TMC428 by just sending a sequence of SPI datagrams to the TMC428 after power on. The TMC428
itself performs a power on reset (POR). Almost any register of the TMC428 is set to zero by the POR.
The RAM of the TMC428 is not initialized by the power on reset, and so the RAM has a more or less
random content after power on. In contrast to power on, there is no need for re-initialization of the
TMC428 after it has been set into power-down by writing the power_down (JDX=%1000) register. The
initialization of the TMC428 enfolds three main phases:
1. initializing the TMC428 configuration RAM
2. configuring the stepper motor global parameter register
3. parameterizing individual stepper motor registers
•choose micro step resolution / step pulse pre-divider / acceleration pre-divider
•choose step velocities v_min and v_max and the step acceleration a_max
•calculate pmul & pdiv for the chosen set of parameters
•set the reference switch configuration and the ramp mode
•set the automatic current scaling [optional]
2.1 TMC428 Configuration RAM
First of all, the stepper motor driver datagram configuration has to be written into the RAM area of the
TMC428. Additionally, the micro step look-up table (LUT) has to be initialized when using micro
stepping. Both tables should be put into one single array for initialization of the TMC428 by the micro
controller after power up. The following constant array represents the configuration concerning stepper
motor driver chain and sine wave look up table according to the example given within the TMC428
datasheet (sections " Stepper Motor Driver Datagram Configuration" and "Initialization of the Microstep
Look-Up-Table"):
unsigned char tmc428_ram_tab[128]=
{
0x10, 0x05, 0x04, 0x03, 0x02, 0x06, 0x10, 0x0D, 0x0C, 0x0B, 0x0A, 0x2E, 0x11, 0x05, 0x04, 0x03,
0x02, 0x06, 0x11, 0x0D, 0x0C, 0x0B, 0x0A, 0x2E, 0x07, 0x05, 0x04, 0x03, 0x02, 0x06, 0x0f, 0x0D,
0x0C, 0x0B, 0x0A, 0x2E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x09, 0x0B, 0x0C, 0x0E, 0x10, 0x11, 0x13, 0x14, 0x16, 0x17,
0x18, 0x1A, 0x1B, 0x1D, 0x1E, 0x20, 0x21, 0x22, 0x24, 0x25, 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C,
0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x38, 0x39, 0x3A, 0x3B,
0x3B, 0x3C, 0x3C, 0x3D, 0x3D, 0x3E, 0x3E, 0x3E, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F
};
The first 64 bytes represent the stepper motor driver chain configuration for a chain of three TRINAMIC
stepper motor drivers of type TMC236 / TMC239 / TMC246 / TMC249. The values 0x2E values
represent the primary signal code 0x0E (= mnemonic PH_B) with the NxM bit set.